/*window_resize - begin*/
var d = document;
var winIE = (navigator.userAgent.indexOf("Opera")==-1 && (d.getElementById &&  d.documentElement.behaviorUrns))  ? true : false;

function bodySize(){
	if(winIE && d.documentElement.clientWidth) {
		sObj = d.getElementsByTagName("body")[0].style;
		if(d.documentElement.clientWidth<1000) {
		   	sObj.width = "1000px";
		}
		else if(d.documentElement.clientWidth>1280) {
			sObj.width = "1280px";
		}
		else {
			sObj.width = "100%";
		}
	}
}

function init(){
	if(winIE) { bodySize(); }
}
 
onload = init;

if(winIE) { onresize = bodySize; }
/*window_resize - end*/

/*flash - begin*/
function insertFlash(width,height,path,bgcolor,align,id) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+path+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="bgcolor" value="'+bgcolor+'" />');
	document.write('<embed src="'+path+'" quality="high" wmode="transparent" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" name="'+id+'" align="middle" menu="false" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
/*flash - end*/

$(document).ready(function(){

/*autoselecting menus - begin*/
	$(function(){
		var path = location.pathname.substring(1);
		if ( path ) {
			var linkElem = $("#top a[@href$='" + path + "']");
			for(var i = 1; i <= 9; i++){
				if($(linkElem).parent().parent().attr("id") == "tcm_car_"+i) {
					var MouseX = $(".car_block a[id='car_" + i + "']").offset().left-57;
					var winWidth = $(window).width();
					if(MouseX < 237) MouseX = 237;
					else if(MouseX > winWidth-183) MouseX = winWidth-183;
					$(linkElem).parent().parent().css({"margin-left": MouseX+"px"}).show();
				}
			}
			$(linkElem).attr("class", "current");
			$(linkElem).parent().parent().parent().find("a:first").attr("class", "current");
			$(linkElem).parent().parent().parent().parent().parent().find("a:first").attr("class", "current");
			$(linkElem).parent().parent().show();
			$(linkElem).parent().parent().parent().parent().show();
		}
	});
/*autoselecting menus - end*/

	$(".car_block a").mouseover(function(){
		var carId = this.id;
		var MouseX = $(this).offset().left-57;
		var winWidth = $(window).width();
		if(MouseX < 237) MouseX = 237;
		else if(MouseX > winWidth-183) MouseX = winWidth-183;
		$(".top_cars_menus ul:visible").hide();
		$("#tcm_"+carId).css({"margin-left": MouseX+"px"}).show();
		$(".menu_level_1 a").removeClass("current");
		$(".menu_level_2:visible").hide();
		$(".menu_level_3:visible").hide();
	});
	
	$(".menu_level_1 a").mouseover(function(){
		$(this).parent().parent().find("a").removeClass("current");
		$(".menu_level_2:visible").hide();
		$(".menu_level_3:visible").hide();
		$(this).parent().find(".menu_level_2").show().mouseover(function(){
			$(this).stop().show();
		});
		$(".top_cars_menus ul:visible").hide();
	});
	
	$(".menu_level_2 a").mouseover(function(){
		$(this).parent().parent().find("a").removeClass("current");
		$(".menu_level_3:visible").hide();
		$(this).parent().find(".menu_level_3").show().mouseover(function(){
			$(this).stop().show();
		});
		$(this).parent().parent().parent().find("a:first").addClass("current");
	});

	$("#center").mouseover(function(){
		$(".top_cars_menus ul").hide();
	});
});