$(document).ready(function() {
	  
//////////////GERNAL JQUERY FOR PAGES
//FIX FOOTER AT BOTTOM OF SITE


var $windowHeight = $(window).height();
var $bodyHeight = $("body").height();

//console.log( "Window:" + $windowHeight  + "Body:"+ $bodyHeight);

if($bodyHeight < $windowHeight){
		var rightcol = $("#topfooter").height();
		var extraheight = ($windowHeight - $bodyHeight);
		var footerheight = $("#topfooter").height();
		
		$("#topfooter").height(footerheight+extraheight);
		
		//console.log("Footer height:" +  footerheight+ "Extra height:" +extraheight);
}



//IF RESIDE
$(window).resize(function() {
						  
 		var $windowHeight = $(window).height();
		var $bodyHeight = $("body").height();
  	
		//console.log( "Window:" + $windowHeight  + "Body:"+ $bodyHeight);
	
		
		var rightcol = $("#topfooter").height();
		var extraheight = ($windowHeight - $bodyHeight);
		var footerheight = $("#topfooter").height();
		
		$("#topfooter").height(footerheight+extraheight);
		

	
});




/////////SEARCH FIELD
	
	$("#searchlink").click(function(){
		$("#searchform").submit();
	});
	

	$("#searchfield").focus(function(){
			var whatstherenow = $(this).val();
			if(whatstherenow=="Search..."){
				$(this).val("");
			}
	})


///LEGAL POP
$("#legaldisclaimer").click(function(){
	poptastic();
	return false;
});

	
/////////HOME PAGE	

	
	//if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
		 
		if($("body").hasClass("homepage")){
		
		
		function calculateTimeout(currElement, nextElement, opts, isForward) { 
			// here we set even number slides to have a 2 second timeout; 
			// by returning false for odd number slides we let those slides 
			// inherit the default timeout value (4 sec) 
			if($(this).hasClass("iamthelast")){
				var index =15550;
			}else{
				var index =5550;
			}
			return index; 
		} 

		 
		 
		 $('#homepageslideshow').cycle({
			fx: 'fade',
			speed:   2500,
			cleartype: true, cleartypeNoBg: true,
			timeoutFn: calculateTimeout,
			before:function(){
           		
				if($(this).hasClass("iamthelast")){
					
					$(".titlecolor").html("New In Stores!");
					$(".titlecolorfr").html("Nouveau en magasin!");
					Cufon.replace('h1',{fontFamily:'mondrenmts'});
					
					$("#firstinfo").fadeOut( 'fast', function(){
							$("#seoundinfo").show();
					});
				}
				
				if($(this).hasClass("iamthefirst")){
					
					$(".titlecolor").html("Fall for this!");
					$(".titlecolorfr").html("Tombez en an amour cet automne!");
					
					Cufon.replace('h1',{fontFamily:'mondrenmts'});

					$("#seoundinfo").fadeOut( 'fast', function(){
							$("#firstinfo").show();
					});
				}
				
	     	}
			
		 });
		

		
		
		$("#logoContainer").addClass("ipadlogo");
		
		$("#idfristimageofslideshow").addClass("showimage");
		
		}
	
	//}else{
		
		//LOGO
	
		$('#swfcontainer').flashembed({
			// embedding arguments
			src: '/_lib/swf/new-logo.swf', 
			version: [8, 0], 
			wmode: 'transparent', 
			menu: 'false'
		});
		
		
	
	//}

	 /*BIG LInk*/
	 var target ='.biglink';
	 var hoverClass = 'hoverBigLink';
	 $(target).each(function(){
		$(this).hover(
			function(){
				$(this).addClass(hoverClass);
				if (!$.browser.msie) {
					$(this).fadeTo("normal", 0.8);
				}
			},
			function(){
				$(this).removeClass(hoverClass);
				if (!$.browser.msie) {
					$(this).fadeTo("normal", 1);
				 }

			});
			
			$(this).click(function(){
				var whattodo = $(this).find('a').attr('target');
				if(whattodo=="_blank"){
					window.open($(this).find('a').attr('href'));
				}else{
					location = $(this).find('a').attr('href');
				}
			});
			
			$(this).css('cursor','pointer');
			
	 });
	 
	  
	  /*SLIDE SHOW BELOW*/
	  
	  	var whatwearelookingfor = $(".items").children("ul").eq(0).attr("title"); 
		$(".footertitle").text(whatwearelookingfor);
		Cufon.replace('.footertitle',{fontFamily:'Myriad Pro',textShadow: '#736e6a -1px 0px' });
	  
	  
		var api =  $(".scrollable").scrollable({easing: 'swing', speed: 700, circular: true}).autoscroll({ interval: 5000 }).navigator().data("scrollable");
	
	
	
	api.onSeek(function() {
		
		/* When there was a header below
		var numbertoget = this.getIndex() + 1;
		var whatwearelookingfor = $(".items").children("ul").eq(numbertoget).attr("title"); 
		$(".footertitle").text(whatwearelookingfor);
		Cufon.replace('.footertitle',{fontFamily:'Myriad Pro',textShadow: '#736e6a -1px 0px' });
		*/
	});
	
	
	 //Center at scrollable
			var num = 0;
			$( ".navi a" ).each(function(){
				num++;
			});
			
			$width = (num * 15); 
			$(".navi").css("width",$width);
			
		
		//Diaglo box
		$("#loginlink[rel]").overlay({
			
			// some mask tweaks suitable for modal dialogs
			mask: {
				color: '#fff',
				loadSpeed: 200,
				opacity: 0.7
			}
		
		 });
		
		
	
	//SUBMENU STUFF
  	var submenuConfig = {    
     interval: 50,
     sensitivity: 1,
	 over: addSubMenu, 
	 timeout: 50,
     out: removeSubMenu
    };
	
  
	$("#ourcompanyNav").hoverIntent(submenuConfig);
	
	//SUBMENU STUFF
  	var submenuConfigforCollection = {    
     interval: 50,
     sensitivity: 2,
	 over: addSubMenuforCollection, 
	 timeout: 50,
     out: removeSubMenuforCollection
    };
	
	$("#collectionsNav").hoverIntent(submenuConfigforCollection);
	//$("#pressNav").hoverIntent(submenuConfigforCollection);
	
	
	//SUBMENU STUFF
  	var submenuConfigforMedia = {    
     interval: 50,
     sensitivity: 2,
	 over: addSubMenuforMedia, 
	 timeout: 50,
     out: removeSubMenuforMedia
    };
	
	$("#pressNav").hoverIntent(submenuConfigforMedia);
	
	
	
	//Accrandiane menu
	$("#submenucontainerCollection h4").click(function(){
		
		var whatwearedoing = $(this).parent().find(".collapsemenu");
			$(whatwearedoing).slideToggle("slow",function(){ 
			$(".collapsemenu").not(whatwearedoing).slideUp('slow');
		});
		
		

		
	});
	
	
	
//////////COLLECTION PAGE JS
	
	var gotothiscol = $("#gotothiscol").val();
	
	
	//FOR COLLECTIONS
 	if( $("div").hasClass("collectioncontanerScrollable") ){
		
		var n = $(".collectioncontaner").length
		
		if(n == 1 ){
			
		   var collectionapi = $(".collectioncontanerScrollable").scrollable({next:'.nextcollection', prev:'.prevcollection', circular: false}).data("scrollable");
			
			$(".nextcollection").hide();
			$(".prevcollection").hide();
			
		}else{
		
			var collectionapi = $(".collectioncontanerScrollable").scrollable({next:'.nextcollection', prev:'.prevcollection', circular: true}).data("scrollable");

		
		}//END OF IF 6
		
		collectionapi.move(gotothiscol);
		//GET RID OF ARROWS

		
	}
	
	//FOR LOOKBOOK
 	if( $("div").hasClass("lookbookcontanerScrollable") ){
		
		if ( $('.lookbokcontanerItemsss').children().size() > 0 ) {
			
		var lookbookapi = $(".lookbookcontanerScrollable").scrollable({next:'.nextcollection', prev:'.prevcollection', circular: true}).data("scrollable");
		lookbookapi.move(gotothiscol);
		$(".lookbookcontaner img[title]").tooltip({offset: [65, 80], layout: '<span/><div/>'});
		
		}else{
			$("#collectionnavContainer").hide();
		}
		
		var num = 1;
		$(".lookbookcontaner").not(".cloned").each(function(i){
		num = i;
		});
		if(num==0){
		$("#collectionnavContainer").hide();	
		}

	}

	
	//Nopadding to every 3rd child
	$(".collectioncontaner  li:nth-child(3n)").addClass("lastinlist");
	$(".collectioncontaner img[title]").tooltip({offset: [65, 80], layout: '<span/><div/>'});
	$(".lookbookcontaner  li:nth-child(6n)").addClass("lastinlist");



////COLLECTION DEATILS
	$("#collectiondeailsNav ul a").click(function(){
		
		var nameofiamgetochangeto = $(this).attr("rel");
		
		
		if( $(this).parent().parent().parent().find("ul").hasClass("esentialspath")){
			var newimagewithpath = "/imagedb/essentials/" + nameofiamgetochangeto;
		}else{
			var newimagewithpath = "/imagedb/product/" + nameofiamgetochangeto;
		}
		
		$(".largetumnail img").attr("src",newimagewithpath);  
		
		var filenametouse =  /\w*/.exec(nameofiamgetochangeto);
	 	filenametouse =  /[^normal*]*/.exec(filenametouse);
		filenametouse =  /\w*[^\b_]/.exec(filenametouse);
		
		var getext = /[^.]+$/.exec(nameofiamgetochangeto);
		
		if($(this).parent().parent().parent().find("ul").hasClass("esentialspath")){
			var fullPathandimage = "/imagedb/essentials/"+filenametouse+"."+getext;
		}else{
			var fullPathandimage = "/imagedb/product/"+filenametouse+"."+getext;	
		}
		
		
		$("a#single_image").attr("href",fullPathandimage);
		$("#viewlarger").attr("href",fullPathandimage);
		
		return false;
	});



		$("#viewlarger").click(function(){
			$.fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	400, 
				'speedOut'		:	200, 
				'overlayShow'	:	false,
				'href' : this.href
			});
			return false;
		});
		
		$("a#single_image").click(function(){
			$("a#single_image").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	400, 
				'speedOut'		:	200, 
				'overlayShow'	:	false,
				'href' : this.href
			});
			return false;
		});
	
	
	
	$(".availablecolorsdropdown").hover(function(){ 
		$(this).addClass("availablecolorsdropdownActive");
		$(this).find("ul").slideDown('fast');
	  },function(){ 
	  	$(this).removeClass("availablecolorsdropdownActive");
		$(this).find("ul").slideUp('fast');
	 });
	
	

