$(document).ready(function(){
						   
	//HOLIDAY TAKEDOWN
	//var d=new Date();
	//var dayToday=d.getDate();
	
	//EMAIL SUBSCRIBE TRACKING
	$('.topNavSubscribe').click(function() {
		pageTracker._trackPageview('/en/subscribe to holts style');
	});
	
	$('.topNavSubscribeFr').click(function() {
		pageTracker._trackPageview('/fr/subscribe to holts style');
	});
	$('.topNavSubscribe').click(function() {
		pageTracker._trackPageview('/en/subscribe to holts style');
	});
	
	$('.topNavSubscribeFr').click(function() {
		pageTracker._trackPageview('/fr/subscribe to holts style');
	});
	
	//WHOLELOTTAHOLTS EVENTS LP
			//city toggle
			$('div.button').click(function() {
		 		var theStore = $('a',this).attr("rel");
				if($(this).next().is(':visible')) {
					$('div.content').slideUp('normal');
					$(".button").removeClass("active");
				} else {
					$('div.content').slideUp('normal');
					$(".button").removeClass("active");
					$(this).addClass("active");
					$(this).next().slideDown({duration:500,complete:function(){
						styleScroll(theStore);
					}
					});
				}
			});
		
			$("#open").trigger('click');
			
			function styleScroll(theStore) {
				var myTimer = {};
				myTimer = $.timer(1,function(){
				CSBfleXcroll(theStore);
			});
			}
			
			//event toggle
			$(".event").click(function(){
				$(this).next(".event-details").slideToggle("normal", function() {
				CSBfleXcroll($(this).parents('.eHolder').attr('id'));
				});
			});
			$("div.event-details").hide();
			
			//change +/-
			$(".event").toggle(function(){
			$(this).addClass("active");
				}, function () {
				$(this).removeClass("active");
			});
	

	
	//VENDOR BOUTIQUE TEMPLATE
	$("a.detailsPage").click(function() {
	$("#boutiqueDetails").load($(this).attr("href"), function(){
			  $("#boutiqueOverlay").fadeIn();
			 });
	return false;
    });
	
	$("#boutiqueOverlay #boutiqueClose").click(function(event){
			$("#boutiqueOverlay").fadeOut();
			return false;
		});
	//Set the popup window to center  
		
	
	
	//WHAT'S NOW LOOKBOOK
	$("a.whatsNowZoom").click(function() {
	$("#whatsNowOverlayContent").load($(this).attr("href"), function(){
			  $("#whatsNowOverlay").fadeIn();
			 });
	return false;
    });
	
	$("#whatsNowOverlay #whatsNowClose").click(function(event){
			$("#whatsNowOverlay").fadeOut();
			return false;
		});
	
	
	var language_id = getUrlParameters('language_id');
	if (location.href.indexOf("/en/") > -1) {
		language_id = "1";
	} else if (location.href.indexOf("/fr/") > -1) {
		language_id = "2";	
	}
	
	
  
	$('ul#navBar li, ul#navBarFr li').hover(
		function() {
			$(this).addClass('on');
		},
		function() {
			$(this).removeClass('on');
		}
	);
	
	//ADD THIS LANGUAGES
	if (language_id == "2") {
		$(".addThis").addClass("fr");
		$("a.addthis_button_compact img").attr("src", "/holts/images/v2/share-fr.gif");
		$(".print").attr("title", "Imprimer");
		$(".addthis_button_facebook").attr("title", "Facebook");
		$(".addthis_button_email").attr("title", "Courriel");
		$(".addthis_button_twitter").attr("title", "Twitter");
	}
	
	
	

	
	//STORE LOCATION IMAGES
	$("#locations #locationImages ul li a").click(function() {
        $("#locations #locationImages p#locationBigImg img").attr("src", $(this).attr("href"));
		return false;
    });
	
	
	//POPUP EVENT
	$("a.eventItem").click(function() {
	$("#popupEvent").load($(this).attr("href"), function(){
			  $("#popupEvent").show();
			 });
	return false;
    });
	
	
	//STORE MENU
	$("#stores").click(function() {
		var tabClass = $("#storeMenu").attr("class");
		if (tabClass == 'off') {
			$("#storeMenu").removeClass('off');
			$("#storeMenu").addClass('on');
		} else {
			$("#storeMenu").removeClass('on');
			$("#storeMenu").addClass('off');
		}
    });
	
	$("#storeMenu li.selectStoreItem").click(function() {

		$('#store_selected').text($(this).text());
		$('#selectedEmail').val($(this).attr("id"));	

    });
	
	
	/*BRANDS COLUMNS*/
	$('#calgaryMainContentWide #calgarybrandslist ul').makeacolumnlists({cols: 3, colWidth: 150, equalHeight: 'ul', startN: 1});
	$('#brands ul').makeacolumnlists({cols: 3, colWidth: 233, equalHeight: 'ul', startN: 1});
	$('.brandsList ul').makeacolumnlists({cols: 2, colWidth: 0, equalHeight: 'ul', startN: 1});
	$('#psn .psnBrandsList ul').makeacolumnlists({cols: 2, colWidth: 235, equalHeight: 'ul', startN: 1});
	
	/*BRANDS PAGE POPUP*/
	$("#brands ul li span").mouseover(function() {
								  
		var offset = $(this).offset();
		var itemWidth = $(this).width();
		var id = $(this).parent().attr("value");
		
		$('#brandPopup').removeClass('left');
		$('#brandPopup').addClass('right');
		
		$("#brandPopup").load("/holts/pages/brands/pop_brand.dot?language_id="+language_id+"&url="+id, function(){
			  $("#brandPopup").css("margin-top",offset.top-47);
			  $("#brandPopup").css("margin-left",offset.left-286);
			  $("#brandPopup").show();
			 });
		
    });
	
	/*PSN BRANDS PAGE POPUP*/
	$(".psnBrandsList ul li span").mouseover(function() {
								  
		var offset = $(this).offset();
		var itemWidth = $(this).width();
		var id = $(this).parent().attr("value");
		
		$('#brandPopup').removeClass('left');
		$('#brandPopup').addClass('right');
		
		$("#brandPopup").load("/holts/pages/psn/psnbranddisplay.dot?language_id="+language_id+"&url="+id, function(){
			  $("#brandPopup").css("margin-top",offset.top-47);
			  $("#brandPopup").css("margin-left",offset.left-284);
			  $("#brandPopup").show();
			 });
		
    });
	
	/*BRANDS POPUP - FOR ALL PAGES*/
	$("a.brandPopup").mouseover(function() {
		
		var mainColOffset = $('#mainCol').offset();
		var offset = $(this).offset();
		var itemWidth = $(this).width();
		var id = $(this).attr("id");
		var difference = offset.left - mainColOffset.left;
		
		
		if (difference <= 273) {
			var lateralMove = offset.left+itemWidth;
			$('#brandPopup').removeClass('right');
			$('#brandPopup').addClass('left');
		} else {
			var lateralMove = offset.left-280;
			$('#brandPopup').removeClass('left');
			$('#brandPopup').addClass('right');
		}


		$("#brandPopup").load("/holts/pages/brands/pop_brand.dot?language_id="+language_id+"&url="+id, function(){
			  $("#brandPopup").css("margin-top",offset.top-47);
			  $("#brandPopup").css("margin-left",lateralMove);
			  $("#brandPopup").show();
			  $("#brandPopup a.brandClose").show();
			 });
		
    });
	

	
	$('#brandPopup').hover(
	function() {
		
	},
	function() {
		$(this).hide();
	});
	
	$("a.brandPopup").click(function() {
		return false;
	});
	
	
	//SUBSCRIBE FORM - TOP MENU
	$("#PIID_34_0").click(function() {
			$("#PIID_34_0").val('');					   
	
	});
	
	//LANDING PAGE PHOTO GALLERY
	$("#landingPageGallery ul li a").click(function() {
        $("#landingPageGallery img.mainImage").attr("src", $('img', this).attr("src"));
		$("#landingPageGallery ul li a").removeClass('on');
		$(this).addClass('on');
		return false;
    });
	
	$("#articlesGallery ul li a").click(function() {
        $("#articlesGallery img.mainImage").attr("src", $('img', this).attr("src"));
		$("#articlesGallery ul li a").removeClass('on');
		$(this).addClass('on');
		return false;
    });
	
	
	
	//PAST EVENTS GALLERY
	initialNav();
	
	$('.galleryDiv .imgList a').lightBox({
		fixedNavigation:true
	 });
	
	$('.videoDiv .imgList li a').prepend("<div class='videoPlay png'></div>");
	
	
	//FALL 2009 MUST HAVES
	$("#fall2009MustHaves").easySlider();
	
	//SPRING 2010 WHAT'S NOW
	$("#spring2010WhatsNow").easySlider();
	
	//CALGARY STORE IMAGES
	$('#calgaryPhotos .NoBulletInline a').lightBox({
		fixedNavigation:true
	 });
	
	
	//FATHER'S DAY GIFT GUIDE pagination
		if ($('#fathersDayThumbnails ul').children().size() != 0) {
			giftGuidePagination($('#fathersDayThumbnails ul').children().size(), 'all');
			var sortBy = "all";
		}

	//FATHER'S DAY gift guide filters
    	$('.sortBy a').click(function() {
			if ($(this).attr('class') == 'all') {
				number_of_items = $('#fathersDayThumbnails ul').children().size();
			} else {
				number_of_items = $('#fathersDayThumbnails ul').find('li.'+$(this).attr('class')).size();
			}
			giftGuidePagination(number_of_items, $(this).attr('class'));
			$("ul.sortBy li").removeClass('active');
			$(this).parent().addClass('active'); 
			sortBy = $(this).attr('class');
			//return false;
      	});

	/*GIFT GUIDE OVERLAYS*/
	//get the number of products
	var productNumber = $("ul#productList li").size();
	
	//the current number
	var theNumber = 1;
	
	//open the product details overlay
	$("ul#productList li a:not(.cancel)").click(function() {
        
		//hide all detail divs
		for (var i=0; i<=productNumber; i++) {
			$("#giftOverlay #productDetails"+i).hide();
		}
		
		var offset = $(this).offset();
		var containerHeight = $("#fathersDay").height();
		var theProduct = $(this).attr("product");
		
		//Google tracking
		if (language_id == "1") {
			pageTracker._trackPageview('/en/fathers-day-gift-guide/'+theProduct);
		} else {
			pageTracker._trackPageview('/fr/fathers-day-gift-guide/'+theProduct);
		}
	
		theNumber = $(this).attr("number");
                
        //Set the popup window to center  
		var centering = ( $(window).height() - ($("#giftOverlay").height()+360) ) / 2+$(window).scrollTop();
		
		if (centering < 0) {
			centering = 50;
		}
		
        $("#giftOverlay").css("top", centering+"px");
		
		document.location.hash='#product='+theProduct;
		
		$("#giftOverlay").css("left", "95px", function() {
			$("#giftOverlay").fadeIn();
		});
		
		
		$("#giftOverlay #productDetails"+theNumber).fadeIn(function() {
			$("#giftOverlay #productDetails"+theNumber).addClass('active');
		});
		
		return false;
    });
	
	
	//close the overlay overlay
	$("#giftOverlay a.closeProduct").click(function() {
		//$('#giftOverlay').fadeOut();
		$("#giftOverlay #productDetails"+theNumber).hide();
		$("#giftOverlay").css("left", "-950000px");
	
		document.location.hash='#n';
		return false;
    });
	
	
	//get array position
	function getItemRow(value) {
		
	}

	
	
	//next button
	$("#giftOverlay a.next").click(function() {
		
		
		if (sortBy != 'all') {
		
		//CREATE THE SORT BY ARRAYS
		var sortByList = [];
		$('#giftOverlay div').each(function() {
			if ($(this).hasClass('.'+sortBy)) { 
				var overlayID = $(this).attr('id');
				overlayID = overlayID.replace('productDetails','')
				sortByList.push(overlayID);
			}
		});

		
		//GET POSITION OF CURRENT PRODUCT IN THE ARRAY
		var arrayPosition=-1;
		for (i=0; i<sortByList.length; i++) {
			if(sortByList[i] == theNumber) {
				arrayPosition = i;
			break;
			}
		}
		
		$("#giftOverlay #productDetails"+theNumber).hide();
		
		var sortByLength = sortByList.length-1;
		if (arrayPosition == sortByLength) {
			arrayPosition = 0;
			theNumber = sortByList[0];
		} else {
			arrayPosition = parseFloat(arrayPosition)+1;
			theNumber = sortByList[arrayPosition];
		}
		$("#giftOverlay #productDetails"+theNumber).fadeIn('slow');
		document.location.hash='#'+$("#giftOverlay #productDetails"+theNumber).attr('product');
		
		} else {
		$("#giftOverlay #productDetails"+theNumber).hide();
		if (theNumber == productNumber) {
		  theNumber = 1;
		} else {
		  theNumber = parseFloat(theNumber)+1;
		}
		
		$("#giftOverlay #productDetails"+theNumber).fadeIn('slow');
		document.location.hash='#'+$("#giftOverlay #productDetails"+theNumber).attr('product');		
		}
			  
		return false;
    });
	
	//back button
	$("#giftOverlay a.back").click(function() {
		
		
		if (sortBy != 'all') {
			//CREATE THE SORT BY ARRAYS
			var sortByList = [];
			$('#giftOverlay div').each(function() {
				if ($(this).hasClass('.'+sortBy)) { 
					var overlayID = $(this).attr('id');
					overlayID = overlayID.replace('productDetails','')
					sortByList.push(overlayID);
				}
			});

		
			//GET POSITION OF CURRENT PRODUCT IN THE ARRAY
			var arrayPosition=-1;
			for (i=0; i<sortByList.length; i++) {
				if(sortByList[i] == theNumber) {
					arrayPosition = i;
				break;
				}
			}
		
			$("#giftOverlay #productDetails"+theNumber).hide();
		
			var sortByLength = sortByList.length-1;
			if (arrayPosition == 0) {
				arrayPosition = sortByLength;
				theNumber = sortByList[sortByLength];
			} else {
				arrayPosition = parseFloat(arrayPosition)-1;
				theNumber = sortByList[arrayPosition];
			}
			
			$("#giftOverlay #productDetails"+theNumber).fadeIn('slow');
			document.location.hash='#'+$("#giftOverlay #productDetails"+theNumber).attr('product');
		
		} else {
			$("#giftOverlay #productDetails"+theNumber).hide();
			
			if (theNumber == 1) {
				theNumber = productNumber;
			} else  {
				theNumber = parseFloat(theNumber)-1;
			}
		
			$("#giftOverlay #productDetails"+theNumber).fadeIn('slow');
			document.location.hash='#'+$("#giftOverlay #productDetails"+theNumber).attr('product');		
		}
			  
		return false;
    });
	
	
	//load the overlay based on hash
	if (document.location.hash.indexOf('product') != -1) {
		var hashMatch = document.location.hash.match(/product=([A-Za-z0-9-]*)/);
		if (hashMatch != null) {
			productId = hashMatch[1];
				if (productId != 'n') {
				theNumber = $("ul#productList li a[product="+productId+"]").attr("number");
				
				for (var i=0; i<=productNumber; i++) {
					$("#giftOverlay #productDetails"+i).hide();
				}
				
				$("#giftOverlay").css("left", "95px", function() {
					$("#giftOverlay").fadeIn();
				});
				
				$("#giftOverlay #productDetails"+theNumber).fadeIn();
			}
		}
	}
	
	
	//creates category URLs
	var hashSortValue = document.location.hash.match(/sort=([A-Za-z0-9]*)/);
	if (hashSortValue != null) {
		var sortValue = hashSortValue[1];
		$('.sortBy a[sortPrice=' + sortValue + ']').click();
	}
	
	
	
	
	//HOLTS CAFE OVERLAY POPUP
	$("a#cateringButton").click(function(event){
			$("div#cateringBox").fadeIn("slow");
			return false;
		});

		$("div#catering-close").click(function(event){
			$("div#cateringBox").fadeOut();
			return false;
		});
		
	$("a#recipeButton").click(function(event){
			$("div#recipeBox").fadeIn("slow");
			return false;
		});

		$("div#recipe-close").click(function(event){
			$("div#recipeBox").fadeOut();
			return false;
		});
		


	//FUN FACTS
	var funFactsNumber = 7;
	var currentFunFact = 0;
	
	//next fun fact button
	$("#funfacts #rightArrow").click(function() {
		$('#funfacts ul#slideshow li').eq(currentFunFact).removeClass('on');
		$('#funfacts #navNumbers a').eq(currentFunFact).removeClass('on');
		if (currentFunFact == funFactsNumber) {
				  currentFunFact = 0;
			  } else {
			  	  currentFunFact = currentFunFact+1;
			  }
			  $('#funfacts ul#slideshow li').eq(currentFunFact).addClass('on');
			  $('#funfacts #navNumbers a').eq(currentFunFact).addClass('on');
		return false;
    });
	
	//back fun fact button
	$("#funfacts #leftArrow").click(function() {
		$('#funfacts ul#slideshow li').eq(currentFunFact).removeClass('on');
		$('#funfacts #navNumbers a').eq(currentFunFact).removeClass('on');
		if (currentFunFact == 0) {
				  currentFunFact = funFactsNumber;
			  } else {
			  	  currentFunFact = currentFunFact-1;
			  }
			  $('#funfacts ul#slideshow li').eq(currentFunFact).addClass('on');
			  $('#funfacts #navNumbers a').eq(currentFunFact).addClass('on');
		return false;
    });
	
	$("#funfacts #navNumbers a").click(function() {
		$('#funfacts ul#slideshow li').eq(currentFunFact).removeClass('on');
		$('#funfacts #navNumbers a').eq(currentFunFact).removeClass('on');
		currentFunFact = parseFloat($(this).text())-1;
		$('#funfacts ul#slideshow li').eq(currentFunFact).addClass('on');
		$('#funfacts #navNumbers a').eq(currentFunFact).addClass('on');
		return false;
    });
	
	
  
});

