$(document).ready(function(){
	/******* Anchors *******/
	$("a").click(function(){
		$(this).blur();
	});
	$("a[href=#]").click(function(){
		return false;
	});

	/******* Style URL Handler *******/
	if(window.location.search.indexOf("style=") > -1){
		$.cookie("style", $.jqURL.get('style'), {expires: 500, path: '/'});
	}

	/******* Style Switcher *******/
	$("#switcher .yellow").click(function(){
		$("body").removeAttr("class").addClass("yellow");
		$.cookie("style", "yellow", {expires: 500, path: '/'});
		$('#subheader h1').sifr({ font: 'helvetica-medium' });
		if(window.location.pathname.indexOf("/videos") > -1){
			var frameSrc  = $("iframe:first").attr("src");
			if(frameSrc.indexOf("skin") == -1){
				frameSrc = frameSrc + "&skin=library1";
				$("iframe:first").attr("src",frameSrc);
			}
		}
	});
	$("#switcher .blue").click(function(){
		$("body").removeAttr("class").addClass("blue");
		$.cookie("style", "blue", {expires: 500, path: '/'});
		$('#subheader h1').sifr({ font: 'helvetica-medium' });
		if(window.location.pathname.indexOf("/videos") > -1){
			var frameSrc  = $("iframe:first").attr("src");
			if(frameSrc.indexOf("skin") > -1){
				frameSrc = frameSrc.replace("skin=library1","");
				$("iframe:first").attr("src",frameSrc);
			}
		}
	});

	/*if($.cookie("style") != null && $.cookie("style") != $("body").attr("class")){
		var correctStyle = $.cookie("style");
		$("body").removeAttr("class").addClass(correctStyle);
		$.cookie("style", correctStyle, {expires: 500, path: '/'});
		$('#subheader h1').sifr({ font: 'helvetica-medium' });
	}*/

	/******* Search Box *******/
	$("#search .query").focus(function(){
		if($(this).val() == "Title, Actor, Director, or Genre"){
			$(this).val("");
		}
	});
	$("#search .query").blur(function(){
		if($(this).val() == ""){
			$(this).val("Title, Actor, Director, or Genre");
		}
	});

	/******* Sifr *******/
	// Text replacement
	if(window.location.host.indexOf("bhn.") > -1){
		$.sifr({
			path: '/BHN_VOD/assets/swf/fonts/',
			save: true
		});
	} else {
		$.sifr({
			path: '/assets/swf/fonts/',
			save: true
		});
	}
	$('#subheader h1').sifr({ font: 'helvetica-medium' });


	/******* Item Meta *******/
	$(".pod .item img").attr('alt','');

	var tooltipconfig = {    
		sensitivity: 2,
		interval: 200,
		over: function(){
		 $(this).find(".info").show();
		},
		out: function(){
		 $(this).find(".info").hide();
		}
	};

	$(".pod .item").hoverIntent( tooltipconfig )

	$(".pod .item").mousemove(function(e){
      	$(this).find(".info").css('top',e.pageY+10);
      	$(this).find(".info").css('left',e.pageX-50);
	 });
	$(".pod").each(function (){
		if($(this).find(".item").length == 0 && $(this).find("p.medium").length == 0){
			$(this).hide();
		}
	 });
});

var bhn = {};
bhn.listings = {};
bhn.listings.data = null;

// Channel Listings by Region
bhn.listings.channels = [];
bhn.listings.channels["east"] = [11006,10179,14902,10035,11867,10240,11115,10986];
bhn.listings.channels["tampa"] = [10179,11006,14902,10035,11867,10240,11115,10986];
bhn.listings.channels["centralfl"] = [10179,14902,11006,10035,11867,10240,11115,10986];
bhn.listings.channels["west"] = [21760,11867,11007,10179,34215,10244,11117,10987];

