var $j = jQuery.noConflict();

$j(document).ready(function() {
  $j("#left li").has('ul').removeClass("current-menu-item");
  $j('span.faq-answer').not(':empty').prepend('<span class="hint">Ответ: </span>');
  
  $j('.entry-content .clear:last').remove();
});

$j(function() {
	
	menuSlide();
	nggSideBar();
	$j(".car_searchBlockTop").jScroll();
	
	$j('#slider').nivoSlider({
		effect:'sliceDown',
		slices: 5,
		pauseTime:5000	
	});

	$j("div.inds_c3 div:nth-child(3n)").addClass('inds_car_nl');
	
	$j(".cat_tl_buy").bind('click', function(){
		bcar = $j(this).parent('div').children('span.car_title').html();
		$j("#car_title").html(bcar);
		$j("#car_title_in").val(bcar);
		$j("#closeWindow").fadeIn();
		$j("#toForm").fadeIn();
	});

	$j(".car_tableListBG .cat_tl_buy").bind('click', function(){
		bcar = $j(this).parent('div').children('span.car_title').html();
		$j("#car_title").html(bcar);
		$j("#car_title_in").val(bcar);
		$j("#buyCar_name").val(bcar);
		$j("#subject").val(bcar);
		$j("#closeWindow").fadeIn();
		$j("#toForm").fadeIn();
	});
	
	$j("#inds a").click(function(){
		$jinds_a = $j(this).parent().parent();
		offSet = $jinds_a.position();
		num = $jinds_a.attr('rel');
		
		$j('#inds div.inds_a').removeClass('inds_a_ative');
		$jinds_a.addClass('inds_a_ative');
			
		$j('#inds_polz').animate({left: offSet.left},500);
		
		$j('#inds_cars .inds_b').hide();
		$j('#inds_b_'+num).show();
		
		if($j(this).attr('href')=='#') { return false; }
	});
	
	$j("#closeWindow, #closeWindow_link").click(function(){
		$j("#toForm").fadeOut();
		$j("#toForm_inner").fadeOut();
		$j("#closeWindow").fadeOut();
	});

	$j("#callPhone").click(function(){
		if($j(this).val() == 'Ваш телефон'){$j(this).val('')}
	});			

	$j("div.car_tableListBG").mouseenter(function() {
		$j(this).children("div.cat_tl_buy").slideDown();
		$j(this).children("div.car_tableListBGSorce").animate({'opacity':'0.7'},500);
	}).mouseleave(function() {
		$j(this).children("div.cat_tl_buy").slideUp();
		$j(this).children("div.car_tableListBGSorce").animate({'opacity':'0.2'},500);
	});
  	
	$j("#mloginShow").bind('click', function(){
		if($j('#m_login').is(":visible")){
			$j('#m_login').slideUp();
		}else{
			$j('#m_login').slideDown();
		}
		
		return false;
	});
	
	$j("#mloginShow").bind('click', function(){$j('div.car_selM').stop();
		if($j('div.car_selM').is(":visible")){
			$j('div.car_selM').animate({width:'0px'},1000, function(){$j(this).hide();});
					
		}else{
			$j('div.car_selM').show();
			$j('div.car_selM').animate({width:'200px'},1000);
		}
		
		return false;
	});	

	$j("#pPrice tr").mouseenter(function() {
		$j(this).css({ backgroundColor: '#000'},500);
		$j(this).children('td.pPriceW').css({ backgroundColor: '#F60', color: '#000'});
	}).mouseleave(function() {
		$j(this).css({backgroundColor: '#333'},500);
		$j(this).children('td.pPriceW').css({ backgroundColor: 'transparent', color: '#FFF'});
	});

	$j("#pCalc input").keyup(function() {
		this.value = this.value.replace(/[^0-9\.]/g,'');
		price = $j("#pCalcVal").html();
		day = $j(this).val();
		$j("#pCalc td.pPriceW").html(price*day+'<span class="rr">р.</span>');
		$j("#pCalc td.pPriceW").css({ backgroundColor: '#F60', color: '#000'});
	});
	
	$j("#pCalc").mouseleave(function(){
		$j("#pCalc td.pPriceW").css({backgroundColor: 'transparent', color: '#FFF'})});	
		
	$j("#pCarSlider img").bind('click', function(){	
		if($j(this).attr('id')!=='t_vide_show'){	
			$j("#pCarImg img").fadeOut('slow', function(clone) {
				//$j(this).remove();
			});
			$j("#pCarImg .pCarImgD").html($j(this).clone());
			$j("#pCarImg img").css('opacity','1');
			$j("div.t_vide_can").slideUp();
		}else{
			$j("div.t_vide_can").slideDown();		
		}
	}).mouseenter(function() {
		$j(this).animate({'opacity': '1'},500);
	}).mouseleave(function() {
		$j(this).animate({'opacity': '0.5'},500);
	});



	$j("#car_markSel").change(function() {
		getMM();
	});
	
	$j("#car_ModelSel").change(function() {
		getMM2();
	});
	
	$j("#car_ModelPr").change(function() {
		getMMPR();
	});
	
	function selMessage(){
		
	}
		
	
});