//GET URL VALUES
function getUrlParameters(name) {  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href );  

		if( results == null )    
			return "";  
		else    
			return results[1];
}


//EVENT CALENDAR HIGHLIGHTER
function eHighline(b, e, cl){
	var n;
	n=parseInt(e)-parseInt(b);
	var c;
	for (i=0;i<=n;i++){
		c=parseInt(b)+i;
		$("#events_"+c).addClass("events highline_"+cl);
	}
}

function eHighlineRecur(d, cl){
	for (var i=0; i<d.length; i++) {
		$('events_'+d[i]).addClass('events highline_'+cl);
	}
}

function eHighlineRecur_off(d, cl){
	for (var i=0; i<d.length; i++) {
		$('events_'+d[i]).removeClass('highline_'+cl);
	}
}

function eHighline_off(b, e, cl){
	var n;
	n=parseInt(e)-parseInt(b);
	var c;
	for (i=0;i<=n;i++){
		c=parseInt(b)+i;
		$("#events_"+c).removeClass("highline_"+cl);
	}
}

//PSN
function showStores(){
	var tabClass = $('#storeMenu1').attr("class");
		if (tabClass == 'off') {
			$("#storeMenu1").removeClass('off');
			$("#storeMenu1").addClass('on');
		} else {
			$("#storeMenu1").removeClass('on');
			$("#storeMenu1").addClass('off');
		}
}

