
/* sni-healthy-eats - Sat, 21 Nov 2009 07:17:36 -0500 */


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

/**
 * healthyeats-ads.js
 *
 * requires core ads functionality from sni-global.js
 * requires mdManager (uses mdManager within functions, but not during load)
 */


function FoodAd(adtype, adsize, pos, keywords) {
	if(pos < 0 || pos == undefined) {pos = 1;}
	if(keywords == undefined) { keywords = ""; }
	
	var ad = new DartAd();
	ad.setUrl("http://"+SNI.Ads._adServerHostname+"/js.ng/");
	
	if (adtype== 'BIGBOX' && pos == 5) {
		ad.addParameter("adtype", 'BIGBOX');
	} else {
		ad.addParameter("adtype", adtype );
	}
	
	if (adtype== 'LEADERBOARD') {
		ad.addParameter("Params.styles", "SNI_LEADERBOARD"); //tells ad server to wrap with div.ad-ldr
	}
		
	ad.addParameter("adsize", adsize);
	ad.addParameter("PagePos", pos);

	if( keywords != "" ) {
		var words = keywords.split(" ");
		for(i=0; i < words.length; i++) {
			ad.addParameter("keyword", words[i]);
		}
	}
	
	writeAd(ad);
}


function writeAd(ad){
	if (typeof adRestrictionManager != 'undefined') {
		ad.useIframe = adRestrictionManager.isIframe(ad, mdManager);
		if( adRestrictionManager.isActive(ad, mdManager) != false) {
			adManager.createAd(ad);
		}
	} else {
		adManager.createAd(ad);
	}	
}


//Recipe Ad
function RecipeAd (pos, adtype, pnames, pvals) {
	if(pos < 0 || pos == undefined) {pos = 1;}
			
	var ad = new DartAd();
	
	if (pos == 1 && adtype == 'GOOGLE') {pos = 2;}
	
	ad.setUrl("http://"+SNI.Ads._adServerHostname+"/js.ng/");
	ad.addParameter("PagePos", pos);
	// ad.addParameter("Params.styles", "trace");
	
	if (adtype != "" &&  adtype != undefined)
	 { 
       ad.addParameter("adtype", adtype);
	 } else {
	  	if(pos == 5) {
  			ad.addParameter("adtype", 'BIGBOX');
		}
	 }
	 
	var paramNames = pnames.split(" ");
	var paramVals = pvals.split(" ");
	
	for(i = 0; i < paramNames.length; i++) {
		ad.addParameter(paramNames[i], paramVals[i]);
	}

	writeAd(ad);
}


function LeaderboardAd(pos) {
	if(pos < 0 || pos == undefined || pos=='') {pos = 1;}
	FoodAd('LEADERBOARD', '468x60',  pos);
}


function PushdownAd(pos) {
	if(pos < 0 || pos == undefined) {pos = 1;}
	FoodAd('PUSHDOWN', '', pos);
}


function GoogleBixboxAd(pos) {
	// Food GOOGLE BIG BOX 300x250 adtag
	if(pos < 0 || pos == undefined) {pos = 1;}
	FoodAd('GOOGLE_BIGBOX', '', pos);
}


function GoogleLeaderboardAd(pos) {
	// Food GOOGLE HORIZONTAL RECTANGLE 630x132 adtag
	if(pos < 0 || pos == undefined) {pos = 1;}
	FoodAd('GOOGLE_LEADERBOARD', '', pos);
}


function BigboxAd(pos, keywords) {
	if(pos < 0 || pos == undefined) {pos = 1;}
	FoodAd('BIGBOX', '', pos, keywords);
}


function SuperstitialAd(pos) {
	if(pos < 0 || pos == undefined) {pos = 1;}
	FoodAd('SUPERSTITIAL', '', pos);
}


/*
function WDSearchAd(adtype, pos, keywords) {
	if(pos < 0 || pos == undefined) {pos = 1;}
			
	var ad = new DartAd();
	
	ad.setUrl("http://"+SNI.Ads._adServerHostname+"/js.ng/");
	ad.addParameter("adtype", adtype);
	ad.addParameter("adsize", "");
	ad.addParameter("PagePos", pos);
	// ad.addParameter("Params.styles", "trace");
	
	var words = keywords.split(" ");
	for(i = 0; i < words.length; i++) {
		ad.addParameter("keyword", words[i]);
	}
	writeAd(ad);
}

*/