bhn.listings.getListings = function(market){
	var webroot = "";
	var service = "";
	var timezone = "";

	if(window.location.host.indexOf("bhn.") > -1){
		webroot = "/BHN_VOD/";
	} else {
		webroot = "/";
	}
	switch(market){
		case "122":
			region = "tampa";
			timezone = "1";
		break;
		case "121":
			region = "centralfl";
			timezone = "1";
		break;
		case "120":
			region = "west";
			timezone = "4";
		break;
		default:
			region = "east";
			timezone = "1";
		break;
	}

	service = webroot + "nowontvservice.aspx?timeZone="+timezone+"&channels="+bhn.listings.channels[region].join(",");

	$.getJSON(service,function(data){
		bhn.listings.data = data.data;
		var listContent = "";
		var styleCode = "";

		for(var i=0; i < bhn.listings.channels[region].length; i++){
			var pos = bhn.listings.find(bhn.listings.channels[region][i]);
			styleCode = "background-image:url("+webroot+"assets/images/content/listingsLogos/"+bhn.listings.data.tf_station_num[pos]+".png);";
			if($.browser.msie && $.browser.version < 7){
				styleCode = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+webroot+"assets/images/content/listingsLogos/"+bhn.listings.data.tf_station_num[pos]+".png', sizingMethod='crop')";
			}
			listContent += "<li><div class=\"logo\" style=\""+styleCode+"\">"+bhn.listings.data.affiliate[pos]+"</div> <div class=\"title\">"+bhn.listings.data.tf_title[pos]+"</div></li>";
		}
		$("#nowontv ul").html(listContent);
		$("#nowontv ul li:even").addClass("even");
		$("#nowontv ul li:odd").addClass("odd");

		// Set "As Of" Time
		var a_p = "";
		var d = new Date();
		var curr_hour = d.getHours();
		if (curr_hour < 12){
			a_p = "AM";
		}else{
			a_p = "PM";
		}
		if(curr_hour == 0){
			curr_hour = 12;
		}
		if(curr_hour > 12){
		   curr_hour = curr_hour - 12;
		}
		var curr_min = d.getMinutes();
		if(curr_min < 10){
			curr_min =  "0"+curr_min;
		}

		$("#nowontv .asof").text(curr_hour+":"+curr_min+" "+a_p);
	});
};
bhn.listings.find = function(id){
	for(var i=0; i < bhn.listings.data.affiliate.length; i++){
		if(bhn.listings.data.tf_station_num[i] == id){
			return i;
		}
	}
};