function selectStoreItem3(it, lang){
				var storeid=it.value;
				var url = 'psnstore.dot?language_id='+lang+'&url='+storeid;
				window.location=url;
	}
	
function showCalgaryBrands() {
	  
			  $("#calgaryStoreInfo").hide();
			  $("#calgaryBrands").show();
			  return false;

}

function hideCalgaryBrands() {
			  $("#calgaryBrands").hide();
			  $("#calgaryStoreInfo").show();
			  $("#brandPopup").hide();
			   return false;
}





function showCalgaryNewBrands() {
	
			  $("#calgaryNewBrands").show();
			  return false;
}

function hideCalgaryNewBrands() {
			  $("#calgaryNewBrands").hide();
			   return false;
			  
}



function showPSNBrand(id){
	
	var language_id = getUrlParameters('language_id');
	$("#popupEventPSN").load("/holts/pages/psn/psnbranddisplay.dot?language_id="+language_id+"&url="+id, function(){
			  $("#popupEventPSN").show();
			 });			
}

function openPersonalShoppingPopup(city){
	
	 	var language_id = getUrlParameters('language_id');
		$("#personalShoppingPopup").load("/holts/pages/services/personal_shopping_popup.dot?language_id="+language_id+"&id="+city, function(){
			  $("#personalShoppingPopup").show();
			 });
	
}

	
function initialNav()
{
	//alert($('.photoDiv .imgList li').length);
	$('.holder').each(function()
	{
		var total_len = $('.imgList li', this).length;
		
		if ($(this).hasClass('videoDiv'))
		{
			var len = 2;
		}
		else if ($(this).hasClass('photoDiv'))
		{
			var len = 4;	
		}
		else
		{
			var len = 6;
			var rows = Math.round(total_len / 3);
			for(i=1; i<=rows; i++)
			{
				$(this).find('li').eq(i*3-1).addClass('right');	
			}
		}
		
		var pages = Math.ceil(total_len / len);
		
		
		if (pages > 1)
		{
			for (i=1; i<=pages; i++)
			{
				var span = '<span>'+i+'</span>';
				$('.navBar', this).append(span);
				
			}
			
			$('.navBar span',this).eq(0).addClass('selected');
			
			$('.navBar span',this).click(function()
			{
				$(this).parent().find('span').removeClass('selected');
				$(this).addClass('selected');
				$(this).parent().parent().find('li').hide();
				var page_num = $(this).text();
				for (i=1; i<=len; i++)
				{
					$(this).parent().parent().find('li').eq(((page_num-1)*len+i)-1).fadeIn('slow');
					
				}
			});
		}
		
		
	});
	
	$('.photoDiv .imgList li a, .videoDiv .imgList li a').each(function() {
		var title = $(this).find('img').attr('longdesc');
		var location = $(this).find('img').attr('loc');
		if (title != '')
		{
			var html = '<span class="desc"><p class="title">'+title+'</p><p class="location">'+location+'</p></span>';
			$(this).append(html);
		}
	});
	
/*	$('.galleryDiv .imgList').find('li').each(function(i){
	   $(this).find('a').prepend('<div class="photoGalleryIco png"></div>');
	});*/
	
	$('.galleryDiv .imgList li a').prepend("<div class='photoGalleryIco png'></div>");
	
}