//Video PreRoll & Overlay Ad functions for Maven, Pickle
function VideoPlayerAd(adtype, adsize, pos) {
	var ad = new AdUrl();
	
	ad.setUrl("http://"+SNI.Ads._adServerHostname+"/html.ng/");
	if (adtype != '') {	ad.addParameter("adtype", adtype); }
	if (adsize != '') { ad.addParameter("adsize", adsize); }
	if (!pos || pos=='') { pos = 1; }
	ad.addParameter("PagePos", pos);
	ad.useFeature("tile");
	writeAd(ad);

   return ad.buildExpandedUrl();
}


// Video Player Ad Integration
// The video player will make calls to the following javascript functions to 
//    1. Get a Dart ad tag url for PRE_ROLL and OVERLAY ads.
//--Wrapper function which the video player calls to get a preroll ad tag url -->
function getDartEnterpriseUrl(adtype,pos){
   		adtype = adtype.toUpperCase();
   		var strUrl = VideoPlayerAd(adtype,'', pos);
   		return strUrl;
}

function setDartEnterpriseBanner(adType, sync_banner) {
	if (adType == 'LEADERBOARD') {
	  if($("#leaderboard").length > 0) {
			boxW = 728;
			boxH = 90;
			$("#leaderboard").html("<iframe src='" + sync_banner + "\' width=\'" + boxW + "\' height=\'" + boxH + "\'" + "frameborder='0' scrolling='no' marginheight='0' marginwidth='0'></iframe>");
		}
	} else { // assumes adType == 'BIGBOX' or should
		if($("#bigbox").length > 0) {
			boxW = 300;
			boxH = 250;
			if (sync_banner.indexOf("336x850") > -1) {
				boxW = 336;
				boxH = 850;
			} else if (sync_banner.indexOf("300x600") > -1)	{
				boxW = 300;
				boxH = 600;
			}
			$("#bigbox").html("<iframe src='" + sync_banner + "\' width=\'" + boxW + "\' height=\'" + boxH + "\'" + "frameborder='0' scrolling='no' marginheight='0' marginwidth='0'></iframe>");
		}
	}
	return;
} 

// multiple sponsor logo tag
function MultiLogoAd(adtype,logoNum) {
	var ad = new DartAd();
	if (logoNum == undefined || logoNum == '' || logoNum > 4 || logoNum < 1) { logoNum = 4; }
	if (adtype == undefined || adtype == '') { adtype = 'LOGO';	}
	ad.setUrl("http://"+SNI.Ads._adServerHostname+"/snDigitalLogo"+logoNum+".html?");
	ad.addParameter("adtype", adtype );
	ad.addParameter("PagePos", 1 );
	if (logoNum > 0) {
		writeAd(ad);
		$(document).ready( function() {
			if ($(".sponsor-multi-logo a img").length > 0) {
				$(".sponsor-multi-logo").prepend("<em>Sponsored by:</em>");
			}
		});
	}
}


//==ENDECA Functions Begin ===============================================================
//functions added at the request of Amy Thomason for the Endeca recipe search

function WDGuidedNavSearchAds(adtype, pos, keywords, filters, pageNo) {
	var ad = new DartAd();
	if(pos < 0 || pos == undefined) {
		pos = 1;
	}
	if(pageNo > 0 && pageNo != undefined) {
	   ad.addParameter("Page", pageNo);
	}
	ad.setUrl("http://"+SNI.Ads._adServerHostname+"/js.ng/");
	ad.addParameter("adtype", adtype);
	ad.addParameter("adsize", "");
	ad.addParameter("PagePos", pos);
	// ad.addParameter("Params.styles", "trace");
	var words = keywords.split(" ");
	for(i = 0; i < words.length; i++) {
		ad.addParameter("keyword", words[i]);
	}
	var words = filters.split(" ");
	for(i = 0; i < words.length; i++) {
		ad.addParameter("filter", words[i]);
	}
	writeAd(ad);
}


function WDGuidedNavSiteAdAds(adtype, keywords, filters, pageNo) {
	WDGuidedNavSearchAds(adtype, 1, keywords, filters, pageNo);
	//WDGuidedNavSearchAds(adtype, 2, keywords, filters, pageNo)
}