function getModel(){
  $j.ajax({
	  type: "POST",
	  url: "",
	  data: "getModel="+$j("#car_markSel").val(),
	  success: function(msg){
		  $j("#car_ModelSel").empty();
		  $j("#car_ModelSel").append(msg);
	  }
	});			
}

function getMM(){
	auto = $j("#car_markSel").val();
	flag = $j('#car_markSel').attr('rel');
	if(flag == 'd')
		window.location='?page_id=1129&auto='+auto+'&driver=1';
	else if(flag == 's')
		window.location='?page_id=1129&auto='+auto+'&driver=2';
	else
		window.location='?page_id=1129&auto='+auto;
}

function getMM2(){
	auto = $j("#car_markSel").val();
	model = $j("#car_ModelSel").val();
	flag = $j('#car_markSel').attr('rel');
	
	if(flag == 'd')
		window.location='?page_id=1129&auto='+auto+'&model='+model+'&driver=1';
	else if(flag == 's')
		window.location='?page_id=1129&auto='+auto+'&model='+model+'&driver=2';
	else
		window.location='?page_id=1129&auto='+auto+'&model='+model;
}

function getMMPR(){
	price = $j("#car_ModelPr").val();
	window.location='?page_id=1129&price='+price;
}

function menuSlide(){
	$j('a[title="%"]').addClass('jSlideDown');
	$j('a[title="%"]').attr('title','');
	$j("ul.sub-menu").hide();
	$j('ul.leftMenu li a.jSlideDown').bind('click', function() {		
		$j(this).parent('li').parent('ul').children('li').children('ul.sub-menu').slideUp();		
		slideO = $j(this).parent('li').children('ul.sub-menu');
		if(slideO.css('display') == 'none'){
			slideO.slideDown();
		}else{
			slideO.slideUp();
		}		
		return false;
	});
	$j('ul.leftMenu li.current-menu-ancestor li').show();
	$j('ul.leftMenu li.current-menu-ancestor').show();
	$j('ul.leftMenu li.current-menu-item').show();
	
	$j('ul.leftMenu li.current-menu-ancestor').show();

	$j('ul.leftMenu li.current_page_item > ul.sub-menu').show();
	
	$j('ul.leftMenu ul.sub-menu li.current-menu-item').parent('ul').show();
	$j('ul.leftMenu li.current-menu-ancestor').parent('ul.sub-menu').show();		
}

function nggSideBar(){
	$j("#ngg_miss_left a").attr('href','?page_id=1240');
	$j("#ngg_miss_left img").mouseenter(function() {
		$j(this).animate({'opacity': '1'},500);
	}).mouseleave(function() {
		$j(this).animate({'opacity': '0.6'},500);
	});	
	}
