IFILM.AdObj = function(targ, scriptSrc, confObj, disableRefresh, showCallout) {
	this.targ = targ;
	this.scriptSrc = scriptSrc;
	this.disableRefresh = disableRefresh || false;
	this.showCallout = showCallout || false;
	this.config = confObj || {
		width: '300',
		height: '251',
		FRAMEBORDER: "0",
		border: "0",
		marginwidth: "0",
		marginheight: "0",
		hspace: "0",
		vspace: "0",
		scrolling: "no", 
		style: "border: none",
		src: "/iframe/vciframesrc.jsp?advurl=" + encodeURIComponent(scriptSrc),
		allowtransparency: 'true'
	}
	IFILM.adManager.addAd(this);
	safelog("Ad Object created with scriptSrc:" + scriptSrc, "info", "IFILM.AdObj");	
}

IFILM.AdObj.prototype = {
	previouslyHidden: false,
	display: function() {
		var displayAt = jq('#' + this.targ).get(0);
		if(displayAt && displayAt.tagName) {
			var iframe;
			if(displayAt.tagName.toLowerCase() != "iframe") {
				var na = new NodeAssembly(displayAt);
				if(this.showCallout)
					na.createEl('p', {'class':'ad_callout'}, 'ADVERTISEMENT');
				var iframe = na.createElWithReturn("iframe", this.config);
				na.insertIn();
			} else {
				var iframe = displayAt;
			}
			
			safelog(this.scriptSrc);
			
			this.targetFrame = iframe;
			this.addHeightAdjustTrigger();
			
			var scriptTag= this.createAdString();
			this.dispatchAd(scriptTag);
		}
	},
	
	adjustHeight: function(targetFrame) {
		var cw = targetFrame.contentDocument || targetFrame.contentWindow.document;
		try {
			if(cw) {
				var atHTML = cw.getElementsByTagName("html")[0];
				if(atHTML) {
					var docSize = cw.body.scrollHeight || atHTML.offsetHeight;
					var rawSize = targetFrame.height;
					
					if(Math.abs(docSize - rawSize) > 20 && docSize < 700)
						targetFrame.height = docSize;
				}
				
				if(jq("img[src='http://m1.2mdn.net/viewad/817-grey.gif']", cw).get(0))
					jq(targetFrame).parent().hide();
			}
		} catch(e) {
			safelog("Error auto-resizing ad " + e, "Error", "IFILM.AdObj.adjustHeight");
		}
	},
	
	addHeightAdjustTrigger: function() {
		var adjustHeight = this.adjustHeight;
		if(this.targ != 'globalTextAdUnit') {
			jq(this.targetFrame).load(function(e) {
				adjustHeight(this);
			});
		}
	},
	
	createAdString: function() {
		var scriptTag = "/iframe/vciframesrc.jsp?advurl=" + encodeURIComponent(this.scriptSrc);
		scriptTag +=  "&ifilmrnd=" + Math.round(Math.random() * 1000000) + '-' + Math.round(Math.random() * 1000000);
		return scriptTag;
	
	},
	dispatchAd: function(adString) {
		if(this.targetFrame ) {
			var dispatcher = this.targetFrame.contentDocument || this.targetFrame.contentWindow.document; 
			var adLoc = adString || this.createAdString();
			this.adDisplayed = true;
		}
		
	},
	targetFrame: null,
	adDisplayed: false,
	refresh: function() {
		jq('#' + this.targ).empty();
		this.display();
	},
	styleref: [
		'<style type="text/css">',
		'body {margin:0; padding: 0; border: none; }',
		'</style><style type="text/css">',
		'a img { border: none; }',
		'</style>'
	]

}

