// JavaScript Document

//the current category
var currCategory = "axeskincare";
//the current subcategory
var currSubCategory = "f1_moisturizers";
//the current subcategory level 2
var currSubCategory2 = "";

//get the url parametrs
var url = window.location.href.toLowerCase();
var urlParamList;

urlParam = url.split("?");
if (urlParam.length>1){
	urlParam = urlParam[1].split("&");
	for (var i=0; i<urlParam.length; i++){
		if(urlParam[i].indexOf("categorycode=")!=-1){
			urlParameter = urlParam[i].replace("categorycode=","");
			urlParamList = urlParameter.split("^");
		}
	}
	if (urlParamList[0])currCategory = urlParamList[0];
	if (urlParamList[1])currSubCategory = urlParamList[1];
	if (urlParamList[2])currSubCategory2 = urlParamList[2];
}else{
	window.location = "/_zh/_cn/about/promos/allgift/index.aspx?CategoryCode=AXESkincare^F1_Moisturizers&";
}

/*
if (url.indexOf("CategoryCode=AXESkincare")!=-1) {
	currCategory = "axeSkincare";
}
if (url.indexOf("CategoryCode=AXEMakeup")!=-1) {
	currCategory = "axeMakeup";
}
if (url.indexOf("CategoryCode=AXEFragrance")!=-1) {
	currCategory = "axeFragrance";
}
if (url.indexOf("CategoryCode=AXEMen")!=-1) {
	currCategory = "axeMen";
}
*/
function showSubNav(levelNum){
	var currMenu = $("#leftNavMenu").find("img[id='"+currCategory+"']");
	var subCurrMenu = $(".subNav").find("img[id='"+currSubCategory+"']");

	if(levelNum==1){
		$("#"+currCategory).attr("src",$("#"+currCategory).attr("src").replace("_off","_on"));
		//close all sub nav menu
		$(".subNav").slideUp("fast");
		//open current sub nav menu
		$("#"+currCategory).next(".subNav").slideDown("fast");
		//change the current nav menu button status
		$(subCurrMenu).attr("src",$(subCurrMenu).attr("src").replace("_off","_on"));
	}
	if(levelNum==2){
		//close all level 2 sub menu
		$(".subNav2").slideUp("fast");
		//open current level 2 sub menu
		$(subCurrMenu).next(".subNav2").slideDown("fast");
		//change the current level 2 sub menu button status
		if(currSubCategory2!="")$("#"+currSubCategory2).attr("src",$("#"+currSubCategory2).attr("src").replace("_off","_on"));
	}
}

$(document).ready(function(){

	//open current category nav menu
	if(currSubCategory!="")showSubNav(1);
	if(currSubCategory2!="")showSubNav(2);
	
	//set left nav menu hover
	$("#leftNavMenu img").hover(
		function(){
			if(currCategory!=$(this).attr("id") && currSubCategory!=$(this).attr("id") && currSubCategory2!=$(this).attr("id"))$(this).attr("src",$(this).attr("src").replace("_off","_on"))
		},
		function(){
			if(currCategory!=$(this).attr("id") && currSubCategory!=$(this).attr("id") && currSubCategory2!=$(this).attr("id"))$(this).attr("src",$(this).attr("src").replace("_on","_off"))
		}
	);
	
	$("#axeskincare, #axemakeup, #axefragrance, #axemen").click(function(){
		if(currCategory != $(this).attr("id")){
			$("#"+currCategory).attr("src",$("#"+currCategory).attr("src").replace("_on","_off"));
			currCategory = $(this).attr("id");
			//showSubNav(1);
			window.location = $(this).next(".subNav").find("a").eq(0).attr("href");
		}
	});
	
	$("#f1_complexion, #f1_eyes, #f1_lips").click(function(){
		if(currSubCategory != $(this).attr("id")){
			$("#"+currSubCategory).attr("src",$("#"+currSubCategory).attr("src").replace("_on","_off"));
			currSubCategory = $(this).attr("id");
			//showSubNav(2);
			window.location = $(this).next(".subNav2").find("a").eq(0).attr("href");
		}
	});

	//$(".catalog .fancy").each(function(i){this.style.backgroundImage=['none','url(..\/images\/allGiftContainerBG.gif)'][i%3-1]});
	//remove the row terminator lines
	/*
	for(i=0;i<$(".catalog .fancy").size();i++){
		if(i%3==2)$(".catalog .fancy").eq(i).css("background-image","none");
	}*/
});