///////// storelocator	RETAILERS
	$(".storerow").each(function(){
		var thehightest = 0;
		$(this).children("ul").each(function(){
			if(thehightest< $(this).height()){
				thehightest = $(this).height();
			}
	 	 });
		$(this).children("ul").height(thehightest);
	 });
	
	
///////// LOGIN	RETAILERS AND REWARDS PROGRAM LOGIN
	$(".forgotpassword strong").toggle(
	function(){
		$(".forgotpassword div").fadeIn('fast');
	},
	function(){
		$(".forgotpassword div").fadeOut('fast');
	});

	$(".rewardsforgotpassword strong").toggle(
	function(){
		$(".rewardsforgotpassword div").fadeIn('fast');
	},
	function(){
		$(".rewardsforgotpassword div").fadeOut('fast');
	});
	
	$("#retilersloginform").submit(function(){
		
		var accountnumber = $("#accountnumber").val();
		var zipcode = $("#zipcode").val();
		var urlcheck = "retailers-check.php";

		$.get(urlcheck, { suser: accountnumber, spass: zipcode },
		 function(data){
		  if(data == "1") {
		   document.location = "/retailers.php";
		  } else {
                   $(".sumbitbox .errors").show();
		  }
                 },
                 "html"
                );
                
		return false;
	});

	$("#rewardsloginform").submit(function(){
		
		var email = $("#femail").val();
		var password = $("#fpassword").val();
		var urlcheck = "rewards-check.php";

		$.get(urlcheck, { femail: email, fpass: password },
		 function(data){
		  if(data == "1") {
		   document.location = "/rewards.php";
		  } else {
                   $(".sumbitbox .errors").show();
		  }
                 },
                 "html"
                );
                
		return false;
	});

	$("#rewardslostform").submit(function(){
        
		var email = $("#lemail").val();
		var urlcheck = "rewards-lost.php";

		$.get(urlcheck, { femail: email },
		 function(data){
		  if(data == "1") {
                   $(".sumbitlostbox .success").show();
		  } else {
                   $(".sumbitlostbox .errors").show();
		  }
                 },
                 "html"
                );
                
		return false;
	});

	$("#rewardssubscribeform").submit(function(){
        
	        var emailRegexp = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var email = $("#femail").val();
		var password = $("#fpassword").val();
		var password_confirm = $("#fpassword_confirm").val();
		var custno = $("#custno").val();
		var firstname = $("#firstname").val();
		var lastname = $("#lastname").val();
		var birthdaym = $("#birthdaym").val();
		var birthdayd = $("#birthdayd").val();
		var urlcheck = "rewards-create.php";
		
		var err = "";
		if(email == "") { err += "Email\n"; }
		else if(!emailRegexp.test(email)) { err += "Invalid email format\n"; }
		if(password == "") { err += "Password\n"; }
		else if(password != password_confirm) { err += "Password confirmation mismatch\n"; }
		if(custno == "") { err += "Customer Number\n"; }
		if(firstname == "") { err += "Firstname\n"; }
		if(lastname == "") { err += "Lastname\n"; }
		if(birthdaym == "" || birthdayd == "") { err += "BirthDay\n"; }
		
		if(err != "") {
		  alert("Some fields are empty or incorrect:\n" + err);
		  return false;
                }

		$.get(urlcheck, { femail: email, fpassword: password, custno: custno, firstname: firstname, lastname: lastname, birthdaym: birthdaym, birthdayd: birthdayd },
		 function(data){
		  if(data == "1") {
                   $(".sumbitbox .success").show();
                   $(".sumbitbox .duplicate").hide();
                   $(".sumbitbox .errors").hide();
		  } else if(data == "2") {
                   $(".sumbitbox .duplicate").show();
                   $(".sumbitbox .success").hide();
                   $(".sumbitbox .errors").hide();
		  } else {
                   $(".sumbitbox .duplicate").hide();
                   $(".sumbitbox .success").hide();
                   $(".sumbitbox .errors").show();
		  }
                 },
                 "html"
                );
                
		return false;
	});
	
	
