TSNSchedule = {
	'ScrollDelay' : 10000,
	'MenuActiveColor' : '#ff0000',
	'MenuInactiveColor' : '#666666',
	'OrderOfPages' : ['schedule_programnote','schedule_tsn','schedule_tsnalt','schedule_tsncs','schedule_nhlnet'],
	'CorrespondingMenuItems' : ['schedule_programnotemenu','schedule_tsnmenu', 'schedule_tsnaltmenu', 'schedule_tsncsmenu','schedule_nhlnetmenu'],
	'CorrespondingMenuContainers' : ['schedule_programnotemenublock','schedule_tsnmenublock', 'schedule_tsnaltmenublock', 'schedule_tsncsmenublock','schedule_nhlnetmenublock'],
	'LastAutoScrollingItem' : 2,
	'PageNames' : [],
	'Pages' : [],
	'MenuItems' : [],
	'ActiveItem' : false,
	'InactiveItem' : false,
	'ItemCount' : 0,
	'HasProgramNote' : 0,
	'IgnoreEvents' : false,
	'ActiveScheduleBlock' : null,
	'InactiveScheduleBlock' : null, 
	'ActiveMenu' : null,
	'InactiveMenu' : null,
	'ScheduleTimer' : null,
	'SupportsOpacity' : (window.external && (typeof window.XMLHttpRequest == "object") && document.body.filters) || (document.body.style.opacity !== undefined), // screen out 

	'AllowEvents' : function() { 
		TSNSchedule.IgnoreEvents = false; 
		TSNSchedule.ScheduleTimer = TSNSchedule.AutoAdvanceScroller.delay(TSNSchedule.ScrollDelay);
	},
	
	'DisallowEvents' : function() { 
		TSNSchedule.IgnoreEvents = true; 
		$clear(TSNSchedule.ScheduleTimer);
	},

	'GetRemoteSchedule' : function() {
		var dt = new Date();
		var timestamp = dt.getTime();
		myAjax = new Ajax("http://tsn.ca/datafiles/html/television/schedule.html?cachebuster=" + timestamp, { update:$('scheduleTimes'), method: 'get',onComplete:TSNSchedule.InitializeSchedule}).request();
	},

	'InitializeSchedule' :  function(){  
		var pageNumber = 0;
		var pageBlock;
		for (var item = 0; item < TSNSchedule.OrderOfPages.length; item++) {
			TSNSchedule.HasProgramNote = TSNSchedule.HasProgramNote || $('schedule_programnote') != null;
			if ($(TSNSchedule.OrderOfPages[item])) {
				pageNumber =TSNSchedule.Pages.length;
				TSNSchedule.Pages[ pageNumber ] = $(TSNSchedule.OrderOfPages[item]);
				TSNSchedule.Pages[ pageNumber ].style.display = item < 1 ? "block" : 'none';
				$(TSNSchedule.CorrespondingMenuContainers[item]).style.display = "inline";
				pageBlock = new Fx.Style(TSNSchedule.Pages[ pageNumber ],'opacity');
				pageBlock.set(0);
				TSNSchedule.PageNames[ pageNumber ] = TSNSchedule.OrderOfPages[item];
			}
			if ($(TSNSchedule.CorrespondingMenuItems[item])) {
				TSNSchedule.MenuItems[ pageNumber ] = $($(TSNSchedule.CorrespondingMenuItems[item]));
			}
		}
		TSNSchedule.ItemCount = TSNSchedule.Pages.length;
		TSNSchedule.Scroll(0);
	},

	'Show' : function(intItem) {
			TSNSchedule.Scroll(intItem + (TSNSchedule.HasProgramNote ? 0 : -1));
			return false;
	},
	'Scroll' : function(intItem) {
		if (TSNSchedule.IgnoreEvents) return false; // You can't initiate a new scroll until the old one is over
		if (intItem === TSNSchedule.ActiveItem) return false; // No need to do anything
		TSNSchedule.DisallowEvents();
		TSNSchedule.InactiveItem = TSNSchedule.ActiveItem;
		TSNSchedule.ActiveItem = intItem % TSNSchedule.ItemCount;
		if (TSNSchedule.InactiveItem !== false && TSNSchedule.Pages[TSNSchedule.InactiveItem]) {
			TSNSchedule.InactiveScheduleBlock = new Fx.Style(TSNSchedule.Pages[TSNSchedule.InactiveItem], 'opacity', {duration:TSNSchedule.SupportsOpacity ? 500 : 1});
			TSNSchedule.InactiveScheduleBlock.start(1,0);
			if (TSNSchedule.MenuItems[TSNSchedule.InactiveItem]) {
				TSNSchedule.InactiveMenu = new Fx.Style(TSNSchedule.MenuItems[TSNSchedule.InactiveItem], 'color', {duration:500});
				TSNSchedule.InactiveMenu.start(TSNSchedule.MenuInactiveColor);
			}
		}
		if (TSNSchedule.Pages[TSNSchedule.ActiveItem]) {
			TSNSchedule.Pages[TSNSchedule.ActiveItem].style.display = 'block';
			TSNSchedule.Pages[TSNSchedule.ActiveItem].style.opacity = 0;
			TSNSchedule.ActiveScheduleBlock = new Fx.Style(TSNSchedule.Pages[TSNSchedule.ActiveItem], 'opacity', {duration:TSNSchedule.SupportsOpacity ? 500 : 1,onComplete:TSNSchedule.CompleteScroll});
			TSNSchedule.ActiveScheduleBlock.start(0, 1);

			if (TSNSchedule.MenuItems[TSNSchedule.ActiveItem]) {
				TSNSchedule.ActiveMenu = new Fx.Style(TSNSchedule.MenuItems[TSNSchedule.ActiveItem], 'color', {duration:500});
				TSNSchedule.ActiveMenu.start(TSNSchedule.MenuActiveColor);
			}
		}
	},

	'CompleteScroll' : function() { 
		if (TSNSchedule.Pages[TSNSchedule.InactiveItem]) {
			TSNSchedule.Pages[TSNSchedule.InactiveItem].style.display = "none";
		}
		TSNSchedule.AllowEvents(); 
	},

	'AutoAdvanceScroller' : function() {
		if (TSNSchedule.ActiveItem > TSNSchedule.LastAutoScrollingItem - 1 + (TSNSchedule.HasProgramNote ? 0 : -1)) { 
			TSNSchedule.Scroll(0); 
		}
		else {
			TSNSchedule.Scroll(TSNSchedule.ActiveItem + 1);
		}
	}
}
TSNSchedule.GetRemoteSchedule();

