/* Global Script for Just Jeans */


function popup( url, width, height ) {
	var winLeft = (screen.width - width)/2;  	//Auto position popup in center of screen
	var winTop = (screen.height - height)/2;	//Auto position popup in center of screen
	var newwindow = window.open( url, "popup", ('width='+width+', height='+height+', resizable=yes, scrollbars=yes, menubar=no, status=yes, top='+winTop+', left='+winLeft )); 
	if (window.focus) {newwindow.focus()}
}


//jQuery
$(function(){
	
	// Dynamic shadow edges
	$("#content, .shadow").each(function (i) {
		$(this).wrapAll('<div class="shadow-left"><div class="shadow-bottom"><div class="shadow-right"><div class="shadow-top"><div class="shadow-topleft"><div class="shadow-topright"><div class="shadow-bottomleft"><div class="shadow-bottomright"></div></div></div></div></div></div></div></div>');
	});
	
	//Collect page hierarchy information from body class and make available to all JavaScript
	var bodyClasses = $("body").attr("class").split(" ");
	
	
	/* All links in popups are in new window
	************************************************/
	$(".popup #content a").attr("target","_blank");

	
	/* Zebra stripe tables
	************************************************/
	$("table tbody tr:odd td").addClass("odd");
	
	
	/*  Header active link
	************************************************/
	for( var i in bodyClasses ) {
		$("#header .menu li."+bodyClasses[i]).addClass("active");
		$("#header .account-menu li."+bodyClasses[i]).addClass("active");
	}
	
	
	/*  Footer active link
	************************************************/
	for( var i in bodyClasses ) {
		$("#footer .menu li."+bodyClasses[i]).addClass("active");
	}
	
	
	/*  Navigation active link
	************************************************/
	// makes the first child of the matched body class active 
	// - this is a bit hard coded and assumes that level 1 menu will be first body class, level 2 will be second etc..
	for( var i in bodyClasses ) {
		//$("#nav ."+bodyClasses[0]+" > *:first").addClass("active");
		$("#nav ."+bodyClasses[0]+" ."+bodyClasses[1]+" > *:first").addClass("active");
		$("#nav ."+bodyClasses[0]+" ."+bodyClasses[1]+" ."+bodyClasses[2]+"  > *:first").addClass("active");
	}
	
	$("html").keypress(function (e) {
      if (e.which == 49) {
      	$("#nav").attr("class","white");
	  } else if (e.which == 50) {
	    $("#nav").attr("class","grey");
	  } else if (e.which == 51) {
		$("#nav").attr("class","black");
	  }
    });

	
	
	/*  Checkout path active item
	************************************************/
	$(".checkout-path div").each(function (i) {
		var className = $(this).attr("class").replace(/ .*/g, ""); //add only first class to list
		if( $("body").hasClass(className) ) {
			$(this).addClass("active");
		}
	});
	
	/*  Search bar hint text
	************************************************/
	$(".search-field").hint();
	
	/*  Search Bar AutoSuggest
	************************************************/
	var data = "2 for $40,3/4,aztec,bag,ballet,bead,belt,biker jacket,blazer,bleach,blend,bootcut,boyfriend,buckle,butterfly,button,calvin klein jeans,cami,canvas,canvas jacket,cap,cardi,cargo,chambray,check,check shirt,cheeky short,core denim,crochet,crop,crushed,crushed leather,cuff,damage,denim,denim jacket,denim mini,denim skirt,denim vest,dobby,drain pipe,embellished,embroidered,flare,floral,frill,fringe,gift card,gift voucher,glam,grandpa,henley,high waist,hoodie,jacket,j.society,jeans,kaftan,knit,lace,lace trim,leather jacket,lee,legging,leon,levi's,low waist,maxi dress,maxi skirt,metallic,military,mini,OMM,pant,pinstripe,plait,playsuit,polo,pom pom,pouch,print,print tee,racer,relaxed,riders,riders by lee,rigid,ripped,roll up,sale,sandle,scarf,scoop neck,sequin,shirt,shirt dress,short,skinny,slouch,square neck,straight,stretch,stripe,strummer,studded,super skinny,sweat,tee,thong,tie dye,tiered,tote,trench,trilby,tunic,v-neck,vest,vintage,voucher,wide leg,wrap,y-neck,zip,zip thru".split(",");
	$(".search-field").autocomplete(data,{
		selectFirst: false
	});
	
	/*  Replace love with a heart
	************************************************/
	$(".special-thumb-info").each( function(i) {
		var specialString = $(this).html();
		specialString = specialString.replace("love","<img src='/images/global/heart.gif' alt='love' />");
		$(this).html(specialString);
	});
	
	
});