//////DROP DOWN FOR TRADE SHOW
	
	//Set custom configurations
	var configtrade = {
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
		 interval: 100, // number = milliseconds for onMouseOver polling interval
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		 timeout: 100, // number = milliseconds delay before onMouseOut
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};
	
	$(".dropdowncontainer .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
	$(".dropdowncontainer").hoverIntent(configtrade); //Trigger Hover intent with custom configurations

/////////FIND YOUR FIT
		$("a.findyourfitimages").click(function(){
			$("a.findyourfitimages").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	400, 
				'speedOut'		:	200, 
				'overlayShow'	:	false,
				'href' : this.href
			});
			return false;
		});
		
	///////FIT FIT FROM
		
		//ARRAY OF 
	 	var quiz = [];
	 	 
		//TYPE OF JEANS ARRAY
		var suzanne1 = [1,0];
		var suzanne2 = [1,0];
		var suzanne3 = [1,0];
		var suzanne4 = [1,2];
		var suzanne5 = [0,2];
		var suzanne = [suzanne1,suzanne2,suzanne3,suzanne4,suzanne5];

		var suzannepetite1 = [1,0];
		var suzannepetite2 = [2,0];
		var suzannepetite3 = [1,0];
		var suzannepetite4 = [1,2];
		var suzannepetite5 = [2,3];
		var suzannepetite = [suzannepetite1,suzannepetite2,suzannepetite3,suzannepetite4,suzannepetite5];
		
		var olivia1 =  [2,0];
		var olivia2 =  [1,0];
		var olivia3 =  [1,2];
		var olivia4 =  [1,2];
		var olivia5 =  [2,3];
		var olivia =  [olivia1,olivia2,olivia3,olivia4,olivia5];

		var oliviapetite1 = [2,0];
		var oliviapetite2 = [2,0];
		var oliviapetite3 = [1,2];
		var oliviapetite4 = [1,2];
		var oliviapetite5 = [2,3];
		var oliviapetite = [oliviapetite1,oliviapetite2,oliviapetite3,oliviapetite4,oliviapetite5];

		var peggy1 = [1,0];
		var peggy2 = [1,0];
		var peggy3 = [3,0];
		var peggy4 = [3,0];
		var peggy5 = [1,0];
		var peggy = [peggy1,peggy2,peggy3,peggy4,peggy5 ];
		
		var peggypetite1 = [1,0];
		var peggypetite2 = [2,0];
		var peggypetite3 = [0,3];
		var peggypetite4 = [0,3];
		var peggypetite5 = [1,3];
		var peggypetite = [peggypetite1,peggypetite2,peggypetite3,peggypetite4,peggypetite5];
	
		var dusty1 = [2,0];
		var dusty2 = [1,0];
		var dusty3 = [3,0];
		var dusty4 = [3,0];
		var dusty5 = [1,3];
		var dusty = [dusty1,dusty2,dusty3,dusty4,dusty5];
		
		var dustypetite1 = [2,0]; 
		var dustypetite2 = [2,0];
		var dustypetite3 = [3,0];
		var dustypetite4 = [3,0];
		var dustypetite5 = [1,3];
		var dustypetite = [dustypetite1,dustypetite2,dustypetite3,dustypetite4,dustypetite5];
	
		var kylie1 = [3,0];
		var kylie2 = [1,0];
		var kylie3 = [1,2];
		var kylie4 = [1,2];
		var kylie5 = [2,3];
		var kylie = [kylie1,kylie2,kylie3,kylie4,kylie5];

	 	var currentindex = 0;
			
		//$(".fitpanel:first").fadeIn();
		//$(".findyourfitlink:first").addClass("active");
		
		$(".startpanel a").click(function(){   
			$(".startpanel").fadeOut('slow', function(){
				$("#findyourfitmenu").fadeIn();
				$(".fitpanel:first").fadeIn();
				$(".findyourfitlink:first").addClass("active");
				
				return false;
			})							  
		});
		
		
		//DROPDOWN FOR FID FIT
		$(".findfitdropdown a").click(function(){
			
			var valuetochange = $(this).attr("rel");
			$(this).parent().parent().parent().parent().find(".selectfitfit").attr("rel", valuetochange );
			
			var texttochange = $(this).text();
		    $(this).parent().parent().parent().parent().find("span").text(texttochange);
			
			 var thereisavalue = true;
			 
			 $(".selectfitfit").each(function(i){
		 		var selectvalue = $(this).attr("rel");
				if(selectvalue == "")
					thereisavalue = false;
					quiz[i] = selectvalue;
					//quiz.push(selectvalue);
			 });
			 
			 if(thereisavalue){

				//console.log(currentindex + " " + "ARRAY =" + quiz);
			
				//disapare and show
				
				$(".fitpanel:eq("+currentindex+")").fadeOut('slow',function(){
					$(".findyourfitlink:eq("+currentindex+")").removeClass("active");
					currentindex++;
					$(".fitpanel:eq("+currentindex+")").fadeIn('slow');
					$(".findyourfitlink:eq("+currentindex+")").addClass("active");
				});	
				
				
			
			} 
			
			return false;
			
			 
		});//END OF CUSTOM DROPDOWN FOR Find FIT
		
		
		$(".fitpanelimagcontainer li").click(function(){
			
		  if(currentindex==3){
				var selectvalue = $(this).attr("rel");
				quiz[4]= selectvalue;
				
				
				///TEST 
					var howmanyright = [];
					var suzannenum = 0;
					var olivianum = 0;
					var peggynum = 0;
					var dustynum = 0;
					var kylienum = 0;
					
					
				///
				
				
				if(jQuery.compare(quiz, suzanne)){
					window.location = "find-your-fit-match.php?type=suzanne";
				}else if(jQuery.compare(quiz, suzannepetite )){
				   window.location = "find-your-fit-match.php?type=suzannepetite";				
				}
				else if(jQuery.compare(quiz, olivia)){
				   window.location = "find-your-fit-match.php?type=olivia";				
				}
				else if(jQuery.compare(quiz, oliviapetite)){
					window.location = "find-your-fit-match.php?type=oliviapetite";			
				}
				else if(jQuery.compare(quiz, peggy)){
				   window.location = "find-your-fit-match.php?type=peggy";				
				}
				else if(jQuery.compare(quiz, peggypetite)){
					window.location = "find-your-fit-match.php?type=peggypetite";			
				}
				else if(jQuery.compare(quiz, dusty)){
					window.location = "find-your-fit-match.php?type=dusty";				
				}
				else if(jQuery.compare(quiz, dustypetite)){
					window.location = "find-your-fit-match.php?type=dustypetite";			
				}
				else if(jQuery.compare(quiz, kylie)){
				   window.location = "find-your-fit-match.php?type=kylie";			
				}
				else{
					
					$.each(quiz, function(key, value) {
							
							//suzanne
							if(( quiz[key] == suzanne[key][0])||(quiz[key] == suzanne[key][1])){
								suzannenum++;
								
							}
							//suzannepetite 
							if(( quiz[key] == suzannepetite[key][0])||(quiz[key] == suzannepetite[key][1])){
								suzannenum++;
							}
							
							//olivia 
							if(( quiz[key] == olivia[key][0])||(quiz[key] == olivia[key][1])){
								olivianum++;
							}
							//oliviapetite
							if(( quiz[key] == oliviapetite[key][0])||(quiz[key] == oliviapetite[key][1])){
								//howmanyright.push("olivia");
								olivianum++;
							}
							
							
							//dusty
							if(( quiz[key] == dusty[key][0])||(quiz[key] == dusty[key][1])){
								//howmanyright.push("dusty");
								dustynum++;
							}
							//dustypetite
							if(( quiz[key] == dustypetite[key][0])||(quiz[key] == dustypetite[key][1])){
								//howmanyright.push("dusty");
								dustynum++;
							}
							

							//peggy
							if(( quiz[key] == peggy[key][0])||(quiz[key] == peggy[key][1])){
								//howmanyright.push("peggy");
								peggynum++;
							}
							//peggypetite
							if(( quiz[key] == peggypetite[key][0])||(quiz[key] == peggypetite[key][1])){
								//howmanyright.push("peggy");
								peggynum++;
							}
							
							
							//kylie
							if(( quiz[key] == kylie[key][0])||(quiz[key] == kylie[key][1])){
								//howmanyright.push("kylie");
								kylienum++;
							}
							
		 			 });
					
						var howmanyright = [[suzannenum,"suzanne"],[olivianum,"olivia"],[peggynum,"peggy"],[dustynum,"dusty"], [kylienum,"kylie"]];
					
					 	var highest = howmanyright[0][0];
					 	
						if(quiz[1]==2)
							var highestname = howmanyright[0][1]+"petite";
						else
							var highestname = howmanyright[0][1];
					
						
						$.each(howmanyright, function(i) {
							
							if(highest<howmanyright[i][0]){ 
								highest = howmanyright[i][0];
								
								if(quiz[1]==2 && howmanyright[i][1] !="kylie" ){
									highestname  = howmanyright[i][1]+"petite";
								}else{
									highestname  = howmanyright[i][1];
								} 
								
							}
						
						});


					 window.location = "find-your-fit-match.php?type="+highestname;
					
				}
				


		  }else{
			var selectvalue = $(this).attr("rel");
			quiz.push(selectvalue);	
			$(".fitpanel:eq("+currentindex+")").fadeOut('slow',function(){
				 $(".findyourfitlink:eq("+currentindex+")").removeClass("active");
				 if(currentindex<3)currentindex++;
				$(".fitpanel:eq("+currentindex+")").fadeIn('slow');
				$(".findyourfitlink:eq("+currentindex+")").addClass("active");
			});
			
			return false;
	   }
	   
	   //console.log(currentindex + " " + "ARRAY =" + quiz);
	   
	   
	 
	 });//END OF CLICK BUTTON
		
		
	$(".issueimagecontainer").hover(function(){ $(this).find(".issueimage1").fadeOut('fast'); },function(){ $(this).find(".issueimage1").fadeIn('fast'); });	