if (window["OneClipVideoListRenderer"] && document.getElementById("OneClipViewer") && document.getElementById("Playlist")) {
    OneClipVideoListRenderer.LoadOneClipPlayer();
}


AutoTrader = {
	'Tags':[
		[
		["Cars that drive as smooth as skates on ice","Fit your teams hockey bag's in the back of your new SUV"],
		["Fit the starting 5 in your new SUV","Travelling allowed!  Find your new car now"],
		["SUV's that can fit the entire offensive line","Upgrade your tailgate party... with a new tailgate.  Find new trucks here"],
		["0 to 60 quicker than a major league fastball","Hit a grand slam with your new wheels"],
		["Drive like Tiger…in your new car","Cars that are faster and more comfortable than golf carts"],
		["Catch me if you can!  Find your new sports car here","Drive like the pros.  Sports cars and more"],
		["Get your fantasy car to match your fantasy team","Turn Fantasy into reality.  Find your new car."]
		],
		[
		["Hockey bag bigger than your trunk?  Upgrade to a car that can fit your bag, and the goalie's.","New addition to the family?  Then it's time for a new addition to your driveway."],
		["Drive the lane, in your new car","Check out these new crossovers… and other great vehicles"],
		["It's up...and...Its Good!  It's your perfect new car!","Score a touchdown with the perfect new car"],
		["Score a homerun in your new van","Take me out to the ball game.  Show off your new car."],
		["Convertibles with enough space for your clubs","Drive well in any weather condition… hard top convertibles and more"],
		["You won't get stuck at the pit stop.  Upgrade to a new car today","Less road noise than the Indy 500.  Find your new car today."],
		["Top picks for the driver in you","Score big on the road with these top picks"]
		],
		[
		["Time to get a car that you can say is faster than the Zamboni.","New cars that can get the whole family to the rink"],
		["Arrive in style! Roll up to the game in a new vehicle.  Thousands to choose from.","If you can't play like a pro, drive to the game like one.  Thousands of new cars to choose from"],
		["Be on the receiving end of a brand new car","Put your old car on the injured roster and let a new car take the field."],
		["Interiors as spacious as centre field","Find a car that fits your lifestyle like a glove"],
		["Drive great distances.  New cars for any lifestyle","More space than golf carts.  Find your new car today."],
		["Take pole position when you leave your driveway","Helmets not required for your new car."],
		["Make a trade to upgrade your car.","Trade in your old car for a new one"]
		],
	],
	'Place': function() {
		objTarget = document.getElementById('ATPlaceHolder');
		if (objTarget) {
			try {
				intMonth = AutoTrader.GetMonth();
				intSection = AutoTrader.GetSection();
				intRandom = Math.round(Math.random());
				boolShow = true;

				if (boolShow) {
					objContainingDiv = document.createElement("div");
					objHeader = document.createElement('h2');
					objPara = document.createElement("p");
					objAnchor = document.createElement('a');

					objContainingDiv.className = 'feature';
					objAnchor.setAttribute('href','http://tsn.ca/clicks/autotrader.html');
					
					objHeaderText = document.createTextNode('Advertisement');
					objLinkText = document.createTextNode(AutoTrader.Tags[intMonth - 3][intSection][intRandom]);
					
					objTarget.appendChild(objContainingDiv);
					objContainingDiv.appendChild(objHeader)
					objHeader.appendChild(objHeaderText);
					objContainingDiv.appendChild(objPara);
					objPara.appendChild(objAnchor);
					objAnchor.appendChild(objLinkText);
					objTarget.style.display="block";
				}
			}
			catch(e) {
			}
		}
	},
	'GetSection' : function() {
		intSection = 5;
		if (AutoTrader.Find('nhl')) { intSection = 0;}
		if (AutoTrader.Find('nba')) { intSection = 1;}
		if (AutoTrader.Find('cfl') || AutoTrader.Find('nfl')) { intSection = 2; }
		if (AutoTrader.Find('mlb')) { intSection = 3; }
		if (AutoTrader.Find('golf')) { intSection = 4; }
		return intSection;
	},
	'Find' : function (strFind) {
		try {
			strLocation = document.location.toString();
			intLocationMatch = strLocation.indexOf(strFind);
			if (intLocationMatch > 0 && intLocationMatch < 20) {
				return true;
			}
		}
		catch (e) {
			return false;
		}
		return false;
	},
	'GetMonth' : function() {
		try {
			dtNow = new Date();
			intMonth = dtNow.getMonth();
			intMonthNumber = intMonth < 4 ? 4 : (intMonth > 6 ? 6 : intMonth);
		}
		catch (e) {
			intMonthNumber = 0;
		}
		return intMonthNumber;
	}
}
AutoTrader.Place();