$(document).ready(function() {
//omniture
 
	$(".helpfooter a, .helpheader, .helpcheckout, .helpmyaccount, .helpproductpage, .helpcontact, #liveChat a").click(function (event) { 
		s.linkTrackVars='events';s.linkTrackEvents='event24';s.events='event24'; s.tl(this,'o','startLivechat'); 
	});	
 	$(".menutier1 li a").click(function (event) { 
		s.linkTrackVars='eVar3'; 
		s.eVar3="browse";
		s.tl(this,'o', 'mainmenu'); 
	});	
//this pops up the footer email
		$("a.vipList").fancybox({ 'frameWidth': 440, 'frameHeight': 600, 'overlayShow': true,'hideOnContentClick': false });
		/*string.split(/\-/g)*///this will split it on  a dash for cookie
	
	
	//this highlights the link of catagory
	 if(getQuerystring('categoryID')){
		$('#'+getQuerystring('categoryID')).addClass('on');
	}
	 if(getQuerystring('p')){
		$('#'+getQuerystring('p')+' a').addClass('on');
		 
	}	
	var tierone;
	var tiertwo;
	var cookie = GetCookie('menuStateus');
		$('.menutier1 .ter1title').click(function () {
			if($(this).hasClass("go")){
			 
				var loc = $('#navigationDiv a:first').attr('href').replace('/index.aspx','')+'/'+ $('span', this).attr('id')+'/index.aspx';
				if(window.location.pathname == loc ){
					return;
				}else{
					window.location.href = loc;			 
					return;
				}
			}
			
			var index = $($(this).parent().parent()).attr('id'); 
			
			tierone = index;
						
			$(".ter1title").removeClass("selected");
			$(".menutier2content").hide('slow');
			if($(this).parent().find(".menutier1content").css("display") != "block"){
										
				$(".menutier1content").each(function (i) {

					$(".menutier1content").hide('slow');

				});
				
				$(this).parent().find(".ter1title").addClass("selected");

				$(this).parent().parent().find(".menutier1content").show('slow');
			}else{
			
				$(this).parent().find(".menutier1content").hide('slow');
			
			}
		});
		$('.menutier1content .ter2titlelink').click(function () {
			
			var tiertwo = $($(this).parent()).attr('class'); 
			createCookie('menuStateus', $(this).parent().parent().parent().parent().attr('id') + "-" + tiertwo,1)

		});
	
		/* this is if you want to slide open the second tier*/
		
		$('.menutier1content .ter2title').click(function () {
			$(".selected2").removeClass("selected2");
			var tiertwo = $($(this).parent()).attr('class'); 
			createCookie('menuStateus', $(this).parent().parent().parent().parent().attr('id') + "-" + tiertwo,1)
			if($(this).parent().find(".menutier2content").css("display") != "block"){
				
				$(".menutier2content").each(function (i) {

					$(".menutier2content").hide('slow');
				
				});
				$(this).parent().find(".ter2title").addClass("selected2");
				$(this).parent().find(".menutier2content").toggle('slow');
			
			}else{
			
				$(this).parent().find(".menutier2content").hide('slow');
			
			}
			
		});
		
		/*if(getQuerystring('land')){
			cookie2 = getQuerystring('land');
			createCookie('menuStateus',cookie2,1)
			cookie = cookie2.toString();
			what(cookie);
			return;

		}*/
		if(cookie){
			
			what(cookie);
				//return;
			//if(getQuerystring('gID')){}
			
		}else{
			what("no");
		}
		$('.menutier1link .ter1title').click(function () {
			
			 var src = $(this).attr('nohref');
			location.href = src; 
			 
		
		});
		 $('#freeShipping').hover(
			 function () {
				
					//$("#freeshippingDetails").fadeIn("slow");
					document.getElementById('freeshippingDetails').style.display = "block"
					
			},function () {
					//$("#freeshippingDetails").fadeOut("slow");
					document.getElementById('freeshippingDetails').style.display = "none"
				
			

		});


});
//this is because this function is called on the body onload
function menuState(){}

function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
} 
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};

function what(cookie){
	var menustat = cookie.split(/\-/g);
	var gender;
	var collection;
	var	urlArray = []
	//drops country code then splits
	var urlArray = window.location.pathname.toLowerCase().replace(/^\/..\//,"").replace(/\/$/,"").split("/");
	
	if(urlArray[0] == "")urlArray.remove(0);	
	if(urlArray == "" || urlArray == "productslist.aspx" || urlArray == "productdetails.aspx" || urlArray == "productslistb.aspx" || urlArray == "productdetailsb.aspx"){
		if(getQuerystring('gID')){
			switch(getQuerystring('gID').toLowerCase())
				{
				case "m":
				  gender = "mens";
				  break;
				case "w":
				  gender = "womens";
				  break;
				case "k":
				  gender = "kids";
				  break; 
				default:
				 gender = menustat[0];
			}
		}
		
		
			collection = menustat[1]
		
		
	}else if(urlArray[0] == "care" || urlArray[0] == "gifts"){
		gender = menustat[0];
		collection = menustat[1];
	
	}else{
		
		gender = urlArray[0];
		collection  = urlArray[1];

	}

	createCookie('menuStateus', gender + "-" + collection,1)
	$("#" + gender + ' .ter1title').addClass("selected");
	$("#" + gender + " .menutier1content").css("display", "block");
	if(menustat.length == 2){
		if(urlArray[0] != "experience"){
			$("#" + gender + " ." + collection + " .menutier2content").css("display", "block");
			$("#" + gender + " ." + collection + " .ter2titlelink").addClass("selected2");
			$("#" + gender + " ." + collection + " .ter2title").addClass("selected2");

		}
	}
}





	


	
							