/////////////PRESS PAGE

$(".scrollablepress").scrollable({next:'.nextcollection', prev:'.prevcollection', circular: true});

$(".scrollablepress2").scrollable({next:'.nextcollection', prev:'.prevcollection', circular: true});


$("#pressNavContainer2 a").click(function(){ return false; });

$(".scrollablepress2 li:nth-child(3n)").addClass("firstinrow");

$(".pressitem").click(function(){ 
			
			
		   $(".scrollablepress2 li").each(function(){ $(this).removeClass("activepress"); });
		   $(this).parent().addClass("activepress");
		   
		   //CLICK
		   $("#pressdetailinfo").fadeOut("fast");
			
			var id = $(this).attr("rel"); 
			var data = {id:id};
			
			//AJAX CALL HERE
			$.ajax({
					type: "POST",
					url: "/ajax/getpressinfo.php",
					data: data,
					dataType: "json",
					success: function(data){
						//GATTER ALL INFO
					 	var newpressitem = "";
						jQuery.each(data, function(i,info){
						
						var download = "";
						
						if(info.downloadkind =="pdf"){
							download = "<li class='pdf'><a target='_blank' href='../imagedb/press/"+ id +"en.pdf' >Download Full Article</a></li>";					
						}
						
						if(info.downloadkind =="zip"){
							download = "<li class='zip'><a target='_blank' href='../imagedb/press/"+ id +"en.zip' >Download Full Article</a></li>";					
						}
						
						if(info.downloadkind =="link"){
							download = "<li class='link'><a target='_blank' href='"+ info.urlen + "' >Go To Site</a></li>";					
						}
								
					///IMAGES
					var isthereimages = "";
					if(info.img  !=""){	
					isthereimages =	'<a class="pressbigimage" href="/imagedb/press/'+ info.bigimg +'"><img border="0" src="/imagedb/press/'+ info.img +'"></a>';
					
					}
								
						newpressitem +=	'<div id="pressdetailinfo"><h3>'+ info.title +'</h3>'+ isthereimages +'<ul id="bottominfo">'+ download +'</ul></div>';
													 
						}); // END OF ARRAY
						
						
					 $("#pressdetailinfo").html(newpressitem).fadeIn("slow");
					 
					 
					 		$("a.pressbigimage").fancybox({
								'transitionIn'	:	'elastic',
								'transitionOut'	:	'elastic',
								'speedIn'		:	400, 
								'speedOut'		:	200, 
								'overlayShow'	:	false,
								'href' : this.href
							});
							
							
					
					}//SUCCESS ENDS
			  });
					
		return false;
});//END OF  .pressitem CLICk



