var palette=palette||{page:{},banner:{},tabs:[{},{},{},{}],interactionElements:""};

$(document).ready(function() {
	
	$("#banner-noFlash").each(function (){
		
		if(!swfobject.hasFlashPlayerVersion("9.0.115")) {
			jQuery("#banner-noFlash").removeClass("hide");
		}
		
		var highlights = []; 
		var omniProps = 1;
		$(this).find("li").each(function () {
			var $this = $(this);
			highlights.push({
				"titleOne": $.trim($this.find('span.titleOne').text()),
				"titleTwo": $.trim($this.find('span.titleTwo').text()),
				"subHeaderOne": $.trim($this.find('span.subTitleOne').text()),
				"subHeaderTwo": $.trim($this.find('span.subTitleTwo').text()),
				"subHeaderLink": ($this.find('a.subTitleLink').attr('href')!="")?$this.find('a.subTitleLink').attr('href')+"?intcmp=homepage_carousel"+omniProps : "",
				"tabLabel": $.trim($this.find('span.tab-label').text()).split(":")[0],
				"tabText": $.trim($this.find('span.tab-text').text()).split(":")[0],
				"fourodurl": $this.find('a.fourodurl').attr('href') || "",
				"img":{
					"src": $this.find('img').attr('src') || "",
					"alt": $this.find('img').attr('alt') || ""
				},
				"outlineColor":palette.tabs[highlights.length].outline||"#000000",
				"txtColor":palette.tabs[highlights.length].text||"#FFFFFF",
				"txtOverColor":palette.tabs[highlights.length].activeLinkText||"#000000",
				"linkBGColor":palette.tabs[highlights.length].activeLinkBg||"#FFFFFF",
				"tabTxtColor":palette.page.text||"#FFFFFF",
				"tabTxtOverColor":palette.banner.activeTabText||"#000000",
				"tabColor":palette.page.background||"#000000",
				"tabOverColor":palette.banner.activeTabBg||"#FFFFFF"
			}); 
			omniProps++;	
		});
		
		var flashVars = {
			"highlights":encodeURIComponent($.toJSON(highlights)),
			"bgColor":palette.page.background||"#000000"
		};
		
		var params = {
	        "width":"925",
	        "height":"354",
	        "wmode":"opaque",
	        "salign":"top",
	        "quality":"high",
	        "bgcolor":palette.page.background||"#000000",
	        "name":"highlights",
	        "allowScriptAccess":"always"
		};
	
		
		var attributes = {
			id:"highlights"	
		};
		
		swfobject.embedSWF(
			"/static/film4/asset/flash/swf/highlights.swf",
			"banner-inner",
			"925",
			"354",
			"9.0.115",
			"/static/film4/asset/flash/swf/expressInstall.swf",
			flashVars,
			params,
			attributes
		);
	
	});
	
	$("#ontv-noFlash").each(function (){

		var thisweek = [];
		
		$(this).find("div.slot").each(function () {
			var $this = $(this);
			thisweek.push({
				"title": $.trim($this.find('.slotTitle').text()),
				"link": ($this.find('a.slotLink').attr('href')!="")?$this.find('a.slotLink').attr('href')+"?intcmp=homepage_tv-listings" : "/ontv"+"?intcmp=homepage_tv-listings",
				"time": $.trim($this.find('.slotTime').text()),
				"img":{
					"src": $this.find('img.slotImg').attr('src') || "",
					"alt": $this.find('img.slotImg').attr('alt') || ""
				}
			}); 	
		});
		
				
		var flashVars = {
			thisweek:encodeURIComponent($.toJSON(thisweek)),
			"bgColor":palette.page.background||"#000000",
			"txtColor":palette.page.text||"#FFFFFF",
			"txtOverColor":palette.banner.activeTabText||"#000000",
			"linkBGColor":palette.banner.activeTabBg||"#FFFFFF"
		};
				
		var params = {
	        width:"600",
	        height:"190",
	        wmode:"opaque",
	        salign:"top",
	        quality:"high",
	        bgcolor:palette.page.background||"#000000",
	        name:"thisweek",
	        allowScriptAccess:"always"
		};
	
		var attributes = {
			id:"thisweek"	
		};
				
		swfobject.embedSWF(
			"/static/film4/asset/flash/swf/this-week.swf",
			"ontv-noFlash",
			"600",
			"190",
			"9.0.115",
			"/static/film4/asset/flash/swf/expressInstall.swf",
			flashVars,
			params,
			attributes
		);
		
	});
	
	$("#newon-noFlash").each(function (){

		var newon = [];
		
		$(this).find("li").each(function () {
			var $this = $(this);
			newon.push({
				"title": $.trim($this.find('h3').text()),
				"url": ($this.find('a').attr('href')!="")?$this.find('a').attr('href')+"?intcmp=homepage_whats-new":"",
				"synopsis": $.trim($this.find('p').text()),
				"thumb":{
					"src": $this.find('img').attr('src') || "",
					"alt": $this.find('img').attr('alt') || ""
				},
				"img":{
					"src": $this.find('img').attr('src').substr(0,$this.find('img').attr('src').lastIndexOf("_")) + "_243x104.jpg" || "",
					"alt": $this.find('img').attr('alt') || ""
				}
			}); 	
		});
		
		var flashVars = {
			newon:encodeURIComponent($.toJSON(newon)),
			"bgColor":palette.page.background||"#000000",
			"txtColor":palette.page.text||"#FFFFFF"
		};
				
		var params = {
	        width:"600",
	        height:"213",
	        wmode:"opaque",
	        salign:"top",
	        quality:"high",
	        bgcolor:palette.page.background||"#000000",
	        name:"newon",
	        allowScriptAccess:"always"
		};
	
		var attributes = {
			id:"newon"	
		};
				
		swfobject.embedSWF(
			"/static/film4/asset/flash/swf/new-on.swf",
			"newon-noFlash",
			"600",
			"213",
			"9.0.115",
			"/static/film4/asset/flash/swf/expressInstall.swf",
			flashVars,
			params,
			attributes
		);
		
	});

});