//==ENDECA Functions End ===============================================================

if (typeof(SNI.HealthyEats.Newsletter) === "undefined") { 
	SNI.HealthyEats.Newsletter = {}; 
}

SNI.HealthyEats.Newsletter = {

	init: function() {			
		var validator = $("#subscribe").validate({
   
	debug: false,

		rules: {
			food_healthy_eats: "required",
			email: { 
				required: true,
				email: true
			},
			email_confirm: {
				required: true,
				equalTo: "#email"
			},
			FIRST_NAME_: "required",
			LAST_NAME_: "required",
			POSTAL_CODE_: "required"
		},
	
		messages: {
			food_healthy_eats: "Please select at least one newsletter",
			email: "Please enter your email address",
			email_confirm: "Please confirm your email address",
			FIRST_NAME_: "Please enter your first name",
			LAST_NAME_: "Please enter your last name",
			POSTAL_CODE_: "Please enter your ZIP code"
		},
	
		errorContainer: ".form-error",
		errorLabelContainer: $(".list", ".form-error"),
		wrapper: "li",
		showErrors: function(errorMap, errorList) {
			if (errorList.length) {
				$('html, body').fadeIn().animate({scrollTop:0}, 'slow');
				this.defaultShowErrors();
			}
		} 
	
	});
	
	// toggle for required checkall
	$("fieldset#sister-sites").find(".select-all").click(function(){
		
		var $this = $(this);
	
		var checkValue = $this.find('#all-news-toggle').text();
		
		if (checkValue === 'Select all'){
			$("#sister-sites input[type='checkbox']").each(function() {
				$("#sister-sites input[type='checkbox']").attr('checked', true);
			});
			$this.find('#all-news-toggle').text('Select none');
		} else {
			$("#sister-sites input[type='checkbox']").each(function() {
				$("#sister-sites input[type='checkbox']").attr('checked', false);
			});
			$this.find('#all-news-toggle').text('Select all');
		}
		
		return false;
	}); // end toggle for checkall


}};



SNI.HealthyEats.Newsletter.Change = {

	init: function() {			
		var validator = $("#changemail").validate({
   
	debug: false,

		rules: {
			email: { 
				required: true,
				email: true
			},
			emailnew: { 
				required: true,
				email: true
			},
			emailnew_confirm: {
				required: true,
				equalTo: "#emailnew"
			}
		},
	
		messages: {
			email: "Please enter your old email address",
			emailnew: "Please enter your new email address",
			email_confirm: "Please confirm your new email address"
		},
	
		errorContainer: ".form-error",
		errorLabelContainer: $(".list", ".form-error"),
		wrapper: "li",
		showErrors: function(errorMap, errorList) {
			if (errorList.length) {
				$('html, body').fadeIn().animate({scrollTop:0}, 'slow');
				this.defaultShowErrors();
			}
		} 
	
	
	});
	
}};


SNI.HealthyEats.Newsletter.Unsubscribe = {

	init: function() {			
		var validator = $("#unsubscribe").validate({
   
	debug: false,

		rules: {
			email: { 
				required: true,
				email: true
			},
			email_confirm: {
				required: true,
				equalTo: "#email"
			}
		},
	
		messages: {
			email: "Please enter your email address",
			email_confirm: "Please confirm your email address"
		},
	
		errorContainer: ".form-error",
		errorLabelContainer: $(".list", ".form-error"),
		wrapper: "li",
		showErrors: function(errorMap, errorList) {
			if (errorList.length) {
				$('html, body').fadeIn().animate({scrollTop:0}, 'slow');
				this.defaultShowErrors();
			}
		} 
	
	});
	
	// toggle for required checkall
	$("fieldset#sister-sites").find(".select-all").click(function(){
		
		var $this = $(this);
	
		var checkValue = $this.find('#all-news-toggle').text();
		
		if (checkValue === 'Select all'){
			$("#sister-sites input[type='checkbox']").each(function() {
				$("#sister-sites input[type='checkbox']").attr('checked', true);
			});
			$this.find('#all-news-toggle').text('Select none');
		} else {
			$("#sister-sites input[type='checkbox']").each(function() {
				$("#sister-sites input[type='checkbox']").attr('checked', false);
			});
			$this.find('#all-news-toggle').text('Select all');
		}
		
		return false;
	}); // end toggle for checkall

}};/* Video Player Object */

