var SNI = SNI || {};SNI.TP = SNI.TP || {};SNI.TP.settings = SNI.TP.settings || {};SNI.Food.Player.inlineDefaultAds = function (divId, channelId, videoId, callback, ui_config) {	var callbackSystem = function (eventType, eventInfo) {	    if (eventType == 'itemBegin') {		     if(typeof setDefaultBigboxAd == "function") {			// removed to enable refreshing of synced ads			//   setDefaultBigboxAd();		       }	    }	};		$(function(){		return new SNI.Player.SNAP({			"container_div_id": divId,			"ui_config": SNI.Util.mergeObjects(SNI.Player.UserInterfaceConfigs.FullSizeNoPlaylist, ui_config, true),			"channel_id": channelId,			"video_id": videoId,			"fcn_callback_user": callback,			"fcn_callback_system": callbackSystem                      		    });	});    };SNI.TP.util = {                                                                                                	injectscript : function(url){		$.ajax({url: url, 			dataType: 'script',			cache: true,			timeout: 5000});	},//end injectscript                                                 	isTentpole : function(cfg){		cfg = cfg || {};		cfg.siteWrapper = cfg.siteWrapper || '#main-bd';		cfg.siteWrapper = $(cfg.siteWrapper);				var wrapperFound = cfg.siteWrapper.find('div.fn-full:first'),		    check = false;		    		if(wrapperFound.length > 0 && wrapperFound.attr('class').indexOf('tp-asset') > -1){		    check = true;		}                                				return check;	},//end isTentpole	isPackage: function(){		if( $('body').hasClass('package') ){			return true;		}		else{			return false;		}	}};SNI.TP.social = {	FBLike : function(cfg) {		cfg = cfg || {};		cfg.url = cfg.url || window.location.href.replace(/\?(.)*?$/,''); // URL to like is either specified or the current URL by default		cfg.style = cfg.style || 'button_count'; // like button style is either specified or standard by default		cfg.dest = cfg.dest || '#fn-w'; // node to be used for injection		cfg.width = cfg.width || 200;		cfg.height = cfg.height || 81;		cfg.injectionMethod = cfg.injectionMethod || 'prepend'; // jQuery injection method to be used		cfg.wrapper = cfg.wrapper || $('<span />', {id : 'fb-like'}); // wrapper of include code to be used				var embedcode = {			standard : '<iframe src="http://www.facebook.com/plugins/like.php?href=' + cfg.url + '&amp;send=true&amp;layout=standard&amp;width=' + cfg.width + '&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=' + cfg.height + '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:' + cfg.width + 'px; height:' + cfg.height + 'px;" allowTransparency="true"></iframe>',			button_count : '<iframe src="http://www.facebook.com/plugins/like.php?href=' + cfg.url + '&amp;send=true&amp;layout=button_count&amp;width=' + cfg.width + '&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=' + cfg.height + '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:' + cfg.width + 'px; height:' + cfg.height + 'px;" allowTransparency="true"></iframe>',			box_count : '<iframe src="http://www.facebook.com/plugins/like.php?href=' + cfg.url + '&amp;send=false&amp;layout=box_count&amp;width=' + cfg.width + '&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=' + cfg.height + '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:' + cfg.width + 'px; height:' + cfg.height + 'px;" allowTransparency="true"></iframe>'		},		getembedcode = function(type){			return embedcode[type];		};				// convert string to jquery object		cfg.dest = $(cfg.dest);		// call injection method on jquery node to insert FB like markup		cfg.dest[cfg.injectionMethod](			function(stuff){				cfg.wrapper.html(					function(){						return getembedcode(cfg.style);					}				);								return cfg.wrapper;			}			);	},	TWShare : function(cfg){		var current_page = window.location.href.replace(/\?(.)*?$/,''),		    widget = $('<a />')		    default_attrs = {		    			'class' : 'twitter-share-button', 		    			'href' : 'http://twitter.com/share', 		    			'data-url' : current_page, 		    			'data-text' : '', 		    			'data-counturl' : current_page, 		    			'data-count' : 'vertical'		    		    };				cfg = cfg || {};		cfg.JS = cfg.JS || 'http://platform.twitter.com/widgets.js';		cfg.injectionMethod = cfg.injectionMethod || 'prepend';		cfg.attrs = cfg.attrs || default_attrs;		cfg.dest = cfg.dest || $('#tweet-anywhere-e');				SNI.TP.util.injectscript(cfg.JS);				for(var prop in cfg.attrs){			widget.attr(prop, cfg.attrs[prop]);		}				widget.attr('data-text', function(){				return $(this).attr('data-text').replace(/\%(.)*?\%/, current_page);;		})				// call injection method on jquery node to insert FB like markup		cfg.dest[cfg.injectionMethod](widget);									}};SNI.TP.holidayCountdown = {        	// function created to display the number of days remaining between the current day and a specified date in the future	init : function(cfg){		var module,                       		    daywrap,		    oneDay = 24 * 60 * 60 * 1000,		    remaining,		    tipswrap;		    		cfg = cfg || {};		cfg.endDate = new Date(cfg.endDate); // required		cfg.today = new Date();		cfg.parent = cfg.parent || '#fn-e';		cfg.module = cfg.module || 'div.countdown:first';		cfg.daywrap = cfg.daywrap || '#num-days';		cfg.hasZero = cfg.hasZero || true; // determines how to display single digits ie: 1 displayed as '1' or '01'		cfg.tips = cfg.tips || false;		cfg.tipswrap = cfg.tipswrap || '#tip';		                                                        	        module = $(cfg.module, cfg.parent);                         		daywrap = $(cfg.daywrap);		remaining = Math.floor( (cfg.endDate.getTime() - cfg.today.getTime()) / (oneDay) ) + 1; // hours*minutes*seconds*milliseconds		tipswrap = $(cfg.tipswrap);		    		if (remaining < 0){			module.remove();			return;		}           		else {			if($.isArray(cfg.tips)){				tipswrap.html(cfg.tips[cfg.tips.length - remaining]);			}						if(cfg.hasZero === true){				if(remaining.toString().length === 1){					remaining = '0' + remaining;				}                         			}   			    			daywrap.html(remaining); // display the number of days remaining until the end date    		}                                     	}};SNI.TP.thumbCollection = {	init : function(cfg){		cfg = cfg || {};				var parent = cfg.parent || 'div.thumb-collection',		    thumbs = cfg.thumbs || 'li',		    tip = cfg.tip || 'div.tip';		    		    $('#fn-w').css('overflow','visible');		    SNI.TP.thumbCollection.currentTip = '';		    parent = $(parent, '#fn-w');		    thumbs = parent.find(thumbs);		    thumbs.bind('mouseenter',			    function(evt){				    var tag = $(this);				    				    tag.addClass('hover');				    SNI.TP.thumbCollection.currentTip = tag;				    				    SNI.TP.settings.timer = setTimeout(					    function(){						    tag.find(tip).fadeIn('fast');					    }    				    ,250);			    }		    );    		    		    thumbs.bind('mouseleave',			    function(evt){				    var tag = $(this);				    				    clearTimeout(SNI.TP.settings.timer);				    tag.find(tip).fadeOut('fast');				    tag.removeClass('hover');       			    }		    );                                 	}};SNI.TP.tabHighlight = function(cfg){		// implementation of JS-powered tentpole nav tab highlighting for formatter-driven pages		// done using the page's sponsorship code		// designed to accept a lookup table of sponsorshipCode:className key:value pairs		cfg = cfg || {};				var dest = $('div.fn-full:first','#main-bd'),		    sponcode = mdManager.getSponsorship();		    		if(cfg.lookuptable === 'undefined'){ // throws error if key:value pairs aren't passed			throw new Error('no lookup table provided.');		}				if(dest.length > 0){			dest.addClass(cfg.lookuptable[sponcode]);		}		else {			$('body').addClass(cfg.lookuptable[sponcode]);		}			};SNI.TP.inits = {	'banner-tooltip' : function (cfg){			cfg = cfg || {};			var bnrcontainer = cfg.bnrcontainer || '#content',			    tt = cfg.tt || '#back-tooltip',			    tttext = cfg.tttext || '#back-tooltip-txt',			    $bnrcontainer = $(bnrcontainer),			      $tt = $(tt),			      $tttext = $(tttext),			      hide = function(){                                                            				      $tt.removeClass('tooltip-shown').stop().animate({'top' : -50,'opacity' : 0},						      function(){							      $(this).addClass('tooltip-hidden');						      }					      );				      $tttext.removeClass('tooltip-shown').stop().animate({'top' : -50,'opacity' : 0},						      function(){							      $(this).addClass('tooltip-hidden');						      }					      );			      },			      show = function(){                                                            				      $tt.removeClass('tooltip-hidden').stop().animate({'top' : 0,'opacity' : 0.5},						      function(){							      $(this).addClass('tooltip-shown');						      }					      );				      $tttext.removeClass('tooltip-hidden').stop().animate({'top' : 0,'opacity' : 1},						      function(){							      $(this).removeClass('tooltip-hidden').addClass('tooltip-shown');						      }					      );			      };			      			      SNI.Food.Omniture.ClickTrackSingle(bnrcontainer,'Tentpole Banner','Thanksgiving 2010');			      $bnrcontainer.hover(show, hide);				},	'transparent-nav' : function(){		var mc = $('#fn-w'),		    rr = $('#fn-e'),		    rrplayer = $('.rr-player-wrap:first',rr),		    rrplayerheight = (rrplayer.length) ? (340) : (0),		    content = $('div.content:first','#main-bd'), 		    mcheight = mc.height(),		    rrheight = rr.height(),		    rroffset = mcheight - rrheight;		    if(rroffset > 0){			    if(typeof document.all !== 'undefined'){				    rr.css('padding-bottom',rroffset + 50);			    }			    else {				    rr.css('padding-bottom',rroffset - rrplayerheight + 30);			    }			  			    content.addClass('tp-fix');		    }	},	'fire' : function(cfg){		cfg = cfg || [];				for(var i = cfg.length; i--;){			SNI.TP.inits[cfg[i]]();		}	}};SNI.TP.inlinePlayer = function(channel,id){	// todo: convert to more flexible version which implements a shared interface with the no-image version	id = id || 'graphic-lead-player';	var dims = {},	    make = {			'graphic-lead-player' : function(){				dims.width = 400;				dims.height = 300;			},			'static-lead-player' : function(){				dims.width = 266;				dims.height = 200;			}		};	    	    make[id]();	    	    $('#'+id).parent().bind('click',		    function(){			    $('#'+id).parent().find('img:first, span:first').hide();			    			    var snap = new SNI.Food.Player.FullSizeNoPlaylist(id, channel, '', '', {			    enableSyncAdFix: 1,			    'dimensions': {				width: dims.width,				height: dims.height			    },			    flashvars: {				autoPlay: true,				showMenu: false,				enableNowPlayingOverlay: false,				enableRelatedMenu: false,				enableRelatedInfoIcon: false,				enableEmail: false,				enableShare: false,				playerSize: 'Inline' // added to fix ad call			    }			});		                 		    }	    );};SNI.TP.inlinePlayerNoImage = function(cfg){	cfg.playerType = cfg.playerType || 'static-lead-player';	cfg.wrapperID = cfg.wrapperID || '';	cfg.channelID = cfg.channelID || '';	cfg.videoID = cfg.videoID || ''; 		var ui_config = {},	getFlashvars = function(){		return  {		    autoPlay: cfg.autoplay || false,		    enableRelatedInfoIcon: cfg.enableRelatedInfoIcon || false,		    enableNowPlayingOverlay: cfg.enableNowPlayingOverlay || false,		    playerSize: 'Inline',		    enableHomePageMode: cfg.enableHomePageMode || true	    };	},	    id,	    playerInstance = SNI.Food.Player.FullSizeNoPlaylist,	    dims = {		    width: 266,		    height: 200	    },	    make = {			'graphic-lead-player' : function(){				dims.width = 400;				dims.height = 300;				cfg.wrapperID = 'graphic-lead-player';							},			'static-lead-player' : function(){				dims.width = 266;				dims.height = 200;				cfg.wrapperID = 'static-lead-player';			}		};		make[cfg.playerType]();	       		if(SNI.TP.util.isTentpole() === true  || ( SNI.TP.util.isPackage() === true  && $('.graphic-lead.module').length>0 ) ){		/* 		extended the player type from just tentpoles to tentpoles and packages with graphic leads		*/		playerInstance = SNI.Food.Player.inlineDefaultAds;	}			return new playerInstance(		cfg.wrapperID, cfg.channelID, cfg.videoID, null, SNI.Util.mergeObjects(			{			    flashvars: {				    autoPlay: cfg.autoplay || false,				    enableRelatedInfoIcon: cfg.enableRelatedInfoIcon || false,				    enableNowPlayingOverlay: cfg.enableNowPlayingOverlay || false,				    playerSize: 'Inline',				    enableHomePageMode: cfg.enableHomePageMode || true				},			    dimensions: dims		        }, ui_config, true		)	);	};SNI.TP.voteCallout = function(cfg){	// retrieve poll results	// find winner	// calculate winner's percentage of the votes	// create/manipulate and display show		cfg.serviceURL = cfg.serviceURL || 'http://cfusion.hgtv.com/com/sni/universalpoll/tentpoleFanFavoriteResultsJSON.cfm';	cfg.moduleURL = cfg.moduleURL || '';	cfg.moduleWrapper = cfg.moduleWrapper || '#vote-callout';	cfg.calloutWrapper = cfg.calloutWrapper || '#vote-results-info';		var results = cfg.results || [],	    votes = [],	    winner,	    winnerPercentage,	    totalVotes,	    calloutIntroText = '',	    n = $('<div />'),	    handleResults;	    	$(		function(){			// add total votes and store in local var 			totalVotes = ( function(){				    var total = 0,					i, len;             							      				    len = results.length;   				    for(i = len; i--;){					    total += parseInt(results[i].votes, 10);  					    votes.push(results[i].votes);				    }				    return total;                    			}() );						// sort results to find largest vote count			votes = votes.sort(function(a,b){return b-a;});						// find and store winner in local var			winner =  $.grep(results,					function(elem, idx){						return (elem.votes === votes[0]);					}					  );  			winner = winner.pop();  						// calculate winning choice/constestant vote percentage			winnerPercentage = Math.round( (winner.votes / totalVotes) * 100);       						// set content for eventual module			calloutIntroText = winner.name + ' is in the lead with  ' + winnerPercentage + '% of the vote.';			                                     			$(cfg.calloutWrapper).html(calloutIntroText);						// un-hide module wrapper			$(cfg.moduleWrapper).removeClass('hide');		}// end load callback	);			};SNI.TP.voteDataCallback = function (votedata){		SNI.TP.voteCallout(		{			results : votedata.data		}		);};SNI.TP.Status_Inject = function(cfg){	cfg = cfg || {};		var DEFAULT_CONFIG = { contestants : 'star' },			asset_node = $('#main-bd .fn-full'),			grid_node = $('#finalists-lead ul'),			grid_talent_ident = ".t-",			grid_target=' a:first',			treatment_grid_class = 'ribbon-elim',			treatment_overview_class = 'ribbon-elim-lg',			overview_target = '.sec-lead.talent-lead span:first',			contestants = {				star : {					grid : { 'asset' : 'tp-asset-102401' },					overviews : [							 {								 'name': 'Alicia Sanchez',								 'id': 4202,								 'eliminated': true,								 'asset': 'tp-asset-102275'							},							{                 								'name': 'Chris Nirschel',								'id': 4203,								'eliminated': true,								'asset': 'tp-asset-102276'							},							{								'name': 'Howie Drummond',								'id': 4204,								'eliminated': true,								'asset': 'tp-asset-102277'							},							{								'name': 'Jeff Mauro',								'id': 4205,								'eliminated': false,								'asset': 'tp-asset-102278'							},							{								'name': 'Juba Kali',								'id': 4206,								'eliminated': true,								'asset': 'tp-asset-102279'							},							{								'name': 'Justin Balmes',								'id': 4207,								'eliminated': true,								'asset': 'tp-asset-102280'							},							{								'name': 'Justin Davis',								'id': 4208,								'eliminated': true,								'asset': 'tp-asset-102281'							},							{								'name': 'Jyll Everman',								'id': 4209,								'eliminated': true,								'asset': 'tp-asset-102282'							},{								'name': 'Katy Clark',								'id': 4210,								'eliminated': true,								'asset': 'tp-asset-102283'							},							{								'name': 'Mary Beth Albright',								'id': 4211,								'eliminated': true,								'asset': 'tp-asset-102284'							},							{								'name': 'Orchid Paulmeier',								'id': 4212,								'eliminated': true,								'asset': 'tp-asset-102285'							},{								'name': 'Penny Davidi',								'id': 4213,								'eliminated': true,								'asset': 'tp-asset-102286'							},{								'name': 'Susie Jimenez',								'id': 4214,								'eliminated': true,								'asset': 'tp-asset-102287'							},							{								'name': 'Vic "Vegas" Moea',								'id': 4215,								'eliminated': true,								'asset': 'tp-asset-102288'							},							{								'name': 'Whitney Chen',								'id': 4216,								'eliminated': true,								'asset': 'tp-asset-102289'							}					]			}	},	applyTreatment = function(type){		var fns = {			grid  : function(){				// iterate over contestants in the JSON above and apply eliminated treatment via DOM manipulation as needed				for(i=0; i < contestants.star.overviews.length; i++){					// if there is a grid item that matches them  && theyre eliminated					if ( grid_node.find(grid_talent_ident+contestants.star.overviews[i].id)  && contestants.star.overviews[i].eliminated === true ){						//add in the eliminated div to their 						$( grid_talent_ident+contestants.star.overviews[i].id+grid_target).prepend('<div class="'+treatment_grid_class+'"></div>');					}				}			},			overview : function(){					for( i=0; i < contestants.star.overviews.length; i++ ){					// if [ who is this ]  && [ are they eliminated ]					if( (asset_node.hasClass(contestants.star.overviews[i].asset)) && (contestants.star.overviews[i].eliminated===true) ){						// inject code to the talent lead						$(overview_target).prepend('<div class="'+treatment_overview_class+'"></div>');						break;					}				}							}		}		switch(getPageType()){			case "grid":				fns.grid();				break;			case "overview":				fns.overview();				break;			default:				break;		}	},	getPageType = function(){		var pageType=false;		// check if we're on a the grid page		if ( asset_node.hasClass(contestants.star.grid.asset) ){			pageType="grid";		}		//skip this if we have a pagetype		if (!pageType){		// check if were on a contestant page			for (i=0; i < contestants.star.overviews.length; i++){				if ( asset_node.hasClass( contestants.star.overviews[i].asset ) ){					pageType="overview";					break;				}			}		}		//if this is a supported page, apply treatment		return pageType;	};			// override defaults in configurations as needed	cfg = $.extend(DEFAULT_CONFIG, cfg);	applyTreatment();};if (typeof(SNI.Food.Sweepstakes) === "undefined") { 		SNI.Food.Sweepstakes = {}; }SNI.Food.Sweepstakes = {	init: function(cfg) {		cfg = cfg || {};		cfg.target = cfg.target || ".sweepsForm"				var validator = $(cfg.target).validate({   	debug: false,	rules: {		fanFav: "required",		fanFav2: "required",		fvFirst: "required",		fvLast: "required",		fvAddress1: "required",		fvCity: "required",		fvState: "required",		fvZip: "required",		fvEvePhone: "required",		fvEmail: "email",		fvEmail: { 			required: true,			email: true		},		fvEmailConfirm: {			required: true,			equalTo: "#fvEmail"		}	},	messages: {		fanFav: "Please select one finalist to eliminate",		fanFav2: "Please select your favorite finalist",		fvFirst: "Please enter your first name",		fvLast: "Please enter your last name",		fvAddress1: "Please enter your address",		fvCity: "Please enter your city",		fvState: "Please select your state",		fvZip: "Please enter your ZIP code",		fvEvePhone: "Please enter a phone number",		fvEmail: "Please enter an e-mail address",		fvEmailConfirm: "Please make sure your e-mails match"	},			errorContainer: ".form-error",		errorLabelContainer: $(".list-alt", ".form-error"),		wrapper: "li",		showErrors: function(errorMap, errorList) {		if (errorList.length) {			$('html, body').fadeIn().animate({scrollTop:0}, 'slow');			this.defaultShowErrors();		} else {			if(window.onbeforeunload != "undefined") {				window.onbeforeunload = null;			}		}	},				submitHandler: function(form) {		//get form values and assign to variables		var voteFirst = $("input#fvFirst").val();		var voteLast = $("input#fvLast").val();		var voteEmail = $("input#fvEmail").val();		var voteEmailConfirm = $("input#fvEmailConfirm").val();		var voteAddress1 = $("input#fvAddress1").val();		var voteCity = $("input#fvCity").val();		var voteState = $("select#fvState").val();		var voteZip = $("input#fvZip").val();		var votePhone = $("input#fvEvePhone").val();		//take variables and add them to cookie		SNI.Util.Cookie.persist("voterData", "voteFirst", voteFirst);		SNI.Util.Cookie.persist("voterData", "voteLast", voteLast);		SNI.Util.Cookie.persist("voterData", "voteEmail", voteEmail);		SNI.Util.Cookie.persist("voterData", "voteEmailConfirm", voteEmailConfirm);		SNI.Util.Cookie.persist("voterData", "voteAddress1", voteAddress1);		SNI.Util.Cookie.persist("voterData", "voteCity", voteCity);		SNI.Util.Cookie.persist("voterData", "voteState", voteState);		SNI.Util.Cookie.persist("voterData", "voteZip", voteZip);		SNI.Util.Cookie.persist("voterData", "votePhone", votePhone);				form.submit();		}	});	// toggle for morelink		$(".morelink").find("a.moretoggle").click(function(){				if ($(".morelink a.moretoggle").hasClass('active')){				$(".morelink a.moretoggle").removeClass('active');				$(".morelink .morelist").hide(250);				return false;			} else {				$(".morelink .morelist").show(250);				$(".morelink a.moretoggle").addClass('active');				return false;			}		}); // end toggle for morelink			//toggle for optional checkall		$('.newsletter-opt-in .checkall').click(function(e){			var target = $(this).parent('li').parent('ul').find('input:checkbox'); //get all the options in the option group						//check the event dom for what this is changing to			//e.srcElement for IE			if(e.srcElement){				if(e.srcElement.checked===true){					target.attr('checked', true);					}				else{									target.attr('checked', false)				}			}			else{			//currentTarget for FF				if(e.currentTarget){					if(e.currentTarget.checked===true){						target.attr('checked', true);					}					else{										target.attr('checked', false)					}				}			}								})// end toggle for checkall}};