/************************
Global jQuery Plugins
*************************/
/******** Flash **********/
;(function(){var $$;$$=jQuery.fn.flash=function(htmlOptions,pluginOptions,replace,update){var block=replace||$$.replace;pluginOptions=$$.copy($$.pluginOptions,pluginOptions);if(!$$.hasFlash(pluginOptions.version)){if(pluginOptions.expressInstall&&$$.hasFlash(6,0,65)){var expressInstallOptions={flashvars:{MMredirectURL:location,MMplayerType:'PlugIn',MMdoctitle:jQuery('title').text()}};}else if(pluginOptions.update){block=update||$$.update;}else{return this;}}htmlOptions=$$.copy($$.htmlOptions,expressInstallOptions,htmlOptions);return this.each(function(){block.call(this,$$.copy(htmlOptions));});};$$.copy=function(){var options={},flashvars={};for(var i=0;i<arguments.length;i++){var arg=arguments[i];if(arg==undefined)continue;jQuery.extend(options,arg);if(arg.flashvars==undefined)continue;jQuery.extend(flashvars,arg.flashvars);}options.flashvars=flashvars;return options;};$$.hasFlash=function(){if(/hasFlash\=true/.test(location))return true;if(/hasFlash\=false/.test(location))return false;var pv=$$.hasFlash.playerVersion().match(/\d+/g);var rv=String([arguments[0],arguments[1],arguments[2]]).match(/\d+/g)||String($$.pluginOptions.version).match(/\d+/g);for(var i=0;i<3;i++){pv[i]=parseInt(pv[i]||0);rv[i]=parseInt(rv[i]||0);if(pv[i]<rv[i])return false;if(pv[i]>rv[i])return true;}return true;};$$.hasFlash.playerVersion=function(){try{try{var axo=new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');try{axo.AllowScriptAccess='always';}catch(e){return'6,0,0';}}catch(e){}return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g,',').match(/^,?(.+),?$/)[1];}catch(e){try{if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){return(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g,",").match(/^,?(.+),?$/)[1];}}catch(e){}}return'0,0,0';};$$.htmlOptions={flashvars:{},pluginspage:'http://www.adobe.com/go/getflashplayer',src:'#',type:'application/x-shockwave-flash'};$$.pluginOptions={expressInstall:false,update:true,version:'6.0.65'};$$.replace=function(htmlOptions){this.innerHTML='<div class="alt">'+this.innerHTML+'</div>';jQuery(this).addClass('flash-replaced').prepend($$.transform(htmlOptions));};$$.update=function(htmlOptions){var url=String(location).split('?');url.splice(1,0,'?hasFlash=true&');url=url.join('');var msg='<p>This content requires the Flash Player. <a href="http://www.adobe.com/go/getflashplayer">Download Flash Player</a>. Already have Flash Player? <a href="'+url+'">Click here.</a></p>';this.innerHTML='<span class="alt">'+this.innerHTML+'</span>';jQuery(this).addClass('flash-update').prepend(msg);};function toAttributeString(){var s='';for(var key in this)if(typeof this[key]!='function')s+=key+'="'+this[key]+'" ';return s;};function toFlashvarsString(){var s='';for(var key in this)if(typeof this[key]!='function')s+=key+'='+encodeURIComponent(this[key])+'&';return s.replace(/&$/,'');};$$.transform=function(htmlOptions){htmlOptions.toString=toAttributeString;if(htmlOptions.flashvars)htmlOptions.flashvars.toString=toFlashvarsString;return'<embed '+String(htmlOptions)+'/>';};if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};});}})();


/******** Sifr **********/
jQuery.fn.sifr=function(prefs){var p=jQuery.extend((prefs===false)?{unsifr:true}:{},arguments.callee.prefs,prefs);if(p.save){arguments.callee.prefs=jQuery.extend(p,{save:false});}if(this[0]===document){return;}if(!p.unsifr&&typeof p.before==='function'){p.before.apply(this,[p]);}this.each(function(){var t=jQuery(this);var a=t.children('.sIFR-alternate');if(a){t.html(a.html());if(p.unsifr){return;}}if(typeof p.beforeEach==='function'){p.beforeEach.apply(this,[t,p]);}var s=t.html('<span class="flash-replaced sIFR-replaced">'+(p.content||t.html()).replace(/^\s+|\s+$/g,'')+'</span>').children();a=t.append('<span class="alt sIFR-alternate">'+s.html()+'</span>').children('.sIFR-alternate');if(a.css('display')!=='none'){a.css('display','none');}var toHex=function(c){var h=function(n){if(n===0||isNaN(n)){return'00';}n=Math.round(Math.min(Math.max(0,n),255));return'0123456789ABCDEF'.charAt((n-n%16)/16)+'0123456789ABCDEF'.charAt(n%16);};c=(c)?c.replace(/rgb|\(|\)|#$/g,''):false;if(!c){return false;}if(c.indexOf(',')>-1){c=c.split(', ');return'#'+h(c[0])+h(c[1])+h(c[2]);}if(c.search('#')>-1&&c.length<=4){c=c.split('');return'#'+c[1]+c[1]+c[2]+c[2]+c[3]+c[3];}return c;};if(p.textTransform){if(p.textTransform.toLowerCase()==='uppercase'){s.html(s.html().toUpperCase());}if(p.textTransform.toLowerCase()==='lowercase'){s.html(s.html().toLowerCase());}if(p.textTransform.toLowerCase()==='capitalize'){var c=s.html().replace(/\>/g,'> ').split(' ');for(var i=0;i<c.length;i=i+1){c[i]=c[i].charAt(0).toUpperCase()+c[i].substring(1);}s.html(c.join(' ').replace(/\> /g,'>'));}}var f={flashvars:jQuery.extend({h:s.height()*(p.zoom||1),offsetLeft:p.offsetLeft||undefined,offsetTop:p.offsetTop||undefined,textAlign:p.textAlign||(/(left|center|right)/.exec(t.css('textAlign'))||['center'])[0],textColor:toHex(p.color||t.css('color'))||undefined,txt:p.content||s.html(),underline:(p.underline||(p.underline!==false&&t.css('textDecoration')==='underline'))?true:undefined,w:(p.width||s.width())*(p.zoom||1)},p.flashvars),height:p.height||s.height(),src:(p.path||'')+((p.path&&p.path.substr(p.path.length-1)!=='/')?'/':'')+(p.font||'')+((p.font&&p.font.indexOf('.swf')===-1)?'.swf':''),width:p.width||s.width(),wmode:'transparent'};f.flashvars.linkColor=toHex(p.link||t.find('a').css('color'))||f.flashvars.textColor;f.flashvars.hoverColor=toHex(p.hover)||f.flashvars.linkColor;if(p.zoom){f.flashvars.offsetTop=((p.offsetTop||0)+((s.height()-(s.height()*p.zoom))/2))*(p.zoomTop||1);f.flashvars.offsetLeft=((p.offsetLeft||0)+((s.width()-(s.width()*p.zoom))/2))*(p.zoomLeft||1);}t.flash(jQuery.extend(f,p.embedOptions),jQuery.extend({expressInstall:p.expressInstall||false,version:p.version||7,update:p.update||false},p.pluginOptions),function(f){var preHeight=t.height();var preWidth=t.width();s.html(jQuery.fn.flash.transform(f));var e=s.find(':first');e.css({verticalAlign:'text-bottom',display:'inline',width:p.width,height:p.height});var marginBottom=preHeight-t.height();var width=parseInt(e.css('width'),10)+parseInt(preWidth-t.width(),10);if(!p.height){e.css({marginBottom:marginBottom});}if(!p.width){e.css({width:width});}if(p.height&&p.verticalAlign==='middle'){e.css({marginTop:Math.floor((p.height-s.height())/2),marginBottom:Math.round((p.height-s.height())/2),height:s.height()});e.attr('height',s.height());}if(p.height&&p.verticalAlign==='bottom'){var a=t.find('.sIFR-alternate');e.css({marginTop:(p.height-s.height()),height:s.height()});e.attr('height',s.height());}if(p.css){e.css(p.css);}});if(typeof p.afterEach==='function'){p.afterEach.apply(this,[t,p]);}});if(!p.unsifr&&typeof p.after==='function'){p.after.apply(this,[p]);}};jQuery.sifr=function(prefs){jQuery().sifr(jQuery.extend({save:true},prefs));};jQuery.fn.unsifr=function(){return this.each(function(){jQuery(this).sifr(false);});};


/** hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+  <http://cherne.net/brian/resources/jquery.hoverIntent.html> */
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/******** Cookies **********/
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}};

/******** Query String Handler **********/
jQuery.jqURL={url:function(args){args=jQuery.extend({win:window},args);return args.win.location.href;},loc:function(urlstr,args){args=jQuery.extend({win:window,w:500,h:500,wintype:'_top'},args);if(!args.t){args.t=screen.height/2-args.h/2;}
if(!args.l){args.l=screen.width/2-args.w/2;}
if(args['wintype']=='_top'){args.win.location.href=urlstr;}
else{open(urlstr,args['wintype'],'width='+args.w+',height='+args.h+',top='+args.t+',left='+args.l+',scrollbars,resizable');}
return;},qs:function(args){args=jQuery.extend({ret:'string',win:window},args);if(args['ret']=='string'){return jQuery.jqURL.url({win:args.win}).split('?')[1];}
else if(args['ret']=='object'){var qsobj={};var thisqs=jQuery.jqURL.url({win:args.win}).split('?')[1];if(thisqs){var pairs=thisqs.split('&');for(i=0;i<pairs.length;i++){var pair=pairs[i].split('=');qsobj[pair[0]]=pair[1];}}
return qsobj;}},strip:function(args){args=jQuery.extend({keys:'',win:window},args);if(jQuery.jqURL.url().indexOf('?')==-1){return jQuery.jqURL.url({win:args.win});}
else if(!args.keys){return jQuery.jqURL.url({win:args.win}).split('?')[0];}
else{var qsobj=jQuery.jqURL.qs({ret:'object',win:args.win});var counter=0;var url=jQuery.jqURL.url({win:args.win}).split('?')[0]+'?';var amp='';for(var key in qsobj){if(args.keys.indexOf(key)==-1){amp=(counter)?'&':'';url=url+amp+key+'='+qsobj[key];counter++;}}
return url;}},get:function(key,args){args=jQuery.extend({win:window},args);qsobj=jQuery.jqURL.qs({ret:'object',win:args.win});return qsobj[key];},set:function(hash,args){args=jQuery.extend({win:window},args);var qsobj=jQuery.jqURL.qs({ret:'object',win:args.win});for(var i in hash){qsobj[i]=hash[i];}
var qstring='';var counter=0;var amp='';for(var k in qsobj){amp=(counter)?'&':'';qstring=qstring+amp+k+'='+qsobj[k];counter++;}
return jQuery.jqURL.strip({win:args.win})+'?'+qstring;}};