// This creates a clean load of the homepage.


$(document).ready(function(){

			// A function that renders on the email popup wrt -hover- event
							   
			$('div#container').hover(function() {


var ieversion;

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
}

if (ieversion >= 7 || !$.browser.msie) {


					if(emailCookie=='false') {
							// Here we will describe a variable popupid which gets the
							// rel attribute from the clicked link							
							var popupid = 'popuprel'; //$(this).attr('rel');
		 
							// Now we need to popup the marked which belongs to the rel attribute
							// Suppose the rel attribute of click link is popuprel then here in below code
							// #popuprel will fadein
							$('#' + popupid).fadeIn();
		 
							// append div with id fade into the bottom of body tag
							// and we allready styled it in our step 2 : CSS
							$('body').append('<div id="fade"></div>');
							$('#fade').css({'filter' : 'alpha(opacity=100)'}).fadeIn();
		 
							// Now here we need to have our popup box in center of 
							// webpage when its fadein. so we add 10px to height and width 
							var popuptopmargin = ($('#' + popupid).height() + 10) / 2;
							var popupleftmargin = ($('#' + popupid).width() + 10) / 2;
		  
							// Then using .css function style our popup box for center allignment
							$('#' + popupid).css({
									'margin-top' : -popuptopmargin,
									'margin-left' : -popupleftmargin
							});
					}


}
			}, function(){});			
		
		
		$('#closeEmail').click(function() {
			Set_Cookie( 'talbotsEmail', 'true', '14', '/', '', '' );
			// Add markup ids of all custom popup box here 						  
			$('#fade, #popuprel').fadeOut();
			window.location.replace("/online/home_page.jsp");
			return false;
		});


		$('#emailAddress2').click(function() {
			$('#emailAddress2').val('');			
		});

		
		$('#cheetahEmailSubmit2').submit(function() {
				Set_Cookie( 'talbotsEmail', 'true', '14', '/', '', '' );
				$('#fade, #popuprel').fadeOut();
				window.location.replace("/online/home_page.jsp");
				return true;
		});

	
	//Count the number of pomotions
	var length = $("#merch li").size();
	
	$('#promoBlock').serialScroll({
		target:'#merchBlock',
		items:'li', 
		prev:'#backArrow',
		next:'#forwardArrow',
		axis:'x',
		duration:700,
		force:false,
		lock:true,
		cycle:false,
		exclude:1,
		onBefore:function(options){
				var position = options.data;
	
				if(position > 0){
					$("#backArrow").removeClass("disabled");
					if(position == length - 2){
						$("#forwardArrow").addClass("disabled");
					}
					else if(position < length -2){
						$("#forwardArrow").removeClass("disabled");
					}
				}
				else if(position == 0){
					$("#backArrow").addClass("disabled");
				}			
			}
	});	
});