if($("div").hasClass("scrollablepress2")){
		
		$(".scrollablepress2 li:first-child").addClass("activepress");
		
		$("a.pressbigimage").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	400, 
				'speedOut'		:	200, 
				'overlayShow'	:	false,
				'href' : this.href
			});
}



/////////FOR THE JEAN GENERATION PAGE
		
	//FOR COLLECTIONS
 	if( $("#contentscontainer").hasClass("jeangeneration") ){
		
		var gotothiscol = $("#gotothiscoljeangen").val();		
		var collectionapi = $(".scrollablevids").scrollable({next:'.nextcollection', prev:'.prevcollection', circular: true}).data("scrollable");
		collectionapi.move(gotothiscol);
	
	}



/////////FOR EVENTS PAGE - GIVE IAMGE ROUNDED CONERS
$(".imgcontainer").each(function(){
		var img = $(this).children("img");
		var imgSrc = img.attr("src");
		var imgHeight = img.height();
		var imgWidth = img.width();
		$(this).css("background-image", "url(" + imgSrc + ")")
		.css("background-repeat","no-repeat");
		img.remove();

		if ($.browser.msie) {
		  	 $(".imgcontainer img").each(function(){
				var imgheight = $(this).height();
				if(imgheight < 80 ){
					var heightdiffrant = ( (80 - imgheight)/2 );  
					$(this).css("margin-top", heightdiffrant);
				}		
			  });
		}

		
});