// instantiate object namespace
if( typeof(SNI.HealthyEats.Player)=='undefined' ) {
	SNI.HealthyEats.Player = {};
}



SNI.HealthyEats.Player.Configs = {
	FullSize : {
		dimensions : {
			width:'576',
			height:'638'
		},
		flashvars : {
			config:"http://web.hgtv.com/webhgtv/hg20/snap-configs/hgtv-player-fullsize.xml",
			channel:'',									// initial channel id to load
			channelurl:'',								// initial channel feed url to load
			videoid:''									// initial video id of channel to play
		},
		params : {
			menu:"false",
			scale:"noscale",
			allowFullScreen:"true",
			allowScriptAccess:"always",
			wmode:"transparent"
		}
	},

	FullSizeNoPlaylist : {
		dimensions : {
			width:'576',
			height:'460'
		},
		flashvars : {
			config:"http://web.hgtv.com/webhgtv/hg20/snap-configs/hgtv-player-fullsize-noplaylist.xml",
			channel:'',									// initial channel id to load
			channelurl:'',								// initial channel feed url to load
			videoid:''									// initial video id of channel to play
		},
		params : {
			menu:"false",
			scale:"noscale",
			allowFullScreen:"true",						// this is a flash thing and should be set to true
			allowScriptAccess:"always",					// we want to leave this at true
			wmode:"transparent"
		}
	},
	
	RightRail : {
		dimensions : {
			width:'320',
			height:'360'
		},
		flashvars : {
			config:"http://web.hgtv.com/webhgtv/hg20/snap-configs/hgtv-player-rightrail.xml",
			channel:'',									// initial channel id to load
			channelurl:'',								// initial channel feed url to load
			videoid:''									// initial video id of channel to play
		},
		params : {
			menu:"false",
			scale:"noscale",
			allowFullScreen:"true",						// this is a flash thing and should be set to true
			allowScriptAccess:"always",					// we want to leave this at true
			wmode:"transparent"
		}
	},
	
	Blog : {
		dimensions : {
			width:'320',
			height:'263'
		},
		flashvars : {
			config:"http://web.hgtv.com/webhgtv/hg20/snap-configs/hgtv-player-blog.xml",
			channel:'',									// initial channel id to load
			channelurl:'',								// initial channel feed url to load
			videoid:''									// initial video id of channel to play
		},
		params : {
			menu:"false",
			scale:"noscale",
			allowFullScreen:"true",						// this is a flash thing and should be set to true
			allowScriptAccess:"always",					// we want to leave this at true
			wmode:"transparent"
		}
	},
	
	Lead : {
		dimensions : {
			width:'400',
			height:'300'
		},
		flashvars : {
			config:"http://web.hgtv.com/webhgtv/hg20/snap-configs/hgtv-player-lead.xml",
			channel:'',									// initial channel id to load
			channelurl:'',								// initial channel feed url to load
			videoid:''									// initial video id of channel to play
		},
		params : {
			menu:"false",
			scale:"noscale",
			allowFullScreen:"true",						// this is a flash thing and should be set to true
			allowScriptAccess:"always",					// we want to leave this at true
			wmode:"transparent"
		}
	}
};




// video library version of player
SNI.HealthyEats.Player.FullSize = function(divId, channelId, videoId) {
	return new SNI.Player.SNAP(divId, SNI.HealthyEats.Player.Configs.FullSize, channelId, videoId);
};
SNI.HealthyEats.Player.Big = SNI.HealthyEats.Player.FullSize;							// alias
SNI.HealthyEats.Player.VideoLibrary = SNI.HealthyEats.Player.FullSize;				// alias


// single video asset version of player
SNI.HealthyEats.Player.FullSizeNoPlaylist = function(divId, channelId, videoId) {
	return new SNI.Player.SNAP(divId, SNI.HealthyEats.Player.Configs.FullSizeNoPlaylist, channelId, videoId);
};
SNI.HealthyEats.Player.VideoAsset = SNI.HealthyEats.Player.FullSizeNoPlaylist;		// alias


// right rail version of player
SNI.HealthyEats.Player.RightRail = function(divId, channelId, videoId) {
	return new SNI.Player.SNAP(divId, SNI.HealthyEats.Player.Configs.RightRail, channelId, videoId);
};


