// JS for NFNS LocalHeader
if( typeof(SNI.Food.LocalHeader) == "undefined" ) {
	SNI.Food.LocalHeader = {};
}

SNI.Food.LocalHeader = {
	/*GLOBAL NAV*/
	localNav: function(mysel) {
		var navTimer = null;
		var initializeMenu = mysel + " #hubnav li";
		hideAll();
		initMenu(initializeMenu);
	
		function initMenu(initializeMenu) {
		var menu = initializeMenu;
	
		$(menu).find('h3:first span').click( function() {
			hideAll();
			}
		);	
		
		  $(menu+"[@class ^= 'nav-']").each(function(i) {
			$(this).hover(function(e){
				hideAll();
				var $this = $(this);
				var divs = $(this).prevAll();
				var width = 0;				
				
				jQuery.each(divs, function() {
					width = width + parseInt($(this).width()) + 4;
				});
											
				var offsetVal = width + 6;

				$('body').bind("click", function(e){bodyClick(e);});			
				
				navTimer = setTimeout(function(){
				  $this.find('div.drop').css({left: offsetVal, top: "28px", background: "none", display: "block"});
				  navTimer = null;
				}, 375);
			},
			function(e){
				clearTimeout( navTimer );
				navTimer = null;
				var closeDiv = $(this);
				if (jQuery.browser.msie ){ $(this).find('div.drop').css({background: "b2b2b2"});}
				
				navTimer = setTimeout(function(){
				  closeDiv.find("a:first").removeClass("dd-on");
				  closeDiv.find('div.drop').css({top: "28px", display: "none", display: "none"});
				  navTimer = null;
				}, 100);
			  
		  });/*hover*/
		});/*each*/
		}
		
		function bodyClick(e) {
			var $clicked=$(e.target);
			if ($clicked.parents().is('.drop')) {
				return false;
			} else {
				hideAll();
			  $('body').unbind();
			}
		}
	
		function hideAll() {
			clearTimeout( navTimer );
			navTimer = null;
			
			$("#hubnav li[@class ^= 'nav-']").each(function() {
				  $(this).find('a:first').removeClass("dd-on");
			});			
			
			$("#hubnav li[@class ^= 'nav-'] div.drop").each(function() {
			  $(this).css({display: "none"});
			});
		}
	},
	/*END GLOBAL NAV*/
	
	init: function(mysel){
		SNI.Food.LocalHeader.localNav(mysel)
	}	
};

if( typeof(SNI.Food.NFNS) == "undefined" ) {
	SNI.Food.NFNS = {};
}

SNI.Food.NFNS.applyElim = function(mysel) {

	if ((typeof eData == 'undefined')|| ($(mysel).length == 0)) return;

	origImgMatch = /(http:\/\/img.foodnetwork.com\/FOOD\/2009\/)\d\d\/\d\d(\/\w*)_s3x4_(\w*\.jpg)/;
	elimImgSub = "$104/08$2_elim_$3";
	for (erec in eData)
	{
		isrc = $(mysel).find("li.t-" + eData[erec].id + " img").attr("src");
		$(mysel).find("li.t-" + eData[erec].id + " img").attr("src", isrc.replace(origImgMatch, elimImgSub));
		myalt =	$(mysel).find("li.t-" + eData[erec].id + " img").attr("alt");
		$(mysel).find("li.t-" + eData[erec].id + " img").attr("alt", myalt + " eliminated week " + eData[erec].wk);
		$(mysel).find("li.t-" + eData[erec].id).addClass("e");
		$(mysel).find("li.t-" + eData[erec].id).addClass("w" + eData[erec].wk);
	}
	return;
};

SNI.Food.NFNS.insertElim = function() {

	if ((typeof eData == 'undefined') || (typeof tData == 'undefined')) return;
	
	latestWk = 0;
	for (erec in eData)
	{
		if (eData[erec].wk > latestWk)
		{
			latestWk = eData[erec].wk;
			theId = eData[erec].id;
		}
	}	
	bFound = false;
	for (irec in tData)
	{
		if (tData[irec].id == theId) { bFound = true; break; }
	}
	if (!bFound) return;
	var outStr = "";

	outStr += '<a href="';
	outStr += tData[irec].bio;
	outStr += '"><img src="';
	outStr += tData[irec].image;
	outStr += '" alt="';
	outStr += tData[irec].name;
	outStr += '" /></a>';
	outStr += '<p><a href="';
	outStr += tData[irec].bio;
	outStr += '"><strong>';
	outStr += tData[irec].name;
	outStr += '</strong></a></p>';
	outStr += '<ul class="list">';
	outStr += '<li><a href="';
	outStr += tData[irec].bio;
	outStr += '">Read ';
	outStr += tData[irec].firstname;
	outStr += "'s bio</a></li>";
	outStr += '<li><a href="';
	outStr += tData[irec].video;
	outStr += '">Watch ';
	outStr += tData[irec].firstname;
	outStr += "'s videos</a></li>";
	outStr += '</ul>';
	document.write(outStr);
	return;	
};