/////////FOR STAY IN TOUCH


$("#stayintochform #day").focus(function(){
		var whatstherenow = $(this).val();
		if(whatstherenow=="DD"){
			$(this).val("");
		}
})

$("#stayintochform #month").focus(function(){
		var whatstherenow = $(this).val();
		if(whatstherenow=="MM"){
			$(this).val("");
		}
})

$("#stayintochform #year").focus(function(){
		var whatstherenow = $(this).val();
		if(whatstherenow=="YYYY"){
			$(this).val("");
		}
})


$("#stayintochform").submit(function(){
									 
		var email = $("#stayintochform #email").val(); 
		var emailok = validate(email);							 
		
		var state = $('#State').val();
		
		
		var day	= $("#day").val();
        var month = $("#month").val();
        var year = $("#year").val();
		
		var birthdate = day + "-" + month + "-" + year;
		
		$("#Birthdate").val(birthdate);
		
		if(emailok==true){
			
		}else{
			$("#stayintochform .sendingerrors").show();
			return false;
		}	
		
});

///STAY IN TOUCH PAGE
//DROP DOWN
$("#stayintouchformcontainer .dropdown a").click(function() {										  
 	
	var $thisUl = $(this).parent().siblings("dd").find(".scrollbox");
	if($thisUl.is(':hidden')){
		$(".dropdown .scrollbox").hide();
		$thisUl.show().jScrollPane();
	}else{
		$thisUl.hide().jScrollPane();
	}
	//$thisUl.toggle();
	
	return false;
});


