$(document).ready(function(){

	// Custom classes for top navigation items
	$("ul.navBar > li").each(function () {
		var index = $("ul.navBar > li").index(this);
		$(this).addClass("lItem_"+index);
	});
	$("div.navBox").find("div.under:eq(1)").addClass("ie6fix");

	// Custom class fot last list item
	$(".lastItem > li:last-child").addClass("last");

	// Tuning scrolls
	var scrollheight = $("div.dataSection").height();
	/*$("#complBox div.dataHeaderSect").height(scrollheight);*/

	// tuning of left navigation
	$(".modelsNav li.current").next().addClass("nextEl");
	$("<img src='/img/left_nav_bg_top.gif' class='topBg' alt='' />").insertBefore("li.nextEl a");

/*  tooltips    */
	// enable tooltip for "download" element
	//$(".download_now").tooltip();

	$(".modData tr.row3 td:first-child").addClass("firstTip");

	$(".present").tooltip({
	// use div.tooltip as our tooltip
	tip: 'div.tooltip',
	// use fade effect instead of the default
	effect: 'fade',
	// make fadeOutSpeed similar to browser's default
	fadeOutSpeed: 20,
	// the time before tooltip is shown
	predelay: 20,
	// tweak the position
	position: "top left"
	});


	$("ul.clrs div.clrBox").hover(
		function(){
			$(this).addClass("hoverBrd").next().show();
		},
		function() {
			$(this).removeClass("hoverBrd").next().hide();
	});

	//    hide- show FAQ
	$("dl.faqIt dt:first").addClass("b").next().show();

	$(".content dl.faqIt dd:not(:first)").hide();
	 $(".content dl.faqIt dt").bind("click",function(){
        if($(this).next().is(":visible"))
        {
            $(this).next().hide();
						$(this).removeClass("b");
						return false;
        }else
        {
						$(this).next().show();
						$(this).toggleClass("b");
						return false;
        }
    });

/* credit calc - radio buttons */
 $("INPUT.label_highlight").bind("click",function(){
		$("label[for='"+this.id+"']").addClass("b");
		$("label[for='"+this.id+"']").siblings("label").removeClass("b");
	});

/* Check Boxes */
 $("INPUT.label_highlight").bind("click",function(){
		if (this.checked)
			$("label[for='"+this.id+"']").addClass("b");
		else
			$("label[for='"+this.id+"']").removeClass("b");
	});

	var leftheight = $("div.contentBox div.leftBox").height();
	var rightheight = $("div.contentBox div.rightBox").height();
	$("div.contentBox div.rightBox").each( function(){
		if ($.browser.msie && $.browser.version == 6) {
			if (leftheight > rightheight ) {
				$("div.contentBox div.rightBox").css("height",leftheight+50);
				}
		}
		if ($.browser.msie && $.browser.version >= 7) {
			if (leftheight > rightheight ) {
				$("div.contentBox div.rightBox").css("min-height",leftheight+100);
				}
		}
		if ($.browser != $.browser.msie) {
			if (leftheight > rightheight ) {
				$("div.contentBox div.rightBox").css("min-height",leftheight+100);
				}
		}
	});

/* Link "добавить еще одну деталь" */
 $("A#oneMorePart").bind("click",function(){
		var number = $("#detListID LI").length + 1;
		if (number<=20) {
			var new_part = $("<li><input id=\"addIt" + number + "ID\" class=\"field\" type=\"text\"  name=\"data[new][detail" + number + "]\">&nbsp;<input class=\"nmbr\" type=\"text\" id=\"count" + number + "ID\" name=\"data[new][detail" + number + "quantity]\">&nbsp;шт.</li>");
			new_part.appendTo("#detListID");
		}
		return false;
	});

/* Show/hide cars props */
	$("TABLE.genData TR A.dash").bind("click",function(){
		var flag = 0;
		var position = $("TABLE.genData TR").index( $(this).parent('TD').parent('TR') );
        $("TABLE.genData TR").each(
			function() {
				if ( $(this).children('TD').children('A').length && flag==0 && $("TABLE.genData TR").index( $(this) )==position ) {
					flag = 1;
				} else if ( !$(this).children('TD').children('A').length && flag==1 ) {
					$(this).toggleClass('hidden');
				} else if ( $(this).children('TD').children('A').length && flag==1 ) {
					flag = 2;
				}
			}
		)
		return false;
    });

	/* Current Date in Forms */
	if ($('SELECT#dayID').length) {
		var today = new Date();
		var tomorrow = new Date( Date.UTC(today.getFullYear(), today.getMonth(), today.getDate()) + 86400000 );
		$('OPTION#day'+tomorrow.getDate()).attr("selected", "selected");
		$('OPTION#month'+(tomorrow.getMonth()+1)).attr("selected", "selected");
		checkDate();
	}
	/* Check count of dates when month changed */
	if ($('SELECT#monthID').length) {
		$('SELECT#monthID').change( function(){
			checkDate();
		});
	}
});

// Change picture with car in body color when click
function changeCarImg (path) {
	$("IMG.moldelClr").attr("src",path);
}

// body color in compare list
function addToCompareList(checkbox, id) {
 	if ($(checkbox).attr('checked')) {
		$("DIV.compareButtBox INPUT:button").attr("disabled", "");
		$("DIV#modelsClrCompare DIV.viewCompared DIV#carOuter" + id).show();
	} else {
		if (!$("UL.clrs LI INPUT:checkbox:checked").length) {
			$("DIV.compareButtBox INPUT:button").attr("disabled", "disabled");
		}
		$("DIV#modelsClrCompare DIV.viewCompared DIV#carOuter" + id).hide();
	}
	return false;
}
/* Check count of dates */
function checkDate() {
	switch ($('SELECT#monthID OPTION:selected').attr('id')) {
		case 'month1':
		case 'month3':
		case 'month5':
		case 'month7':
		case 'month8':
		case 'month10':
		case 'month12':
			$('OPTION#day30').show();
			$('OPTION#day31').show();
		break
		case 'month2':
			$('OPTION#day30').hide();
			$('OPTION#day31').hide();
		break
		case 'month4':
		case 'month6':
		case 'month9':
		case 'month11':
			$('OPTION#day30').show();
			$('OPTION#day31').hide();
		break
	}
}


// Child Gallery
$(document).ready(function(){
	$("div.child_gallery img").css("border", "1px solid #fff", "margin", "4px");
	
	$("div.child_gallery img").hover(
		function(){
			$(this).css("border", "1px solid #C71444");
		},
		function(){
			$(this).css("border", "1px solid #fff");
		}
	);
	
	$("a.child_gallery").toggle(
		function(){
			$("div.child_gallery").slideDown();
			return false;
		},
		function(){
			$("div.child_gallery").slideUp();
			return false;
		}
	);
});