IFILM.adManager = {
	ads: [],
	banner: null,
	ad_refresh_rate: null,
	timer: 10,
	textAd: function(msg) {
		if(StringUtils.trim(jq("#globaltxtad").html()) != '')
			jq("#globaltxtad").fadeOut("normal", function() { jq("#globaltxtad").html(msg); });
		else
			jq("#globaltxtad").html(msg);
			
		jq('#globaltxtad a').html(StringUtils.truncate(jq("#globaltxtad a").html(),60));
		jq('#globaltxtad').fadeIn("normal");
		
		//if(document.location.toString().indexOf('show') != -1)
			//jq('body').css('background-position', 'center 14px');
	},
	hideChannelPlayer: function() {
		jq('#SUPPLEMENT embed,#SUPPLEMENT object').css('display', 'none');
	},
	revealAds: function() {
		var adLim = IFILM.adManager.ads.length;
		for(i = 0; i < adLim; i++) {
			if(!IFILM.adManager.ads[i].previouslyHidden)
				jq('#' + IFILM.adManager.ads[i].targ + ' *').css('visibility', 'visible');
		}

		jq('body>iframe').not('#dsHistoryFrame').css('visibility','visible');
	},
	obscureAds: function() {
		var adLim = IFILM.adManager.ads.length;
		for(i = 0; i < adLim; i++) {
			if(jq('#' + IFILM.adManager.ads[i].targ).css('visibility') == 'hidden' || jq('#' + IFILM.adManager.ads[i].targ).css('display') == 'none')
				IFILM.adManager.ads[i].previouslyHidden = true;
				
			jq('#' + IFILM.adManager.ads[i].targ + ' *').css('visibility', 'hidden');
		}
		
		
		jq('body>iframe').not('dsFrame').css('visibility','hidden');
	},
	displayAds: function() {
		var adlim = this.ads.length;
		for(var x=0; x<adlim; x++)  {
			try {
				if(this.ads[x]) { this.ads[x].display(); }
			} catch(e) { safelog(e, "ERROR", "IFILM.adManager.displayAds"); }
			//this.ads[x] = null;
		}
	},
	refreshAds: function() {
		
		var adlim = this.ads.length;
		for(var x=0; x<adlim; x++) {
			if(this.ads[x].targ == 'HEADERAD') { 
				//jq('#HEADER').removeClass('ad-fullheader').css('background-image', 'url(http://dyn.ifilm.com/website/ver2/header_bg.png)') ;
				jq("#IFILM iframe").remove();
				jq('#HEADER .click_through').remove();
			}
			
			//jq('body iframe:last').remove();
			
			if(this.ads[x] && !this.ads[x].disableRefresh) { 
				this.ads[x].refresh(); 
			} else {
				safelog("reloading ad disabled for " + (x+1) + " of " + adlim, "info", "IFILM.adManager");
			}
		}
	},
	addAd: function(adObj) {
		if(adObj.display) {
			this.ads.push(adObj);
		}
	},
	displayAdsGeneric: function() {
		IFILM.adManager.displayAds();
	},
	displaySkin: function(frame) {
	},
	attachSkin: function(style_src) {
		var stylesheets = document.getElementsByTagName('link');
		var has_stylesheet = false;
		stylesheetLim = stylesheets.length;
		
		for(i = 0; i < stylesheetLim; i++) {
			if(style_src == stylesheets[i].href) {
				has_stylesheet = true;
			}
		}
		
		if(!has_stylesheet) {
			var parent_head = document.getElementsByTagName('head')[0];
			var e = document.createElement('link');
			e.type = 'text/css';
			e.href = style_src;
			e.rel = 'stylesheet';
			e.media = 'screen';
			parent_head.appendChild(e);
		}
	},
	hideAds: function(hideEl) {
		if(hideEl) { 
			hideEl.style.display = "none";
			if(hideEl.parentNode) {
				hideEl.parentNode.style.display="none";
				jq('#' + hideEl.parentNode.id + '_top, #' + hideEl.parentNode.id + '_bottom').css('display','none');
			}
		}
	},
	makeFullheader: function(url, clickThrough) {
		
		
		//if(jq.browser.msie && jq.browser.version < 7) {
		//	url = url.replace(/\.png/,'.jpg');
		//}
		
		//jq('#HEADER').css({'background-image': 'url('+url+')', 'background-repeat': 'no-repeat', 'background-position': 'top left'}).addClass('ad-fullheader').end();
		jq("#HEADERAD").css({'visibility': 'hidden', 'border':'0'});
		
		if(clickThrough)
			jq('#HEADER').prepend('<a href="' + clickThrough + '" target="_blank" class="click_through clearfix">&nbsp;</a>');
	
		if(jq.browser.msie && jq.browser.version < 7)
			jq('#HEADER a.click_through').css('z-index', '2000');
			
		jq('#LOGO a').css({position: 'relative', 'z-index': '2000'});
		
		jq('#HEADER .click_through').css({ 'top': '94px', 'left': jq('#BODYCONTENT').offset().left + 'px'});
		
			
			
	}, 
	createInterstitial: function(width) {
		if(!width) width = 600;
		try {
			tbGenerateOverlay();		
			jq('#INTERSTITIAL').before('<div id="timer">SPIKE.com will appear in <span id="timercount">:0' + IFILM.adManager.timer + '</span> seconds</div>');
			jq("#INTERSTITIAL").before('<div id="closead"><a href="#" id="closeadlink">Continue to SPIKE.com</a>');
			
			jq('#TB_window').remove();
			jq("#TB_overlay,#closeadlink").click(IFILM.adManager.removeInterstitial);
		} catch(e) { safelog(e); }
		
		jq(document).keyup(function(e) {
			if (e == null) // ie
				keycode = event.keyCode;
			else // mozilla
				keycode = e.which;
				
			if(keycode == 27) // close
				IFILM.adManager.removeInterstitial();
		});
		
		if(ie)
			 jq('html').css('overflow', 'hidden');
		
		if(width == 300) {
			jq('#INTERSTITIAL iframe,#INTERSTITIAL').css({ "width":"300px", "height":"250px"});
			jq('#timer').css('margin-top','75px');
		}
		
				 
		jq('#INTERSTITIAL').css({'margin-left':'-' + width/2 + 'px', 'margin-top':'-200px'}).show();
		
		jq("body>iframe,body>embed,body>object,#BODYCONTENT iframe, #BODYCONTENT embed, #BODYCONTENT object").css('visibility', 'hidden');
		IFILM.adManager.obscureAds();
		setTimeout(IFILM.adManager.incrementTimer, '1000');	
		IFILM.cookieManager.setSessionCookie('prestitial', true);
		
		if ( !(jQuery.browser.msie && jQuery.browser.version < 7) ) // take away IE6
			jq("#INTERSTITAL").css({marginTop: '-' + parseInt((200 / 2),10) + 'px'});
		
	},
	removeInterstitial: function(e) {
		if(e) { preventDefault(e); }
		
		jq("#TB_overlay").fadeOut("fast",function(){jq('#closead,#gt_link,#timer,#INTERSTITIAL,#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
		jq(document).unbind("keyup");
		jq("#closeadlink").unbind()
		
		jq("body>iframe,body>embed,body>object,#BODYCONTENT iframe,#BODYCONTENT embed,#BODYCONTENT object").css('visibility', 'visible');
		IFILM.adManager.revealAds();
				
		if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
			jq("body","html").css({height: "auto", width: "auto"});
			jq("html").css("overflow","");
		}
	},
	incrementTimer: function() {
		IFILM.adManager.timer--;
		
		jq('#timercount').html(':0' + IFILM.adManager.timer);
		if(IFILM.adManager.timer != 0)
			setTimeout(IFILM.adManager.incrementTimer,'1000');
		else
			IFILM.adManager.removeInterstitial();
	},
	reskinningUnit: function(imageUrl, bgColor) {
		IFILM.adManager.reskinPage(imageUrl, bgColor);
		jq("#BODYCONTENT").css('background-color', 'transparent');
		jq('#ad1div iframe').css({'position': 'relative', 'width':'330px', 'height': '270px', 'background': 'transparent none'});
		jq('#ad1div').css({'background': 'transparent none', 'border': 0, 'padding': 0, 'margin-bottom': '20px'});
		jq("#ad1div_top, #ad1div_bottom").remove();
		
		setTimeout(IFILM.adManager.removeTopBottom, 250)
	},
	reskinPage: function(imageUrl, bgColor) {
		jq('body').css('background', bgColor + ' url(' + imageUrl + ') no-repeat top center');
	},
	removeTopBottom: function() {
		if(jq('#ad1div_top').get(0))
			jq("#ad1div_top,#ad1div_bottom").remove();
		else
			setTimeout(IFILM.adManager.removeTopBottom, 250)
	}
}

function textAd(msg) {
	IFILM.adManager.textAd(msg);
}

/* GLOBAL AD STUFF FROM FRAME 0 */

var adid = "";
var query = window.location.search.substring(1);
var queryparams = query.split("&");
/*  Global Adv Vars for Dart */
ord=Math.random()*10000000000000000;
var dartRef, hbxRef, refsiteSession, reftypeSession;
/* Global Analytics Vars and Refsite Session Cookie for HBX */
refsiteid = "";
referralType = "";

pageLoadFuncs.push(function() {	
	//ad refresh rate and displaying the ads, handled as the last function of global functions
	window.setTimeout(IFILM.adManager.displayAdsGeneric, 1000);
	try {
		var min = 10000;
		
		if(!IFILM.adManager.ad_refresh_rate || IFILM.adManager.ad_refresh_rate == '') 
			return;		
			
		ad_refresh_rate = IFILM.adManager.ad_refresh_rate;			
		var valInSeconds = parseInt(ad_refresh_rate)*1000;
		
		if(isNaN(valInSeconds) || valInSeconds < min) {
			valInSeconds = min;
		}
		safelog("reload interval: " + valInSeconds, "INFO", "ad refresh interval");
		
		var z = window.setInterval('IFILM.adManager.refreshAds()', valInSeconds);
	} catch(e) {
		safelog("problem reloading " + e.message, "ERROR", "ad refresh interval");
	}
});

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Javascript function for Flash tagging
function resolveLink(args){

//alert(args);
  var string=document.location.href; 
 

  if  ( string.indexOf("http://surveys.relevantview.com/sbox/asandboxdev.sbt/")  != -1)
  {
	  var getrev= new Array();
	  var getrev=string.split("http://surveys.relevantview.com/sbox/asandboxdev.sbt/");
	  var result=getrev[1];
	  var filename=result.split("/"); 
	   
	  var filenamefinal=filename[0];
	  var filenamefinal=result.split(",");
	  var respondentid = filenamefinal[0];
	  var surveyid = filenamefinal[1];
	  var questionid = filenamefinal[2];
	  var url1 = filename[1];
	  var url2 = filename[2]; 
	
	
		//alert("http://surveys.relevantview.com/sbox/asandboxdev.sbt/" + respondentid + "," + surveyid  + "," + questionid+",1,0/http/www.tvland.com/" + args);
	
		if (args.indexOf("http://") != -1)
	
			{
	
				args = args.replace(new RegExp(/^http:\/\//i),"http/");
	  
	  			document.location.href = "http://surveys.relevantview.com/sbox/asandboxdev.sbt/" + respondentid + "," + surveyid  + "," + questionid  +",1,0/" + args;
			}
	
		else
		{
	
			document.location.href = "http://surveys.relevantview.com/sbox/asandboxdev.sbt/" + respondentid + "," + surveyid  + "," + questionid  +",1,0/" + url1 + "/" + url2  + args;
		}
  }
  else
  {
	  document.location.href =  args;
  } 
}

 
 
// Javascript function for Flash tagging
function getLocation() { 

	var string=document.location.href; 
	if  ( string.indexOf("http://surveys.relevantview.com/sbox/asandboxdev.sbt/")  != -1)
	{
		var getrev= new Array(); 
		var getrev=string.split("http://surveys.relevantview.com/sbox/asandboxdev.sbt/"); 
		var result=getrev[1]; 
		var filename=result.split("/"); 
		     
		var filenamefinal=filename[0];
		var filenamefinal=result.split(","); 
		var respondentid = filenamefinal[0];
		var surveyid = filenamefinal[1];
		var questionid = filenamefinal[2];
		var url1 = filename[1];
		var url2 = filename[2];
		var url;
		if (args.indexOf("http://") != -1)

		{
			args = args.replace(new RegExp(/^http:\/\//i),"http/");
  
  			url = "http://surveys.relevantview.com/sbox/asandboxdev.sbt/" + respondentid + "," + surveyid  + "," + questionid  +",1,0/" + args;
		}

		else
		{
			url = "http://surveys.relevantview.com/sbox/asandboxdev.sbt/" + respondentid + "," + surveyid  + "," + questionid  +",1,0/" + url1 + "/" + url2  + args;
		}
		
	}  
	else
	{  
		var url = document.domain;
	}
	 return url;
}





// Relevant View Java Script - END!!!!!!

ScheduleManager = {
	scheduleUrl: '/spiketvschedule/',
	storedSchedule: null,
	tuneInFormats: {
		'SPKEHD': 'http://dyn.ifilm.com/website/ver2/dtv-record-hd.gif',
		'SPKE': 'http://dyn.ifilm.com/website/ver2/dtv-record-sd.gif'
	},
	today: new Date(),
	startTime: 2000,
	curPage: 1,
	maxPage: 0,
	dayDate: new Date(),
	dailySuccess: function(o) {
		try {
			jq('#filters').removeClass('loading');
			jq('#schedule').empty();
			var xml = o;
			ScheduleManager.storedSchedule = xml;
			shows = ScheduleManager.storedSchedule.getElementsByTagName("show");
			showsLim = shows.length;
			var na = new NodeAssembly(jq("#schedule").get(0));
			
			next_date = new Date(ScheduleManager.dayDate.getTime()+86400000);
			next_day = next_date.getDate();
			next_month = next_date.getMonth();
			next_year = next_date.getFullYear();
			
			prev_date = new Date(ScheduleManager.dayDate.getTime()-86400000);
			prev_day = prev_date.getDate();
			prev_month = prev_date.getMonth();
			prev_year = prev_date.getFullYear();
			
			
			var shift = na.createElWithAssembly('div', {'class':'shift'});
			if(new Date(new Date().getTime()+(86400000*7)).getDate() != ScheduleManager.dayDate.getDate()) {
				shift.createEl('a', {'href':'#dayview_' + next_day + '_' + parseInt(next_month+1) + '_' + next_year, 'id': 'next', 'class':'paging day'}, { htmlStr: "<img src='http://dyn.ifilm.com/website/ver2/schedule-day-next.gif' />" });
			}
			
			if(new Date().getDate() != ScheduleManager.dayDate.getDate()) {
				shift.createEl('a', {'href':'#dayview_' + prev_day + '_' + parseInt(prev_month+1) + '_' + prev_year, 'id': 'prev', 'class':'paging day'}, { htmlStr: "<img src='http://dyn.ifilm.com/website/ver2/schedule-day-prev.gif' />" });
			}
			
			shift.createEl('span', {}, ScheduleManager.dayDate.format("ddd, mmm d"));
			
			var filters = na.createElWithAssembly('div', {'id':'filters'});
			filters.createEl("strong", {}, "View:");
			filters.createEl("a", {"href":"#weekview"}, "This Week");
			filters.createTextEl("|");
			filters.createEl("a", {"href":"#dayview", "class": "active"}, "Today");
			
			var schedT = na.createElWithAssembly('table', {'id': 'schedule_table', 'cellspacing':'0', 'cellpadding':'0', 'border': '0', 'width': '100%', 'class': 'clearfix' });
			var schedhead = schedT.createElWithAssembly('tr');
			schedhead.createEl('th', { 'class': 'first-child', 'width': '50' }, { htmlStr: '&nbsp;' });
			schedhead.createEl('th', { 'width': '150' }, 'Show');
			schedhead.createEl('th', { 'width': '150' }, 'Episode');
			schedhead.createEl('th', { }, 'Description');
			var shows_index = 0;
			spaces_left = 15*2;
			
			for(i = 9; i < 24; i++) {
				
				row_class = shows_index%2?'':'alt_row'; 
				var tr = schedT.createElWithAssembly('tr', { 'class': row_class });
				var time = ScheduleManager.convertIntToTime(i, false);
				tr.createEl('td', { 'class': 'first-child', 'valign':'top' }, { htmlStr: '<div>' + time + '</div>' });
							
				var cur_time = i;
				if(cur_time > 23)
					cur_time = cur_time-24;
				
				if(cur_time.toString().length == 1)
					cur_time = '0' + cur_time;
				
				if(shows[shows_index].attributes.getNamedItem("showTime").value == cur_time + '00') {
					show_date = shows[shows_index].attributes.getNamedItem("showDate").value;
					show_time = shows[shows_index].attributes.getNamedItem("showTime").value; 
					this_show_date = ScheduleManager.convertShowTimeToDateTime(show_date, show_time);
					
					if(shows[shows_index] && show_date == shows[i+1].attributes.getNamedItem("showDate").value) {
						var next_show_date = ScheduleManager.convertShowTimeToDateTime(shows[shows_index+1].attributes.getNamedItem("showDate").value, shows[shows_index+1].attributes.getNamedItem("showTime").value);
					} else {
						var next_show_date = ScheduleManager.convertShowTimeToDateTime(show_date, '0400');
					}
					
					time_span = ((next_show_date - this_show_date)/1000)/60;
					col_span = Math.min(time_span/30, 28-i);
					
					col_span = Math.min(col_span, spaces_left);
					
					
					showUrl = StringUtils.trim(getTag(shows[shows_index], "showUrl"));
					showTitle = getTag(shows[shows_index], "showTitle");
					episodeTitle = getTag(shows[shows_index], "episodeTitle");
					episodeDescription = getTag(shows[shows_index], "episodeDescription");
						
					tune_in = shows[shows_index].getElementsByTagName('tuneIn');
					tune_in_html = '<div class="recordformats">';
					
					for(j = 0; j < tune_in.length;  j++) {
						if(j == 0)
							tune_in_html += '<strong>Record:</strong> ';
						tune_in_html += '<a href="' + tune_in[j].attributes.getNamedItem("url").value + '" target="_blank">';
						
						tune_in_html += '<img src="' + ScheduleManager.tuneInFormats[tune_in[j].attributes.getNamedItem("format").value] + '" />';
						tune_in_html += '</a>';
					}
					tune_in_html += '</div>';
					safelog(this_show_date + ' ' + next_show_date + ' ' + showTitle + ' ' + episodeTitle);					
					tr.createEl('td', { 'width': '150', 'class': 'show_cell', 'rowspan': col_span, 'valign':'top' }, { htmlStr: '<div>' + showTitle + ' ' + tune_in_html + '<span class="rating">(' + shows[shows_index].attributes.getNamedItem("rating").value + ')</span></div>' });
					tr.createEl('td', { 'width': '150', 'class': 'episode_cell','rowspan': col_span,  'valign':'top' },  { htmlStr: '<div>' + episodeTitle + '</div>'} );
					tr.createEl('td', { 'width': '380', 'class': 'description_cell','rowspan': col_span,  'valign':'top' }, {  htmlStr: '<div style="height: ' + 60*col_span + 'px">' + StringUtils.truncate(episodeDescription, 200*col_span) + '</div>' });
					shows_index++;
					spaces_left -= col_span;
				}	
				
				row_class = shows_index%2?'':'alt_row';
				tr2 = schedT.createElWithAssembly('tr', {'class':row_class});
				
				time = ScheduleManager.convertIntToTime(i, true);
				tr2.createEl('td', { 'class': 'first-child', 'valign':'top' }, { htmlStr: '<div>' + time + '</div>' });
		
				if(shows[shows_index].attributes.getNamedItem("showTime").value == cur_time + '30') {
					show_date = shows[shows_index].attributes.getNamedItem("showDate").value;
					show_time = shows[shows_index].attributes.getNamedItem("showTime").value;
					this_show_date = ScheduleManager.convertShowTimeToDateTime(show_date, show_time);
					
					if(shows[shows_index] && show_date == shows[shows_index+1].attributes.getNamedItem("showDate").value) {
						next_show_date = ScheduleManager.convertShowTimeToDateTime(shows[i+1].attributes.getNamedItem("showDate").value, shows[shows_index+1].attributes.getNamedItem("showTime").value);
					} else {
						next_show_date = ScheduleManager.convertShowTimeToDateTime(show_date, '0400');
					}
					
					var time_span = ((next_show_date - this_show_date)/1000)/60;
					var col_span = time_span/30;
					col_span = Math.min(col_span, spaces_left);
					
					var showUrl = StringUtils.trim(getTag(shows[shows_index], "showUrl"));
					var showTitle = getTag(shows[shows_index], "showTitle");
					var episodeTitle = getTag(shows[shows_index], "episodeTitle");
					var episodeDescription = getTag(shows[shows_index], "episodeDescription");
					
						
					tune_in = shows[shows_index].getElementsByTagName('tuneIn');
					tune_in_html = '<div class="recordformats">';
					
					for(j = 0; j < tune_in.length;  j++) {
						if(j == 0)
							tune_in_html += '<strong>Record:</strong> ';
						tune_in_html += '<a href="' + tune_in[j].attributes.getNamedItem("url").value + '" target="_blank">';
						
						tune_in_html += '<img src="' + ScheduleManager.tuneInFormats[tune_in[j].attributes.getNamedItem("format").value] + '" />';
						tune_in_html += '</a>';
					}
					
					tune_in_html += '</div>';
					tr2.createEl('td', { 'width': '150', 'class': 'show_cell','rowspan': col_span,  'valign':'top' }, { htmlStr: '<div>' + showTitle + ' ' + tune_in_html + ' <span class="rating">(' + shows[shows_index].attributes.getNamedItem("rating").value + ')</span></div>' });
					tr2.createEl('td', { 'width': '150', 'class': 'episode_cell','rowspan': col_span,  'valign':'top' },  { htmlStr: '<div>' + episodeTitle + '</div>'} );
					tr2.createEl('td', { 'class': 'description_cell','rowspan': col_span,  'valign':'top' }, {  htmlStr: '<div style="height: ' + 60*col_span + 'px">' + StringUtils.truncate(episodeDescription, 200*col_span) + '</div>' });
					shows_index++;
					
					spaces_left -= col_span;
				}
				
			}
			
			na.insertIn();
			ScheduleManager.addTriggers();
			ScheduleManager.filterTrigger();
			jq('.shift a').click(function(e) {
				
				var parts = jq(this).attr('href').split('#')[1].split('_');
				
				if(parts.length > 1) {
					ScheduleManager.dayDate = new Date(parts[3], parts[2]-1, parts[1]);
				}
				ScheduleManager.callSchedule();			
			});
		} catch(e) { safelog(e); }
	}, 
	success: function(o) {
		try {
			jq('#filters').removeClass('loading');
			jq('#schedule').empty();
			var xml = o;
			ScheduleManager.storedSchedule = xml;
			shows = ScheduleManager.storedSchedule.getElementsByTagName("show");
			showsLim = shows.length;
			var na = new NodeAssembly(jq("#schedule").get(0));
			
			var shift = na.createElWithAssembly('div', {'class':'shift'});
			shift.createEl('a', {'href':'#', 'id': 'prev', 'class':'paging'}, "\u00ab earlier");
			shift.createEl('a', {'href':'#', 'id': 'next', 'class':'paging'}, "later \u00bb");
			
			var filters = na.createElWithAssembly('div', {'id':'filters'});
			filters.createEl("strong", {}, "View:");
			filters.createEl("a", {"href":"#weekview", "class": "active"}, "This Week");
			filters.createTextEl("|");
			filters.createEl("a", {"href":"#dayview"}, "Today");
			
			na.createEl('span', { 'id': 'mask_ul', 'class': 'mask' }, ' ');
			na.createEl('span', { 'id': 'mask_bl', 'class': 'mask' }, ' ');
			na.createEl('span', { 'id': 'mask_ur', 'class': 'mask' }, ' ');
			na.createEl('span', { 'id': 'mask_br', 'class': 'mask' }, ' ');
			
			var schedule = na.createElWithAssembly('div', {"id": "show_schedule"});
			var date_div = na.createElWithAssembly('div', {'id': 'day_of_the_week'} );
			date_ul = date_div.createElWithAssembly('ul');
			date_ul.createEl('li', { 'class': 'first-child'}, ' ');
			
			var table = schedule.createElWithAssembly("div", { "id": "schedule_container", "class":"clearfix" });
			var ul_time = table.createElWithAssembly("ul", {"class":"time_heading"});
			
			right_now = new Date();
	
			for(i = 9; i < 28; i++) {
				ul_time.createEl('li', {}, { htmlStr: ScheduleManager.convertIntToTime(i, false) });
				ul_time.createEl('li', {}, { htmlStr: ScheduleManager.convertIntToTime(i, true) });
			}
			 
			var row_count = 1;
			var tr = new Array();
			cur_date = null;
			for(i = 0; i < showsLim; i++) {
				
				var show_date = shows[i].attributes.getNamedItem("showDate").value;
				var show_time = shows[i].attributes.getNamedItem("showTime").value; 
					
				var this_show_date = ScheduleManager.convertShowTimeToDateTime(show_date, show_time);
				if(!cur_date || cur_date != show_date) {
					cur_date = show_date;
					row_count++;
					tr[row_count] = table.createElWithAssembly("ul", { "class":"clearfix" });
					date_ul.createEl('li', {'class':'row_heading'}, { htmlStr: days[this_show_date.getDay()] + '<span>' + parseInt(this_show_date.getMonth()+1) + '/' + this_show_date.getDate() + '</span>'});
				}
				
				if(this_show_date.getHours() == 20) 
					start_point = ' start'
				else
					start_point = '';
					
				if(shows[i+1] && show_date == shows[i+1].attributes.getNamedItem("showDate").value) {
					var next_show_date = ScheduleManager.convertShowTimeToDateTime(shows[i+1].attributes.getNamedItem("showDate").value, shows[i+1].attributes.getNamedItem("showTime").value);
				} else {
					var next_show_date = ScheduleManager.convertShowTimeToDateTime(show_date, '0400');
				}
				
				var time_span = ((next_show_date - this_show_date)/1000)/60;
				if(time_span > 0) {
					var col_span = time_span/30;
					var width = (col_span*200);
					var showUrl = StringUtils.trim(getTag(shows[i], "showUrl"));
					var showTitle = getTag(shows[i], "showTitle");
					var episodeTitle = getTag(shows[i], "episodeTitle");
			
					var episodeDescription = getTag(shows[i], "episodeDescription");
				
					
					 
					
					if(jq.trim(episodeDescription) == '')
						episodeDescription = '<em>There is no description available</em>';
					
					try {
						var show_image = shows[i].getElementsByTagName("showUrl")[0].attributes.getNamedItem("image").value + '?width=50';
					} catch(e) { var show_image = ''; }
						
					if(showUrl != '') {
						var cell = tr[row_count].createElWithAssembly('li', { 'class': start_point + " length_" + col_span });
						var cellSpan = cell.createElWithAssembly('span', { 'class' : 'showTitle' });
						cellSpan.createEl('a', { 'href': showUrl, 'title': showTitle  } , showTitle);
					} else {
						var cell = tr[row_count].createElWithAssembly('li',{ 'class': start_point + " length_" + col_span });
						cell.createEl('span', {'class':'showTitle'}, showTitle);
						
					}
					
					if(StringUtils.trim(episodeTitle) != '' && episodeTitle != showTitle)
					cell.createEl('span', {'class':'epTitle', 'title': episodeTitle}, episodeTitle, 15*col_span);
							
					var div = cell.createElWithAssembly("div", {'class':'episodeDescription'});
					div.createEl('p', {'class':'epDescription'}, { htmlStr: StringUtils.truncate(episodeDescription, 100) + " <span>(" + shows[i].attributes.getNamedItem("rating").value + ")</span>"});
					record = div.createElWithAssembly('span', { 'class': 'recordformats' });
					
					tune_in = shows[i].getElementsByTagName('tuneIn');
					for(j = 0; j < tune_in.length;  j++) {
						if(j == 0)
							record.createEl('strong', {}, 'Record:');
						record_link = record.createElWithAssembly('a', { 'href': tune_in[j].attributes.getNamedItem("url").value, 'target': "_blank" });
						record_link.createEl('img', { 'src': ScheduleManager.tuneInFormats[tune_in[j].attributes.getNamedItem("format").value] });
					}
				}
				
			}
			
			na.insertIn();
			ScheduleManager.addTriggers();
			ScheduleManager.maxPage = jq('.time_heading li').size()-4;
			jq('#schedule_container ul:nth-child(even)').addClass('alt_row');
			ScheduleManager.filterTrigger();
		} catch(e) { safelog(e); }
	}, 
	updateScheduleTable: function(o) {
		xml = o || ScheduleManager.storedSchedule;
	}, 
	failure: function(o) {
		safelog(o);
	}, 
	callSchedule: function() {
		if(document.location.toString().indexOf('dayview') == -1) {
			fetchFromAjax(this.scheduleUrl, ScheduleManager, null, 'GET');
		} else {
			var today = ScheduleManager.dayDate;
			year =  today.getFullYear();
			month = today.getMonth()+1;
			the_date = today.getDate();
			
			if(the_date < 10)
				the_date = "0" + the_date;
				
			if(month < 10)
				month = "0" + month;
			fetchFromAjax('/spikeTVScheduleAfter?startTime=' + year + '' + month + '' + the_date + ':0900&showNo=100',{
				success: ScheduleManager.dailySuccess,
				failure: ScheduleManager.failure
			}, null, 'GET');
		}
	}, 
	convertShowTimeToDateTime: function(show_date, show_time) {
		var time_matches = show_time.match(/([0-9]{2})([0-9]{2})/);
		var date_matches = show_date.match(/([0-9]{4})([0-9]{2})([0-9]{2})/);
		var date = new Date();
		date.setHours(time_matches[1]);
		date.setMinutes(time_matches[2]);
		date.setSeconds(0);
		date.setMilliseconds(0);
		date.setYear(date_matches[1]);
		date.setMonth(date_matches[2]-1);	
		date.setDate(date_matches[3]);
		
		if(date.getHours() >= 0 && date.getHours() <=4)
			date.setDate(date.getDate()+1);
			
		return date;
	}, 
	convertIntToTime: function(time, isHalf) {
		var converted_time = null;
		
		if(time > 12 && time < 24) {
			var hour = time - 12;
			var time_of_day = "PM";
		} else if (time == 12) {
			var hour = 12;
			var time_of_day = "PM";
		} else if( time > 23 ) {
			if(time != 24)  
				var hour = time - 24;
			else
				var hour = 12;
				
			var time_of_day = "AM";
		} else {
			var hour = time;
			var time_of_day = "AM";
		} 
		
		return "<span>" + hour + "<span>:" + (isHalf?"30":"00") + " " + time_of_day + "</span></span>";
	}, 
	moveSchedule: function(e) {
		try {
			if(e) preventDefault(e);
			
			if(jq(this).attr('id') == 'next')
				var multiplier = -1;
			else
				var multiplier = 1;
			
			if(multiplier < 0)	
				ScheduleManager.curPage++;
			else
				ScheduleManager.curPage--;
	
			if(ScheduleManager.curPage < 0)
				ScheduleManager.curPage = 0;
			else if (ScheduleManager.curPage > ScheduleManager.maxPage)
				ScheduleManager.curPage = ScheduleManager.maxPage;
								
			
			if(ScheduleManager.curPage > 0 && ScheduleManager.curPage <= ScheduleManager.maxPage)
				jq('#show_schedule ul').animate( { 'left': ((ScheduleManager.curPage-1)*(-166)) + "px" }, "normal");
		} catch(e) { safelog(e); }
	}, 
	addTriggers: function() {
		ScheduleManager.maxPage = jq('.time_heading li').size()-3;
		if(document.location.toString().indexOf('day') == -1)
			jq('#schedule a.paging').click(ScheduleManager.moveSchedule);
		
		if(jq('#show_schedule .start:first').get(0)) {
			var offset = jq('#show_schedule .start:first').offset();
			var container_offset = jq('#show_schedule').offset();
			diff = offset.left - container_offset.left;
			
			ScheduleManager.curPage = Math.floor(diff/166)+1;
			shift = ((ScheduleManager.curPage-1)*-166);
			
			if(document.all) 
				jq('#show_schedule ul').css( { 'left':  shift + "px" });
			else
				jq('#show_schedule ul').animate( { 'left':  shift + "px" }, "normal");
		}
		
	}
};

pageLoadFuncs.push(function() {	
	ScheduleManager.addTriggers();
	
	if(document.location.toString().indexOf('day') == -1)
		jq('#schedule_container ul:nth-child(even)').addClass('alt_row');
});