$("#stayintouchformcontainer .dropdown dd ul li a").click(function() {
    var text = $(this).html();
	var hiddenfield = $(this).text();
    $(this).parent().parent().parent().parent().parent().parent().parent().find("dt a span").html(text);
	$(this).parent().parent().parent().parent().parent().parent().find("input").val(hiddenfield);
    $(".dropdown dd .scrollbox").hide();
}); 




///////CONTACT US PAGE
//DROP DOWN

$("#contactusformcontainer .dropdown a").click(function() {
 	$("#contactusformcontainer  .dropdown dd ul").toggle();
	return false;
});

$("#contactusformcontainer .dropdown dd ul li a").click(function() {
    var text = $(this).html();
	var hiddenfield = $(this).text();
    $(".dropdown dt a span").html(text);
	 $("#Birthdate").val(hiddenfield);
    $(".dropdown dd ul").hide();
}); 

$(document).bind('click', function(e) {
    var $clicked = $(e.target);
    if (! $clicked.parents().hasClass("dropdown")){
		 if($(".dropdown dd").has(".scrollbox")){
		   $(".dropdown dd .scrollbox").hide();
		 }else{
		  $(".dropdown dd ul").hide();
		}
      
	}
});



	
$("#contactusformcontainer #submit").click(function(){
		
		var email = $("#contactusformcontainer #email").val(); 
		var emailok = validate(email);							 
		
		var FirstName = $("#contactusformcontainer #FirstName").val(); 
		var LastName = $("#contactusformcontainer #LastName").val(); 
        var Telephone = $("#contactusformcontainer #Telephone").val(); 
        var State = $("#contactusformcontainer #State").val(); 
		var comments = $("#contactusformcontainer #comments").val();
		var postalcode = $("#contactusformcontainer #postalcode").val();
		
		if((emailok==true)&&(postalcode!="")){
			
			
			var data = {email:email, FirstName:FirstName, LastName:LastName,  Telephone:Telephone,  State:State, postalcode:postalcode  ,comments:comments };
				
				$.ajax({
						type: 'GET',
						url: "/ajax/mail.php",
						data: data,
						success: function(response){ 
							if(response=="good"){
								$("#contactusform").submit();
							}
							
							if(response=="bad"){
								alert("email can't be sent");
							}
							
						
						},
						error: function(xhr, type, exception) { return false; } 
					})

			
		}else{
			
			$("#contactusformcontainer .sendingerrors").show();
		}	
		
		return false;
		
		
});
	


	
	
