
$(document).ready(function(){
	
	dropDownMenus();
	showHideContent();
	focusAreaRandomizer();
	setYearInFooter();
	
	// links with rel="external" will open in a new window
	$("a[rel=external]").click(function(){
		 window.open(this.href);
		 return false;
	});

	
});


function dropDownMenus()
{
	$("ul#mainNavigation li").hover(
		 function(){
		 	if ( $(this).find("a#selectedMain").hasClass("dropDown") ){
			 	$(this).find("ul").show();
			} else {
			 	$(this).find("a.dropDown").addClass("highlight");
				$(this).find("ul").show();
			}
		}, 
		 function(){
		 	$(this).find("a.dropDown").removeClass("highlight");
			$(this).find("ul").hide();
		}
	);
}


function showHideContent()
{
	$("div.collapseExpandWrapper a.expandContent").click(function(){
		$(this).hide();
		$(this).closest("div.collapseExpandWrapper").find("div.collapseExpandContent").show();
		return false;
	});
	$("div.collapseExpandWrapper a.closeSection").click(function(){
		$(this).closest("div.collapseExpandContent").hide();
		$(this).closest("div.collapseExpandWrapper").find("a.expandContent").fadeIn(500);
		return false;
	});
}


function findLindtGoldBunnyMap()
{
	
	// find lindt gold bunny
	$("div#goldBunnyMap img").css({opacity: 0});
	$("div#goldBunnyMap img.mapHighlight").css({opacity: 1});
	
	// new england
	$("area#mapNewEngland").hover(
		function(){$("div#goldBunnyMap img#imgNewEngland").animate({opacity: 1}, {queue: false, duration: 250});},
		function(){
			if ( $("div#goldBunnyMap img#imgNewEngland").hasClass("mapHighlight") ) {
				$("div#goldBunnyMap img#imgNewEngland").css({opacity: 1});
			}
			else {
				$("div#goldBunnyMap img#imgNewEngland").animate({opacity: 0}, {queue: false, duration: 250});
			}
		}
	);
		
	$("area#mapNewEngland").click(function(){
		
		$("div#goldBunnyRetailers div").hide();
		$("div#retailersNewEngland").fadeIn(500);
		
		$("div#goldBunnyMap img").removeClass("mapHighlight");
		$("div#goldBunnyMap img#imgNewEngland").addClass("mapHighlight");
		
		$("div#goldBunnyMap img").animate({opacity: 0}, {queue: false, duration: 250});
		$("div#goldBunnyMap img#imgNewEngland").animate({opacity: 1}, {queue: false, duration: 250});
		
		return false;
	});
	
	// east
	$("area#mapEast").hover(
		function(){$("div#goldBunnyMap img#imgEast").animate({opacity: 1}, {queue: false, duration: 250});},
		function(){
			if ( $("div#goldBunnyMap img#imgEast").hasClass("mapHighlight") ) {
				$("div#goldBunnyMap img#imgEast").css({opacity: 1});
			}
			else {
				$("div#goldBunnyMap img#imgEast").animate({opacity: 0}, {queue: false, duration: 250});
			}
		}
	);

	$("area#mapEast").click(function(){
		
		$("div#goldBunnyRetailers div").hide();
		$("div#retailersEast").fadeIn(500);
		
		$("div#goldBunnyMap img").removeClass("mapHighlight");
		$("div#goldBunnyMap img#imgEast").addClass("mapHighlight");
		
		$("div#goldBunnyMap img").animate({opacity: 0}, {queue: false, duration: 250});
		$("div#goldBunnyMap img#imgEast").animate({opacity: 1}, {queue: false, duration: 250});
		
		return false;
	});
		
	// south
	$("area#mapSouth").hover(
		function(){$("div#goldBunnyMap img#imgSouth").animate({opacity: 1}, {queue: false, duration: 250});},
		function(){
			if ( $("div#goldBunnyMap img#imgSouth").hasClass("mapHighlight") ) {
				$("div#goldBunnyMap img#imgSouth").css({opacity: 1});
			}
			else {
				$("div#goldBunnyMap img#imgSouth").animate({opacity: 0}, {queue: false, duration: 250});
			}
		}
	);
	
	$("area#mapSouth").click(function(){
		
		$("div#goldBunnyRetailers div").hide();
		$("div#retailersSouth").fadeIn(500);
		
		$("div#goldBunnyMap img").removeClass("mapHighlight");
		$("div#goldBunnyMap img#imgSouth").addClass("mapHighlight");
		
		$("div#goldBunnyMap img").animate({opacity: 0}, {queue: false, duration: 250});
		$("div#goldBunnyMap img#imgSouth").animate({opacity: 1}, {queue: false, duration: 250});
		
		return false;
	});
	
	// central
	$("area#mapCentral").hover(
		function(){$("div#goldBunnyMap img#imgCentral").animate({opacity: 1}, {queue: false, duration: 250});},
		function(){
			if ( $("div#goldBunnyMap img#imgCentral").hasClass("mapHighlight") ) {
				$("div#goldBunnyMap img#imgCentral").css({opacity: 1});
			}
			else {
				$("div#goldBunnyMap img#imgCentral").animate({opacity: 0}, {queue: false, duration: 250});
			}
		}
	);
		
	$("area#mapCentral").click(function(){
		
		$("div#goldBunnyRetailers div").hide();
		$("div#retailersCentral").fadeIn(500);
		
		$("div#goldBunnyMap img").removeClass("mapHighlight");
		$("div#goldBunnyMap img#imgCentral").addClass("mapHighlight");
		
		$("div#goldBunnyMap img").animate({opacity: 0}, {queue: false, duration: 250});
		$("div#goldBunnyMap img#imgCentral").animate({opacity: 1}, {queue: false, duration: 250});
		
		return false;
	});
	
	// west
	$("area#mapWest").hover(
		function(){$("div#goldBunnyMap img#imgWest").animate({opacity: 1}, {queue: false, duration: 250});},
		function(){
			if ( $("div#goldBunnyMap img#imgWest").hasClass("mapHighlight") ) {
				$("div#goldBunnyMap img#imgWest").css({opacity: 1});
			}
			else {
				$("div#goldBunnyMap img#imgWest").animate({opacity: 0}, {queue: false, duration: 250});
			}
		}
	);
	
	$("area#mapWest").click(function(){
		
		$("div#goldBunnyRetailers div").hide();
		$("div#retailersWest").fadeIn(500);
		
		$("div#goldBunnyMap img").removeClass("mapHighlight");
		$("div#goldBunnyMap img#imgWest").addClass("mapHighlight");
		
		$("div#goldBunnyMap img").animate({opacity: 0}, {queue: false, duration: 250});
		$("div#goldBunnyMap img#imgWest").animate({opacity: 1}, {queue: false, duration: 250});
		
		return false;
	});
	
}


function focusAreaRandomizer()
{
	totalFocusAreas = $("div.randomizeFocusAreas div").length;
	setRandomFocus = Math.floor(Math.random()*totalFocusAreas) + 1;
	
	if ( totalFocusAreas == 0 )
	{
		// do nothing
	}
	else
	{
		$("div.randomizeFocusAreas div").hide();
		$("div.randomizeFocusAreas div:nth-child(" + setRandomFocus + ")").show();
	}
}


function setYearInFooter()
{
	var yy = new Date().getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;
	$("span.yearWrapper").text(year);
}

/* centered pop up window */
function centeredPopUpWindow(mypage, myname, w, h, scroll){
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