//COLLECTION PRINT
function printCollections(url,lang){
var page= "/holts/pages/collections/printcollections.dot?language_id="+lang+"&url="+url;
window.open(page,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=800, height=800");
}

function printMustHave(url,lang){
var page= "/holts/pages/articles/printmusthave.dot?language_id="+lang+"&url="+url;	
window.open(page,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=800, height=800");
}

function printFall2009MustHave(url,lang){
var page= "/holts/pages/articles/print-fall-2009-must-haves.dot?language_id="+lang+"&url="+url;	
window.open(page,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=800, height=800");
}

/*TRACK HOME PAGE FLASH GA*/
function trackFlashEvent(spot,campaign) {
	pageTracker._trackEvent('Homepage Feature'+spot, 'Click', campaign);
}

/*Hide Show Layers*/
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}

jQuery.fn.centerAll = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

jQuery.fn.centerHeight = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    return this;
}

jQuery.fn.centerWidth = function () {
    this.css("position","absolute");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}



//HOMEPAGE HERO
var SuperHero = function(container) {
	var self = this;
	var timer = null;
	this.panels = new Array();
	this.currentIndex = 0;
	var flashPlayerVersion = swfobject.getFlashPlayerVersion();
	this.hasFlash = (flashPlayerVersion && flashPlayerVersion.major >= 8 ? true : false);

	this.init = function() {
		if($('.panel', container).length > 1)
		{
		$('.panel', container).each(function(i) {
			var duration = Number($(this).attr('data-duration'));
			var imgDuration = Number($(this).attr('data-img-duration'));
			var swfDuration = Number($(this).attr('data-swf-duration'));
			var imgSrc = $(this).attr('data-img');
			var swfSrc = $(this).attr('data-swf');
			var type = 'image';
			var altText = $('a', this).text();
			var date = new Date();
			var id = 'hero' + i + date.getTime();
			$('a', this).attr('id', id).html('<img src="' + imgSrc + '" width="954" height="596" alt="' + altText + '" />');
			if (swfSrc) {
				if (self.hasFlash) {
					type = 'flash';
					var flashvars = {};
					var autoplay = (i == 0 ? 'true' : 'false' );
					var params = {wmode: 'opaque', play: autoplay, allowScriptAccess: 'always'};
					var attributes = {id: id, name: id};
					swfobject.embedSWF(swfSrc, id, '954', '596', '9', '', flashvars, params, attributes);
					duration = swfDuration;
				} else {
					duration = imgDuration;
				}
			}
			self.panels.push({elem: this, duration: duration, type: type, id: id});
		}).eq(0).addClass('show');
		self.buildControl();
		self.play();
		container.removeClass('loading');
		}
		else {
		$('.panel', container).each(function(i) {
			var duration = Number($(this).attr('data-duration'));
			var imgDuration = Number($(this).attr('data-img-duration'));
			var swfDuration = Number($(this).attr('data-swf-duration'));
			var imgSrc = $(this).attr('data-img');
			var swfSrc = $(this).attr('data-swf');
			var type = 'image';
			var altText = $('a', this).text();
			var date = new Date();
			var id = 'hero' + i + date.getTime();
			$('a', this).attr('id', id).html('<img src="' + imgSrc + '" width="954" height="596" alt="' + altText + '" />');
			if (swfSrc) {
				if (self.hasFlash) {
					type = 'flash';
					var flashvars = {};
					var autoplay = (i == 0 ? 'true' : 'false' );
					var params = {wmode: 'opaque', play: autoplay, allowScriptAccess: 'always'};
					var attributes = {id: id, name: id};
					swfobject.embedSWF(swfSrc, id, '954', '596', '9', '', flashvars, params, attributes);
					duration = swfDuration;
				} else {
					duration = imgDuration;
				}
			}
			self.panels.push({elem: this, duration: duration, type: type, id: id});
		}).eq(0).addClass('show');
		}
	}
	
	this.buildControl = function() {
		var control = $('<div id="control"><div id="pagination"></div></div>');
		for (var i = 0; i < self.panels.length; i++) {
			$('<span>' + (i+1) + '</span>').appendTo($('#pagination', control));
		}
		$('<span class="btn pause"></span>').appendTo($(control));
		$('#pagination span', control).eq(0).addClass('selected');
		
		
		$('.btn', control).click(function() {
			if ($(this).hasClass('play')) {
				self.play();
			}
			else if ($(this).hasClass('pause')) {
				self.pause();
			}
			return false;
		});
		
		$('#pagination span', control).click(function() {
			var index = Number($(this).text()) - 1;
			self.pause();
			self.gotoIndex(index);
			return false;
		});
		
		container.append(control);
	}
	
	

	this.next = function() {
		var nextIndex = self.currentIndex + 1;
		if (self.currentIndex == (self.panels.length - 1)) nextIndex = 0;
		self.gotoIndex(nextIndex);
		var duration = self.panels[nextIndex].duration * 1000;
		self.timer = setTimeout(self.next, duration);
	}
	
	this.gotoIndex = function(nextIndex) {
		if (self.currentIndex == nextIndex) return false;
		
		var currentPanel = self.panels[self.currentIndex ].elem;
		var nextPanel = self.panels[nextIndex].elem;
		
		if (self.panels[self.currentIndex].type == 'flash') {
			var id = self.panels[self.currentIndex].id;
			document.getElementById(id).StopPlay();
			document.getElementById(id).Rewind();
		}
		
		if ($.browser.msie) {
			$(currentPanel).hide();
			$(nextPanel).show();
			if (self.panels[nextIndex].type == 'flash') {
				var id = self.panels[nextIndex].id;	
				document.getElementById(id).Play();
			}
		}
		else {
			$(currentPanel).fadeOut(function() {
				$(this).remove('show').hide();
			});
			$(nextPanel).fadeIn(500, function() {
				$(this).addClass('show');
				if (self.panels[nextIndex].type == 'flash') {
					var id = self.panels[nextIndex].id;	
					document.getElementById(id).Play();
				}
			});
		}
		
		self.currentIndex = nextIndex;
		
		$('#pagination span', container).removeClass('selected').eq(nextIndex).addClass('selected');
	}
	
	this.play = function() {
		var currentPanel = self.panels[self.currentIndex];
		var duration = currentPanel.duration * 1000;
		self.timer = setTimeout(self.next, duration);
		$('.btn', container).removeClass('play').addClass('pause');
	}
	
	this.pause = function() { 
		clearTimeout(self.timer);
		$('.btn', container).removeClass('pause').addClass('play');
	}
	
	this.init();
}



//FATHER'S DAY GIFT GUIDE pagination function
function giftGuidePagination(number_of_items, sortBy) {
	var show_per_page = 6; 
	var number_of_pages = Math.ceil(number_of_items/show_per_page);
	
	//set the value of our hidden input fields
	$('#current_page').val(0);
	$('#show_per_page').val(show_per_page);
	
	var navigation_html = '<a class="previous_link" href="#"><img src="/holts/images/whats-now/spring-2010/arrow_left.gif" /></a>';
	var current_link = 0;
	while(number_of_pages > current_link){
		navigation_html += '<a class="page_link" href="#" longdesc="' + current_link +'">'+ (current_link + 1) +'</a>';
		current_link++;
	}
	navigation_html += '<a class="next_link" href="#"><img src="/holts/images/whats-now/spring-2010/arrow_right.gif" /></a>';
	
	$('#page_navigation').html(navigation_html);
	
	$('.previous_link').click(function() {
		previous();
		return false;
	});
	
	$('.page_link').click(function() {
		var index = $('.page_link').index($(this));
		go_to_page(index);
		return false;
	});
	
	$('.next_link').click(function() {
		next();
		return false;
	});
	
	//add active_page class to the first page link
	$('#page_navigation .page_link:first').addClass('active_page');
	
	//hide all the elements inside content div
	$('#fathersDayThumbnails ul').children().css('display', 'none');
	
	
	//and show the first n (show_per_page) elements
	if (sortBy == 'all') {
		$('#fathersDayThumbnails ul').children().slice(0, show_per_page).css('display', 'block');
	} else {
		$('#fathersDayThumbnails ul').find('li.'+sortBy).slice(0, show_per_page).css('display', 'block');
	}
	
	function previous(){
		new_page = parseInt($('#current_page').val()) - 1;
		//if there is an item before the current active link run the function
		if($('.active_page').prev('.page_link').length==true){
			go_to_page(new_page);
		}
	}
	function next(){
		new_page = parseInt($('#current_page').val()) + 1;
		//if there is an item after the current active link run the function
		if($('.active_page').next('.page_link').length==true){
			go_to_page(new_page);
		}
	}
	function go_to_page(page_num){
		//get the number of items shown per page
		var show_per_page = parseInt($('#show_per_page').val());
		
		//get the element number where to start the slice from
		start_from = page_num * show_per_page;
		
		//get the element number where to end the slice
		end_on = start_from + show_per_page;
		
		//hide all children elements of content div, get specific items and show them
		if (sortBy == 'all') {
			$('#fathersDayThumbnails ul').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');
			
			alert
		} else {
			$('#fathersDayThumbnails ul').find('li.'+sortBy).css('display', 'none').slice(start_from, end_on).css('display', 'block');
		}
		
		/*get the page link that has longdesc attribute of the current page and add active_page class to it
		and remove that class from previously active page link*/
		$('.page_link[longdesc=' + page_num +']').addClass('active_page').siblings('.active_page').removeClass('active_page');
		
		//update the current page input field
		$('#current_page').val(page_num);
	}
	
	}