///////////JEAN GENERATION 
	$("a.youtube").click(function(){
		$.fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	400, 
			'speedOut'		:	200, 
			'overlayShow'	:	false,
			'autoScale' : false,
			'width' : 640,
			'height' : 385,
			'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1',
			'type'      : 'swf',
			'swf'       : {'wmode':'transparent','allowfullscreen':'true'}
	
			});
		
			return false;
	});




	  
});// do stuff when DOM is ready



//FUNCTION FOR HOVERING
function addSubMenu(){
  $(this).children("a").addClass("active");
  $("#submenucontainer").fadeIn('fast'); 
 }

function removeSubMenu(){
  $("#submenucontainer").fadeOut('fast');	
  $(this).children("a").removeClass("active");
  }

      
function addSubMenuforCollection(){
  $(this).children("a").addClass("active");
  $("#submenucontainerCollection").fadeIn('fast'); 
 }

function removeSubMenuforCollection(){
  $("#submenucontainerCollection").fadeOut('fast');	
  $(this).children("a").removeClass("active");
  }
  
  
function addSubMenuforMedia(){
  $(this).children("a").addClass("active");
  $("#submenucontainerMedia").fadeIn('fast'); 
 }

function removeSubMenuforMedia(){
  $("#submenucontainerMedia").fadeOut('fast');	
  $(this).children("a").removeClass("active");
  }

 


//Function for tradeshow find
//On Hover Over
function megaHoverOver(){
	
	
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    
	(function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}

//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}


/////FUNCTION FOR EMAIL CHECK
function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }else{
	  return true;
	}
}

//////OPEN WINDOW 
var newwindow;
function poptastic()
{
	newwindow=window.open('legal-disclaimer.html','name','height=400,width=600,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

//OPENWindow
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}



//FIND NEW FIT YOUR FIT
jQuery.extend({
    compare: function (arrayA, arrayB) {
		
		var isthisamatch = true;
		
		$.each(arrayA, function(key, value) {
				if((value != arrayB[key][0])&&(value != arrayB[key][1])){
					isthisamatch = false;
				}
		  });
		
		return isthisamatch;
		
    }
});





