// 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(); }
}

// get position of child node
function getPosition(main,spec) {
	var items = main.getElementsByTagName(spec.tagName);
	var found = 0;
	for (p = 0; p < items.length; p++) {
		if (items[p] == spec) {
			found = 1;
			break;
		}
	}
	if (found) {
		return p;
	}
	else {
		return -1;
	}
}

// set date elements
var yy = new Date().getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var dd = new Date().getDate();
var mm = new Array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");
var monthNumber = new Date().getMonth();
var monthLabel = mm[monthNumber];

// get class name of element
$.fn.getClassNames = function(){
	if (name = this.attr("className")) {
		return name.split(" ");
	}
	else {
		return [];
	}
};
// get name of element
$.fn.getElementNames = function(){
	if (elementName = this.attr("name")) {
		return elementName.split(" ");
	}
	else {
		return [];
	}
};

$(document).ready(function(){
		
	// add border to first utility nav link
	$("div#utilityNavigation a:first").css({borderRight: "1px solid #e6e5e5"});
	
	// drop down menus
	
		// move discover and experience left -1px to cover up border of previous button
		$("ul#mainNavigation li#discover").hover(
			function(){$(this).css({left: "155px"});},
			function(){$(this).css({left: "156px"});}
		);
		$("ul#mainNavigation li#experience").hover(
			function(){$(this).css({left: "479px"});},
			function(){$(this).css({left: "480px"});}
		);
	
		// hover treatment for drop down menus
		$("ul#mainNavigation li").hover(
			function(){
				$(this).find("a.dropDown").addClass("highlight");
				$(this).find("ul").show();
			},
			function(){
				$(this).find("a.dropDown").removeClass("highlight");
				$(this).find("ul").hide();
			}
		);
			
	// taste overview effects
	$("ul#tasteMenu li span").css({opacity: 0});
	$("ul#tasteMenu li.menuItemHighlight span").css({opacity: 1});
	
	$("ul#tasteMenu li").click(function(){
		
		var tasteMenuPosition = getPosition(this.parentNode,this) + 1;
		
		$("ul#tasteMenu li").removeClass("menuItemHighlight");
		$(this).addClass("menuItemHighlight");
		$("ul#tasteMenu li span").animate({opacity: 0}, {queue: false, duration: 250});
		$("ul#tasteMenu li.menuItemHighlight span").animate({opacity: 1}, {queue: false, duration: 250});
		
		$("div#tasteContainer div.tasteContent").hide();
		$("div#tasteContent"+ tasteMenuPosition).fadeIn(750);
		
	});
	
	$("ul#tasteMenu li").hover(
		function(){
			$(this).find("span").animate({opacity: 1}, {queue: false, duration: 250});
		},
		function(){
			
			if ( $(this).hasClass("menuItemHighlight") ) {
				$(this).find("span").css({opacity: 1});
			}
			else {
				$(this).find("span").animate({opacity: 0}, {queue: false, duration: 250});
			}
			
		}
	);
	
	
	// find excellence
		
	$("div#excellenceMap img").css({opacity: 0});
	
		// new england
		$("area#mapNewEngland").hover(
			function(){$("div#excellenceMap img#imgNewEngland").animate({opacity: 1}, {queue: false, duration: 250});},
			function(){
				if ( $("div#excellenceMap img#imgNewEngland").hasClass("mapHighlight") ) {
					$("div#excellenceMap img#imgNewEngland").css({opacity: 1});
				}
				else {
					$("div#excellenceMap img#imgNewEngland").animate({opacity: 0}, {queue: false, duration: 250});
				}
			}
		);
			
			$("area#mapNewEngland").click(function(){
				
				$("div#excellenceRetailers div").hide();
				$("div#retailersNewEngland").fadeIn(500);
				
				//$("div#excellenceMap img").removeClass("mapHighlight");
				//$("div#excellenceMap img#imgNewEngland").addClass("mapHighlight");
				
				//$("div#excellenceMap img").animate({opacity: 0}, {queue: false, duration: 250});
				//$("div#excellenceMap img#imgNewEngland").animate({opacity: 1}, {queue: false, duration: 250});
				
				return false;
			});
		
		// east
		$("area#mapEast").hover(
			function(){$("div#excellenceMap img#imgEast").animate({opacity: 1}, {queue: false, duration: 250});},
			function(){
				if ( $("div#excellenceMap img#imgEast").hasClass("mapHighlight") ) {
					$("div#excellenceMap img#imgEast").css({opacity: 1});
				}
				else {
					$("div#excellenceMap img#imgEast").animate({opacity: 0}, {queue: false, duration: 250});
				}
			}
		);
		
			$("area#mapEast").click(function(){
				
				$("div#excellenceRetailers div").hide();
				$("div#retailersEast").fadeIn(500);
				
				//$("div#excellenceMap img").removeClass("mapHighlight");
				//$("div#excellenceMap img#imgEast").addClass("mapHighlight");
				
				//$("div#excellenceMap img").animate({opacity: 0}, {queue: false, duration: 250});
				//$("div#excellenceMap img#imgEast").animate({opacity: 1}, {queue: false, duration: 250});
				
				return false;
			});
			
		// south
		$("area#mapSouth").hover(
			function(){$("div#excellenceMap img#imgSouth").animate({opacity: 1}, {queue: false, duration: 250});},
			function(){
				if ( $("div#excellenceMap img#imgSouth").hasClass("mapHighlight") ) {
					$("div#excellenceMap img#imgSouth").css({opacity: 1});
				}
				else {
					$("div#excellenceMap img#imgSouth").animate({opacity: 0}, {queue: false, duration: 250});
				}
			}
		);
		
			$("area#mapSouth").click(function(){
				
				$("div#excellenceRetailers div").hide();
				$("div#retailersSouth").fadeIn(500);
				
				//$("div#excellenceMap img").removeClass("mapHighlight");
				//$("div#excellenceMap img#imgSouth").addClass("mapHighlight");
				
				//$("div#excellenceMap img").animate({opacity: 0}, {queue: false, duration: 250});
				//$("div#excellenceMap img#imgSouth").animate({opacity: 1}, {queue: false, duration: 250});
				
				return false;
			});
		
		// central
		$("area#mapCentral").hover(
			function(){$("div#excellenceMap img#imgCentral").animate({opacity: 1}, {queue: false, duration: 250});},
			function(){
				if ( $("div#excellenceMap img#imgCentral").hasClass("mapHighlight") ) {
					$("div#excellenceMap img#imgCentral").css({opacity: 1});
				}
				else {
					$("div#excellenceMap img#imgCentral").animate({opacity: 0}, {queue: false, duration: 250});
				}
			}
		);
			
			$("area#mapCentral").click(function(){
				
				$("div#excellenceRetailers div").hide();
				$("div#retailersCentral").fadeIn(500);
				
				//$("div#excellenceMap img").removeClass("mapHighlight");
				//$("div#excellenceMap img#imgCentral").addClass("mapHighlight");
				
				//$("div#excellenceMap img").animate({opacity: 0}, {queue: false, duration: 250});
				//$("div#excellenceMap img#imgCentral").animate({opacity: 1}, {queue: false, duration: 250});
				
				return false;
			});
		
		// west
		$("area#mapWest").hover(
			function(){$("div#excellenceMap img#imgWest").animate({opacity: 1}, {queue: false, duration: 250});},
			function(){
				if ( $("div#excellenceMap img#imgWest").hasClass("mapHighlight") ) {
					$("div#excellenceMap img#imgWest").css({opacity: 1});
				}
				else {
					$("div#excellenceMap img#imgWest").animate({opacity: 0}, {queue: false, duration: 250});
				}
			}
		);
		
			$("area#mapWest").click(function(){
				
				$("div#excellenceRetailers div").hide();
				$("div#retailersWest").fadeIn(500);
				
				//$("div#excellenceMap img").removeClass("mapHighlight");
				//$("div#excellenceMap img#imgWest").addClass("mapHighlight");
				
				//$("div#excellenceMap img").animate({opacity: 0}, {queue: false, duration: 250});
				//$("div#excellenceMap img#imgWest").animate({opacity: 1}, {queue: false, duration: 250});
				
				return false;
			});
	
	
	// for any 'print this page' link
	$("a.printPage").click(function(){ window.print(); return false; });
	
	
	// experience bottom focus link lists
	$("ul.borderedList li:first").css({paddingLeft: "0px", borderLeft: "none"});
	
	// bottom focus areas
	$("div.contentFocusAreas ul li:eq(0)").css({left: "27px"});
	$("div.contentFocusAreas ul li:eq(1)").css({left: "335px"});
	$("div.contentFocusAreas ul li:eq(2)").css({left: "643px"});
	
		
	// reset some styles for footer links
	$("ul#footerLinks li:first").css({paddingLeft: "0px"});
	$("ul#footerLinks li:last").css({paddingRight: "0px", borderRight: "none"});
	
	// links with rel="external" will open in a new window
	$("a[rel=external]").click(function(){ window.open(this.href); return false; });
	
	// display year in footer
	$("span.currentYear").text(year);
	
	// translate pngs for ie six
	$(document).pngFix();
	
});