// for players dropped into pickle2 rate my apps
SNI.HealthyEats.Player.RightRailMyHGTV = function(divId, channelId, videoId) {
	buildChannelFeedUrlForPickle = function(chId) {
		return 'http://www.hgtv.com/hgtv/channel/xml/0,,' + chId + ',00.xml';
	};

	return new SNI.Player.SNAP(divId, SNI.HealthyEats.Player.Configs.RightRail, channelId, videoId, buildChannelFeedUrlForPickle);
};


// blog version of player (no playlist)
SNI.HealthyEats.Player.Blog = function(divId, channelId, videoId) {
	buildChannelFeedUrlForBlogs = function(chId) {
		return 'http://www.hgtv.com/hgtv/channel/xml/0,,' + chId + ',00.xml';
	};

	return new SNI.Player.SNAP(divId, SNI.HealthyEats.Player.Configs.Blog, channelId, videoId, buildChannelFeedUrlForBlogs);
};


// lead/dynamic-lead version of player
SNI.HealthyEats.Player.Lead = function(divId, channelId, videoId) {
	return new SNI.Player.SNAP(divId, SNI.HealthyEats.Player.Configs.Lead, channelId, videoId);
};

/* temporary functions */

$(document).ready(function() {

	//Tag Click Info
	$('#tag_cloud a').click(function() { 
		var s=s_gi('scrippshealthyeats');
		var linkText = $(this).text();
		s.linkTrackVars='prop1,eVar8,events';
		s.linkTrackEvents='event12';
		s.prop1=linkText;
		s.eVar8=linkText;
		s.events='event12';
		s.tl(this,'o','Tag Click');
	});
	
	//Category Click Info
    $('.widget_categories a').click(function() { 
        var s=s_gi('scrippshealthyeats');
        var linkText = $(this).text();
        s.linkTrackVars='prop11,eVar9,events';
        s.linkTrackEvents='event15';
        s.prop11=linkText;
        s.eVar9=linkText;
        s.events='event15';
        s.tl(this,'o','Category Click');
    });
	
	//RSS Clicks
	$('.nav .rss a').click(function() { 
		var s=s_gi('scrippshealthyeats');
		s.linkTrackVars='events';
		s.linkTrackEvents='event10';
		s.events='event10';
		s.tl(this,'o','RSS Click');
	});
	
	//Newsletter Clicks
	$('#subscribe button').click(function() {
		var s=s_gi('scrippshealthyeats');
		s.linkTrackVars='events';
		s.linkTrackEvents='event11';
		s.events='event11';
		s.tl(this,'o','Newsletter Click');
	});
	
	/*Email Clicks
	var s=s_gi('scrippshealthyeats');
	s.linkTrackVars='events';
	s.linkTrackEvents='event13';
	s.events='event13';
	s.tl(this,'o','Email Click');
	*/

});


/*
if(typeof(SNI.HealthyEats.Omniture)=='undefined') {
	SNI.HealthyEats.Omniture = {};
}

SNI.HealthyEats.Omniture.ClickTrackSpecific = function(jsel, module, propVal) {

  var $el = $(jsel);
	
	if($el.length == 0) {return;}

	$el.click( function(e) {

		var $clicked=$(e.target);
					
			var s=s_gi(s_account);	
	
			s.linkTrackVars=propVal;			
			//s.events=linkTrackEvents;

			s[propVal] = module;
		
			s.tl(this,'o',propVal);	
			e.stopPropagation();

			//alert(propVal,s);

			
	});

};

SNI.HealthyEats.Omniture.ClickTrackSpecificLinkText = function(jsel, module, propVal) {
  
  var $el = $(jsel);
	
	if($el.length == 0) {return;}
	
	$el.click( function(e) {

		var $clicked=$(e.target);
		
		if ($clicked.is("a") || $clicked.parent().is("a")) {
			var linkText = $clicked.attr('href');
			if ((linkText == "") && ($clicked.is("img"))) {
				linkText = $clicked.attr("alt");
			}
			
			var s=s_gi(s_account);	
	
			s.linkTrackVars=propVal;

			s[propVal] = linkText;
		
			s.tl(this,'o','Link Name');	
			e.stopPropagation();
		}
	});

};
*/