$(document).ready(function(){
	$('.png-fix').ifixpng();

	$('#footer-legal-en').click(function (e) {
		e.preventDefault();
		tb_show(null,"/en/legal.php?KeepThis=true&TB_iframe=true&height=620&width=788&modal=true",false);
	});
	$('#footer-privacy-policy-en').click(function (e) {
		e.preventDefault();
		tb_show(null,"/en/privacy_policy.php?KeepThis=true&TB_iframe=true&height=620&width=788&modal=true",false);
	});
	$('#footer-legal-th').click(function (e) {
		e.preventDefault();
		tb_show(null,"/th/legal.php?KeepThis=true&TB_iframe=true&height=620&width=788&modal=true",false);
	});
	$('#footer-privacy-policy-th').click(function (e) {
		e.preventDefault();
		tb_show(null,"/th/privacy_policy.php?KeepThis=true&TB_iframe=true&height=620&width=788&modal=true",false);
	});


	$('#nav_img1').hover(
      function () { $(this).attr("src","/images/th/2009/share/main_menu/menu-home-a.jpg"); hideMenuAll();},
      function () { $(this).attr("src","/images/th/2009/share/main_menu/menu-home.jpg"); hideMenuAll();}	
	  
	 );
	$('#nav_img2').hover(
		function () { 
			$(this).attr("src","/images/th/2009/share/main_menu/menu-models-a.jpg");
			showNavMenu($(this).attr('id'));
		},
		function () { 
			$(this).attr("src","/images/th/2009/share/main_menu/menu-models.jpg");
			setDestroyNavMenuTimer();
		}
	 );
	$('#nav_img3').hover(
      function () { $(this).attr("src","/images/th/2009/share/main_menu/menu-dealers-a.jpg"); hideMenuAll();},
      function () { $(this).attr("src","/images/th/2009/share/main_menu/menu-dealers.jpg"); hideMenuAll();}	
	 );	
	$('#nav_img4').hover(
      function () { $(this).attr("src","/images/th/2009/share/main_menu/menu-service-a.jpg"); hideMenuAll();},
      function () { $(this).attr("src","/images/th/2009/share/main_menu/menu-service.jpg"); hideMenuAll();}	
	 );	
	$('#nav_img5').hover(
      function () { $(this).attr("src","/images/th/2009/share/main_menu/menu-request-a.jpg"); hideMenuAll();},
      function () { $(this).attr("src","/images/th/2009/share/main_menu/menu-request.jpg"); hideMenuAll();}	
	 );		
	$('#nav_img2_sub').hover(
		function () { 
			showNavMenu('nav_img2');
		},
		function () { 
			setDestroyNavMenuTimer();
		}
	 );
});


// nav menu
var timerID = false;

function showNavMenu (nav_id) {

	clearTimeout(timerID);
	var navMenuData	=	'#'+ nav_id + '_sub';	
	var navMenuPosition =$('#'+nav_id).offset({ scroll: true ,padding:true, border:false });
	var navMenuHeight = $('#'+nav_id).height();
	var navMenuWidth = $('#'+nav_id).width();
	var navMenuDataTop	=	(navMenuPosition.top + navMenuHeight) - 0;
	var navMenuDataLeft	=	navMenuPosition.left - 0;
	$(navMenuData).fadeIn();	
	$(navMenuData).css({ top: navMenuDataTop +"px", left: navMenuDataLeft +"px", position:"absolute" });	
}

function hideMenuAll () {
		$('#nav_img2_sub').hide();
} 

function setDestroyNavMenuTimer () {
	timerID = setTimeout("destroyNavMenu()",100);
}

function destroyNavMenu () {
	$('#nav_img2_sub').fadeOut();
}
// /nav menu



// model nav menu

function showNavModelMenu (nav_id) {
	hideModelMenuAll();
	clearTimeout(timerID);
	var navMenuData	=	'#'+ nav_id + '_sub';	
	$(navMenuData).fadeIn();	
}

function showNavModelMenuFix (nav_id) {
	clearTimeout(timerID);
	var navMenuData	=	'#'+ nav_id + '_sub';	
	$(navMenuData).fadeIn();	
}

function setDestroyNavModelMenuTimer () {
	timerID = setTimeout("destroyNavModelMenu()",500);
}
// /model nav menu



function set_submenu_flash_front() {
	$("#sub_menu_flash").css("z-index","600");
}
function set_submenu_flash_back() {
	$("#sub_menu_flash").css("z-index","30");
}


function GoToPage(toPage) {
	if (toPage != "") {
		window.open(toPage);
	}
}

function jumpMenu(targ,selObj,restore){   
	if (selObj.options[selObj.selectedIndex].value != "") {
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
	}
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

MM_preloadImages(
'/images/th/2009/share/main_menu/menu-home-a.jpg',
'/images/th/2009/share/main_menu/menu-models-a.jpg',
'/images/th/2009/share/main_menu/menu-dealers-a.jpg',
'/images/th/2009/share/main_menu/menu-service-a.jpg',
'/images/th/2009/share/main_menu/menu-request-a.jpg',
'/images/en/2009/share/main_menu/menu-home-a.jpg',
'/images/en/2009/share/main_menu/menu-models-a.jpg',
'/images/en/2009/share/main_menu/menu-dealers-a.jpg',
'/images/en/2009/share/main_menu/menu-service-a.jpg',
'/images/en/2009/share/main_menu/menu-request-a.jpg'
);

function popUpWindow(URL, N, W, H, S) { // name, width, height, scrollbars
	var winleft	=	(screen.width - W) / 2;
	var winup	=	(screen.height - H) / 2;
	winProp		=	'width='+W+',height='+H+',left='+winleft+',top='+winup+',scrollbars='+S+',resizable' + ',status=yes'
	Win			=	window.open(URL, N, winProp)
	if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }
}

function showMap(strUrl) {
  popUpWindow(strUrl,'SHC12',850,700,'yes');
}
