// JavaScript Document

//=======================get element X/Y value;=======================
//(function($) {

jQuery.fn.backgroundPosition = function() {
  var bgPosition = $(this).css('background-position');
  if(typeof(bgPosition) == 'undefined') {
   return $(this).css('background-positionX') + ' ' + $(this).css('background-positionY');
  }else{
   return bgPosition;
  }
};
//X值：$(’#Element’).backgroundPosition().split(” “)[0];
//Y值：$(’#Element’).backgroundPosition().split(” “)[1];
//})(jQuery);
//=======================END get element X/Y value;=======================


//=======================check element is exists;=======================
jQuery.fn.exists = function(){return jQuery(this).length>0;}
//=======================END check element is exists;=======================


var menuCount = 0;
var menuHit = 0;
var leftMenuHeight;
$(function(){
   	setupMenu();
	
	leftMenuHeight = $("#leftMenuMain").height();
	
	menuHit = Math.round(leftMenuHeight/300);
	if (menuHit == 0){
		$("#leftMenuNext").css("display","none");	
	}
	$("#leftMenuPrev").click(function(){
		prevMenu();
	});
	
	$("#leftMenuNext").click(function(){
		nextMenu();
	});
});


function prevMenu(){
	$("#leftMenuPrev").unbind("click");
	$("#leftMenuNext").css("display","inline");
	menuCount--;
	if (menuCount == 0){
		$("#leftMenuPrev").css("display","none");
	}
	$("#leftMenuMain").animate({
		top:'+=300'
	},"slow",function(){
		$("#leftMenuPrev").bind("click",function(){
			prevMenu();
		});
	});	
}

function nextMenu(){
	$("#leftMenuNext").unbind("click");
	$("#leftMenuPrev").css("display","inline");
	menuCount++;
	if (menuCount == menuHit){
		$("#leftMenuNext").css("display","none");
	}
	$("#leftMenuMain").animate({
		top:'-=300'
	},"slow",function(){
		$("#leftMenuNext").bind("click",function(){
			nextMenu();
		});
	});
}

function setupMenu(){
	var menuId;
	if (curPage !="" ){
		$("#"+curPage).find("a").addClass("selectedMenu");
		tmpSrc = $("#"+curPage).find("img").attr("src").replace(".png","_o.png");
		$("#"+curPage).find("img").attr("src",tmpSrc);
	}
	
	$(".mainHeader a").hover(function(){
		menuId = $(this).parent().attr("id");
		if (menuId != curPage){
			if (menuId != curLang){
				$(this).addClass("selectedMenu");
				tmpSrc = $(this).find("img").attr("src").replace(".png","_o.png");
				$(this).find("img").attr("src",tmpSrc);
			}
		}
	},function (){
		if (menuId != curPage){
			if (menuId != curLang){
				$(this).removeClass("selectedMenu");
				tmpSrc = $(this).find("img").attr("src").replace("_o.png",".png");
				$(this).find("img").attr("src",tmpSrc);
			}
		}
	});
	
	tmpSrc = $("#"+curLang).find("img").attr("src").replace(".png","_o.png");
	$("#"+curLang).find("img").attr("src",tmpSrc);
	$("#"+curLang).find("a").click(function(e) {
		e.preventDefault();
	});
	
	if ($("#leftWrapper").height() < $("#rightWrapper").height()){
//		$("#leftWrapper").height($("#rightWrapper").height());
		$("#lineWrapper").height($("#rightWrapper").height());
	}else{
		$("#lineWrapper").height($("#leftWrapper").height());
		$("#rightWrapper").height($("#leftWrapper").height()+10);
	}
	
	$("#rightWrapper p:first").css("margin-top","0");
	$("#leftWrapper div:last").css("border","none");
	if ($("#footerImg").exists()){
		var footerImg = "images/footer_"+curPage.substring(1,4).toLowerCase()+".jpg";
		$("#footerImg").attr("src",footerImg);
	}
}

