var jsTVNZ = window.jsTVNZ || {};
var newsPanel = new Object();
var heroAnimating = false;
var heroClicked = false;
var stopAnimationLoop = false;
var loopCount = 1;
//var dc_tile = 0;
 
var globalObj = new Object();
 
var dartPlayer;

// Video page global variables
var backupAdvertisments;
var lastQualityPlayed;

var rootURL = "/stylesheets/tvnz/news/";

// Makes the init run at page load
$(window).load(function() {
	jsTVNZ.initialize();
});

// the Initialize function, which runs on load, all sub-functions are called in here.
jsTVNZ.initialize = function() {
	// checks to see if the slide Panel(s) Exsists, if it does, initialize them.
	if ($(".slidePanel").is(":visible")) {
		jsTVNZ.Common().initSlidePanel();
	}

	// initializes page controlls:
	jsTVNZ.Common().initPageControls();
	
	// this is a function to stop animation when using a light box, and other pop "overs"
	jsTVNZ.Common().initToggleAnimation();
	
	// this controls the tabs on the latest news module
	jsTVNZ.Common().initLatestNews();
	
	// tab control for On Demand module
	jsTVNZ.Common().initOnDemand();

	// tab control for Watch Episodes module
	jsTVNZ.Common().initWatchEpisodes();

	// tab control for Most Popular module
	jsTVNZ.Common().initMostPopular();
	
	// controls the "share more" rss feeds on the article page
	jsTVNZ.Common().initShareMore();

	// controls the image gallery
	jsTVNZ.Common().initImageGallery();

	// uses the child a url so the entire element is clickable
	jsTVNZ.Common().initSuperClick();

	// initialise the TVSchedule for special events
	jsTVNZ.Common().initTVScheduleSpecialEvent();
	jsTVNZ.Common().initQuickTabModule();
	jsTVNZ.Common().initImageGallerySpecialEvents();
	
	jsTVNZ.Common().checkIfSync();
}

// TVNZ Common functions, that can be re-called at any point.
jsTVNZ.Common = function() {

	var syncToFlash = function() {
		// calls the animation sync from the flash
		jsTVNZ.Common().animateLoop();
	}
	
	var checkIfSync = function() {
		if (!$("#heroPanelFlash").is(":visible")) {
			setInterval(function() {
				jsTVNZ.Common().animateLoop();
			}, 6000);
		}
	}

	// Animation Loop, anything that needs to be animated every 6 seconds needs to go in here
	var animateLoop = function() {
		// there is a function to stop all animation, so if this is true, it wont animate.
		if (!stopAnimationLoop) {
			// Slide Panel Animation
			$(".slidePanel").each(function() {
				// If the mouse it not over the Slide Panel, the next button will be clicked.
				if (!newsPanel[$(this).parent().attr("id")]) {
					$(this).find(".cfbNext, .arrowRight").trigger('animate');
				}
			});
		}
	}
	
	var stopAnimation = function() {
		stopAnimationLoop = true;
	}
	
	var startAnimation = function() {
		stopAnimationLoop = false;
	}
	
	/***************************************************************
	* Live news Database, this is to replace the calltoaction.xml, *
	* to help speed up the process                                 *
	****************************************************************
	* this also allows for one or multipule "noshow" periods, in a *
	* from - to time period (date and time from, date and time too)*
	* date format: dd/mm/yyyy hh:mm:ss AM/PM                       *
	* e.g: 12/19/2008 12:00:00 AM                                  *
	***************************************************************/
	/*
	Breakfast Live stream – 1319543 (Breakfast) http://tvnz.co.nz/breakfast-news/breakfast-live-stream-video-1319543
	Midday News Live stream – 1397073 (national) http://tvnz.co.nz/national-news/one-news-midday-live-stream-video-1397073
	Te Karere Live – 2792573 (Te Karere – programme cos it is under Televsion NOT News) http://tvnz.co.nz/te-karere/live-stream-video-2792573
	4.30pm news live stream – 1397074 (National) http://tvnz.co.nz/national-news/one-news-4-30pm-live-stream-video-1397074
	6pm news live stream – 1319542 (National) http://tvnz.co.nz/national-news/one-news-6pm-live-stream-video-1319542
	Close Up Live stream.- 1319544 (National) http://tvnz.co.nz/close-up/live-stream-video-1319544
	TVNZ 7 News at 8pm Live stream – 1667847 (News on TVNZ 7 - programme cos it is under Televsion NOT News) http://tvnz.co.nz/news-on-tvnz-7/tvnz-news-8-live-stream-video-1667847
	Breakfast Business – 1319541 (Business) http://tvnz.co.nz/business-news/breakfast-business-live-stream-video-1319541
	Q+A – 1667847 (Q and A) http://tvnz.co.nz/news-on-tvnz-7/tvnz-news-8-live-stream-video-1667847
	 */
	var liveNewsDB = {
		weekdays: [
	   		{
	   			// news in a minute
	   			title: "Daily News in a Minute",
	   			url: "http://tvnz.co.nz/national-news/one-news-minute-informed-quickly-video-1664522",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
	   			hours: 0,
	   			minutes: 0
	   		}, {
	   			// NZI business
	   			title: "NZI Business",
	   			url: "http://tvnz.co.nz/business-news/breakfast-business-live-stream-video-1319541",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/nzi_business_live.jpg",
	   			hours: 6,
	   			minutes: 0
	   		}, {
	   			// breakfast
	   			title: "Watch Breakfast",
	   			url: "http://tvnz.co.nz/breakfast-news/breakfast-live-stream-video-1319543",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/breakfast_live.jpg",
	   			hours: 6,
	   			minutes: 30
	   		}, {
				// news in a minute
				title: "Daily News in a Minute",
				url: "http://tvnz.co.nz/national-news/one-news-minute-informed-quickly-video-1664522",
				img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
				hours: 9,
				minutes: 0
	   		}, {
	   			// midday
	   			title: "Watch Midday",
	   			url: "http://tvnz.co.nz/national-news/one-news-midday-live-stream-video-1397073",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_live.jpg",
	   			hours: 12,
	   			minutes: 0
	   		}, {
	   			// news in a minute
	   			title: "Daily News in a Minute",
	   			url: "http://tvnz.co.nz/national-news/one-news-minute-informed-quickly-video-1664522",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
	   			hours: 12,
	   			minutes: 30
	   		}, {
	   			// te karere live
	   			title: "Watch Te Karere",
	   			url: "http://tvnz.co.nz/national-news/te-karere-live-stream-video-2792573",
	   			//url: "http://tvnz.co.nz/te-karere/live-stream-video-2792573",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/te_karere_live_stream.jpg",
	   			hours: 16,
	   			minutes: 0
	   		}, {
	   			// one news live
	   			title: "Watch ONE News",
	   			url: "http://tvnz.co.nz/national-news/one-news-4-30pm-live-stream-video-1397074",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_live.jpg",
	   			hours: 16,
	   			minutes: 30
	   		}, {
	   			// news in a minute
	   			title: "Daily News in a Minute",
	   			url: "http://tvnz.co.nz/national-news/one-news-minute-informed-quickly-video-1664522",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
	   			hours: 17,
	   			minutes: 0
	   		}, {
	   			// one news live
	   			title: "Watch ONE News",
	   			url: "http://tvnz.co.nz/national-news/one-news-6pm-live-stream-video-1319542",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_live.jpg",
	   			hours: 18,
	   			minutes: 0
	   		}, {
	   			// close up
	   			title: "Watch Close Up",
	   			url: "http://tvnz.co.nz/close-up/live-stream-video-1319544",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/closeup_live.jpg",
	   			hours: 19,
	   			minutes: 0
	   		}, {
	   			// news in a minute
	   			title: "Daily News in a Minute",
	   			url: "http://tvnz.co.nz/national-news/one-news-6pm-live-stream-video-1319542",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
	   			hours: 19,
	   			minutes: 30
	   		}, {
	   			// tvnz news
	   			title: "Watch TVNZ News",
	   			url: "http://tvnz.co.nz/national-news/tvnz-news-8-live-stream-video-1667847",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/tvnz7_live.jpg",
	   			hours: 20,
	   			minutes: 0
	   		}, {
	   			// news in a minute
	   			title: "Daily News in a Minute",
	   			url: "http://tvnz.co.nz/national-news/one-news-minute-informed-quickly-video-1664522",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
	   			hours: 21,
	   			minutes: 0
	   		}
	   	],
	   	weekends: [
         	{
         		title: "Daily News in a Minute",
	   			url: "http://tvnz.co.nz/national-news/one-news-minute-informed-quickly-video-1664522",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
         		hours: 0,
         		minutes: 0,
         		day: "both"
         	}, {
				// Q + A
				title: "Q and A",
				url: "http://tvnz.co.nz/q-and-a-news/q-live-stream-video-2566686",
				img: "http://images.tvnz.co.nz/tvnz_site_images/images/q+a_live.jpg",
				hours: 9,
				minutes: 0,
				day: "Sunday"
         	}, {
         		title: "Daily News in a Minute",
	   			url: "http://tvnz.co.nz/national-news/one-news-minute-informed-quickly-video-1664522",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
         		hours: 10,
         		minutes: 0,
         		day: "both"
         	}, {
         		// one news live
         		title: "Watch ONE News",
         		url: "http://tvnz.co.nz/national-news/one-news-6pm-live-stream-video-1319542",
         		img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_live.jpg",
         		hours: 18,
         		minutes: 0,
         		day: "both"
         	}, {
         		title: "Daily News in a Minute",
	   			url: "http://tvnz.co.nz/national-news/one-news-minute-informed-quickly-video-1664522",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
         		hours: 19,
         		minutes: 0,
         		day: "both"
    		}, {
    			// tvnz news
    			title: "Watch TVNZ News",
    			url: "http://tvnz.co.nz/national-news/tvnz-news-8-live-stream-video-1667847",
    			img: "http://images.tvnz.co.nz/tvnz_site_images/images/tvnz7_live.jpg",
    			hours: 20,
    			minutes: 0,
    			day: "both"
    		}, {
    			title: "Daily News in a Minute",
	   			url: "http://tvnz.co.nz/national-news/one-news-minute-informed-quickly-video-1664522",
	   			img: "http://images.tvnz.co.nz/tvnz_site_images/images/onenews_minute.jpg",
    			hours: 21,
    			minutes: 0,
    			day: "both"
    		}
     	]
	}
	
	var initLiveNews = function() {
		www.getServerTime(function(serverTime) {
			var selectedShow;
			var showTheShow = true;
			if (serverTime.dayText == "Saturday" || serverTime.dayText == "Sunday") {
				$(liveNewsDB.weekends).each(function(i) {
					if (this.day == "both" || (serverTime.dayText == "Sunday" && this.day == "Sunday") || (serverTime.dayText == "Saturday" && this.day == "Saturday") ) {
						if ((this.hours < serverTime.hours) || ((this.hours == serverTime.hours) && (this.minutes <= serverTime.minutes))) {
							selectedShow = this;
						}
					}
				});
			} else {
				$(liveNewsDB.weekdays).each(function(i) {
					if ((this.hours < serverTime.hours) || ((this.hours == serverTime.hours) && (this.minutes <= serverTime.minutes))) {
						selectedShow = this;
					}
				});
			}
			
			if (selectedShow.noshow != undefined) {
				if ((typeof(selectedShow.noshow) == "boolean" && selectedShow.noshow == true)) {
					showTheShow = false;
					$("#oneNews .videoLightbox").attr("title", selectedShow.title);
					$("#oneNews .videoLightbox").css({display: "block", alt: selectedShow.title});
					$("#oneNews .videoLightbox img").attr("src", selectedShow.img);
					$("#oneNews .videoLightbox").unbind('click').removeAttr("href").removeAttr("class");
				} else {
					$(selectedShow.noshow).each(function(i) {
						if (www.dateWithin(this.from, this.to, serverTime.date) == true) {
							showTheShow = false;
						}
					});
				}
				if (showTheShow) {
					$("#oneNews .videoLightbox").attr({title: selectedShow.title, href: selectedShow.url});
					$("#oneNews .videoLightbox").css({display: "block", alt: selectedShow.title});
					$("#oneNews .videoLightbox img").attr("src", selectedShow.img);
				} 
			} else {
				$("#oneNews .videoLightbox").attr({title: selectedShow.title, href: selectedShow.url});
				$("#oneNews .videoLightbox").css({display: "block", alt: selectedShow.title});
				$("#oneNews .videoLightbox img").attr("src", selectedShow.img);
			}
		});
	}
	
	// Initilize Ad push down
	var initPushDown = function() {
		var openBanner = true;
		$("#pushDownAd img").each(function() {
			if ($(this).attr("src").match(/817-grey.gif$/) != null) {
				openBanner = false;
			}
		});
		if (openBanner) {
			jsTVNZ.Common().openPushDown();
		}
	}


	var openPushDown = function(delay) {
		$("#pushDownAd").fadeIn(1500, function() {
			if (delay != undefined) {
				setTimeout(function() {
					jsTVNZ.Common().closePushDown();
				}, (delay * 1000));
			}
		});
	}

	
	var closePushDown = function() {
		if ($.browser.mozilla) {
			var version = parseInt($.browser.version.split(".")[0]) + (parseInt($.browser.version.split(".")[1]) / 10);
			if (version < 2) {
				setTimeout(jsTVNZ.Common().fireFoxRemovePushDownSWF, 250);
			} else {
				$("#pushDownAd").fadeOut();//animate({height: 'hide'}, 1500, "easeout");
			}
		} else {
			$("#pushDownAd").fadeOut();//animate({height: 'hide'}, 1500, "easeout");
		}
	}

	var fireFoxRemovePushDownSWF = function() {
		$("#pushDownAd").html("<!-- -->");
		$("#pushDownAd").css({display: "none"});
	}

	
	// Initilize Slide Panels
	var initSlidePanel = function() {
		// Below loops through all the newsPanels on this page, and add's the click functions.
		$("div.slidePanel").each(function() {
			var thisPanelsID = $(this).parent().attr("id");
			// Below gets the count of the number of articals(Groups) in each newsPanel
			$(this).find(".cfbMax").html($(this).find(".group").length);
			$(this).find(".cfbCurrent").html("1");
			// below loops through and hides all but the current artical(Group)
			for (var i = 1; i <= $(this).find(".cfbMax").html(); i++) {
				if (i != $(this).find(".cfbCurrent").html()) {
					$("#" + thisPanelsID + i).hide();
				}
			}
			if ($(this).find(".group").length == 1) { 
				// if there's only one, dont animate this panel	
				newsPanel[thisPanelsID] = true;
			} else {
				// Below toggles the global news panel hoverstate
				$(this).find(".cfbNav").css({display: 'block'});
				$(this).hover(function() {
					newsPanel[thisPanelsID] = true;
				}, function() {
					newsPanel[thisPanelsID] = false;
				});
			}
			// Below adds the click function to the next and previous buttons, spacific to the newsPanel it belongs too.
			if ($(this).find(".cfbNav, .nav").length>0){
				$(this).find(".cfbPrevious").click(function(e) {
					if ($(this).parent().find(".cfbCurrent").html() == 1) {
						$("#" + thisPanelsID + $(this).parent().find(".cfbCurrent").html()).fadeOut();//animate({opacity:'hide'}, 1500, "easeout");
						$(this).parent().find(".cfbCurrent").html($(this).parent().find(".cfbMax").html());
						$("#" + thisPanelsID + $(this).parent().find(".cfbCurrent").html()).fadeIn();//animate({opacity:'show'}, 1500, "easeout");
					} else {
						$("#" + thisPanelsID + $(this).parent().find(".cfbCurrent").html()).fadeOut();//animate({opacity:'hide'}, 1500, "easeout");
						$(this).parent().find(".cfbCurrent").html(parseInt($(this).parent().find(".cfbCurrent").html()) - 1);
						$("#" + thisPanelsID + $(this).parent().find(".cfbCurrent").html()).fadeIn();//animate({opacity:'show'}, 1500, "easeout");
					}
					e.stopPropagation(); // required to prevent propagation causing omniture roundtrips in animation loop 
					e.preventDefault();
					return false;
				});
				
				var clickFunc = function(e) {
					if ($(this).parent().find(".cfbCurrent").html() == $(this).parent().find(".cfbMax").html()) {
						$("#" + thisPanelsID + $(this).parent().find(".cfbCurrent").html()).fadeOut();//animate({opacity:'hide'}, 1500, "easeout");
						$(this).parent().find(".cfbCurrent").html("1");
						$("#" + thisPanelsID + $(this).parent().find(".cfbCurrent").html()).fadeIn();//animate({opacity:'show'}, 1500, "easeout");
					} else {
						$("#" + thisPanelsID + $(this).parent().find(".cfbCurrent").html()).fadeOut();//animate({opacity:'hide'}, 1500, "easeout");
						$(this).parent().find(".cfbCurrent").html(parseInt($(this).parent().find(".cfbCurrent").html()) + 1);
						$("#" + thisPanelsID + $(this).parent().find(".cfbCurrent").html()).fadeIn();//animate({opacity:'show'}, 1500, "easeout");
					}
					e.stopPropagation(); // required to prevent propagation causing omniture roundtrips in animation loop 
					e.preventDefault();
					return false;
				};
				$(this).find(".cfbNext").click(clickFunc);
				$(this).find(".cfbNext").bind('animate',clickFunc); // do this as my animate action too 
			}

			// added later for tv highlights
			if ($(this).find(".mainNav").length>0){
				$(this).find(".arrowLeft").click(function() {
					if ($(this).parent().parent().parent().find(".cfbCurrent").html() == 1) {
						$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeOut();//animate({opacity:'hide'}, 1500, "easeout");
						$(this).parent().parent().parent().find(".cfbCurrent").html($(this).parent().parent().parent().find(".cfbMax").html());
						$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeIn();//animate({opacity:'show'}, 1500, "easeout");
					} else {
						$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeOut();//animate({opacity:'hide'}, 1500, "easeout");
						$(this).parent().parent().parent().find(".cfbCurrent").html(parseInt($(this).parent().parent().parent().find(".cfbCurrent").html()) - 1);
						$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeIn();//animate({opacity:'show'}, 1500, "easeout");
					}
					$(".mainNav .navButton.selected").removeClass("selected");
					$(".mainNav .navButton").each(function(i) {
						if (i == ($(this).parent().parent().parent().find(".cfbCurrent").html() - 1)) {
							$(this).addClass("selected");
						}
					});
					return false;
				});
				var clickFunc = function() {
					if ($(this).parent().parent().parent().find(".cfbCurrent").html() == $(this).parent().parent().parent().find(".cfbMax").html()) {
						$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeOut();//animate({opacity:'hide'}, 1500, "easeout");
						$(this).parent().parent().parent().find(".cfbCurrent").html("1");
						$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeIn();//animate({opacity:'show'}, 1500, "easeout");
					} else {
						$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeOut();//animate({opacity:'hide'}, 1500, "easeout");
						$(this).parent().parent().parent().find(".cfbCurrent").html(parseInt($(this).parent().parent().parent().find(".cfbCurrent").html()) + 1);
						$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeIn();//animate({opacity:'show'}, 1500, "easeout");
					}
					$(".mainNav .navButton.selected").removeClass("selected");
					$(".mainNav .navButton").each(function(i) {
						if (i == ($(this).parent().parent().parent().find(".cfbCurrent").html() - 1)) {
							$(this).addClass("selected");
						}
					});
					return false;
				}; 
				$(this).find(".arrowRight").click(clickFunc);
				$(this).find(".arrowRight").bind('animate',clickFunc);
				$(".mainNav .navButton:first").addClass("selected");
				$(".mainNav .navButton").each(function(i) {
					$(this).click(function() {
						if (i != $(".mainNav .navButton").index($(".mainNav .navButton.selected"))) {
							$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeOut();//animate({opacity:'hide'}, 1500, "easeout");
							
							$(this).parent().parent().parent().find(".cfbCurrent").html((i+1));
							$("#" + thisPanelsID + $(this).parent().parent().parent().find(".cfbCurrent").html()).fadeIn();//animate({opacity:'show'}, 1500, "easeout");
							$(".mainNav .navButton.selected").removeClass("selected");
							$(this).addClass("selected");
						}
						return false;
					});
				});
			}

		});
	}
	
	var initLatestNews = function() {
		// Latest news tabs
		$(".quickTabModule .mainNav a").each(function() {
			$(this).click(function(){
				var $this = $(this);
				if (!$(this).hasClass("selected")) {
					$(this).parent().parent().find(".selected").removeClass("selected");
					$(this).addClass("selected");
					$(this).parent().parent().parent().parent().find(".articles .selected").removeClass("selected");
					$(this).parent().parent().parent().parent().find(".articles ." + $this.children("span").children("span").attr("class")).addClass("selected");
					$(this).removeAttr("style");
					$(this).find("span").removeAttr("style");
					$(this).find("span").find("span").removeAttr("style");
				}
				return false;
			}).css({cursor: "pointer"});
		});
		// checks the height of the items in the read tab, and will remove any overlapping new items
		var x = 0;
		$("#latestNews .read li").each(function() {
			x += $(this).height() + parseInt($(this).css("padding-top")) + parseInt($(this).css("padding-bottom")) + parseInt($(this).css("margin-top")) + parseInt($(this).css("margin-bottom"));
			if ((($("#latestNews .articles").height() - parseInt($("#latestNews .articles").css("padding-top")) - parseInt($("#latestNews .articles").css("padding-bottom"))) - x) > 0) {
				$(this).removeAttr("style").addClass("last");
				$(this).prev("li").removeClass("last");
			} else {
				$(this).css({display: "none"});
			}
		});
	}
	
	var initTabs = function() {		
		// Tabs - used on Search and Article detail page 
		$(".tabs a").each(function() {
			$(this).click(function(){
				var $this = $(this);
				// Checks to see if the one clicked is already selected, if so, do nothing.
				if (!$(this).hasClass("selected")) {
					$(".tabs a.selected").removeClass("selected");
					$(".article .viewSwitch").removeClass("viewSwitch");
					$(".article ." + $this.attr("class")).addClass("viewSwitch");
					$(this).addClass("selected");
					if ($("#tertiaryNav").is(":visible")) {
						$("#tertiaryNav").removeAttr("style");
						$("#tertiaryNav").height($("#tertiaryNav").parent().height());
					}
				}
				// Below is for the "tool bar", if we are not ont he read tab, disable it, else if we are on the read tab, make sure its not disabled.
				if (!$(this).hasClass("readSwitch")) {
					$(".tools p").each(function() {
						$(this).filter(":first-child").addClass("disabled");
					});
				} else {
					$(".tools p").each(function() {
						$(this).filter(":first-child").removeClass("disabled");
					});
				}
				// Below checks to see if the "share move" dialog box is on the screen, if so, hide it.
				if ($("#shareMore").is(":visible")) {
					$("#shareMore").css({display: 'none'});
				}
				return false;
			}).css({cursor: "pointer"});
		});
		
		// Below if for controlls inside a tab that will also toggle the tab itself.
		$(".tabControl").each(function() {
			$(this).click(function() {
				if ($(this).hasClass("watch")) {
					$(".tabs a.watchSwitch").click();
				} else if ($(this).hasClass("see")) {
					$(".tabs a.seeSwitch").click();
				}
				return false;
			}).css({cursor: "pointer"});
		});
		
		// Tertiary Nav Height
		if ($("#tertiaryNav").is(":visible")) {
			$("#tertiaryNav").height($("#tertiaryNav").parent().height());
		}
	}
	
	var initTVSchedule = function() {
		$.each( $("#tv_shed #tv_navigation .nav li a"), function(i, l){
			//Set the 1st element to be selected
			if(i == 0){
				$(this).addClass('selected');
			}
			$(this).click(function() {
				var slectedItem = $("#tv_shed #tv_navigation .nav li").find('.selected');
				$(slectedItem).removeClass("selected");
				$(this).addClass('selected');
				$('.show_container').animate({"left": (i * 237 * -1)+"px"}, { "duration": "slow"});
				return false;
			});
			
		});
		
		$.each( $("#tv_shed .show_container .show_now"), function(i, l){

			var showTitle = $(this).find('.show_title a');
			
			if($(showTitle).attr("href") != undefined){
				$(this).css("cursor","pointer");
				
				$(this).mouseover(function(){
					$(this).css("background-image","url(http://images.tvnz.co.nz/tvnz_site_images/home_tv_shedule_content_hover_repeat.jpg)");
				});
				
				$(this).mouseout(function(){
					$(this).css("background-image","none");
				});
				
				$(this).click(function(){
					window.location.replace($(showTitle).attr("href"));
				});
			}

		});
		
		$.each( $("#tv_shed .show_container .show_next"), function(j, k){
			var showTitle = $(this).find('.show_title a');
			if($(showTitle).attr("href") != undefined){
				$(this).css("cursor","pointer");
				$(this).mouseover(function(){
					$(this).css("background-color","#fff");
				});
				$(this).mouseout(function(){
					$(this).css("background-color","transparent");
				});
			}

		});
	}
	
	var initOnDemand = function() {
		//onDemand
		$("#onDemand .mainNav a").each(function() {
			$(this).click(function() {
				if (!$(this).parent().hasClass("selected")) {
					$("#onDemand .mainNav .selected").removeClass("selected");
					$("#onDemand .main .selected").removeClass("selected");
					$(this).parent().addClass("selected");
					$("#onDemand .main ." + $(this).attr("class")).addClass("selected");
					$(this).removeAttr("style");
					$(this).find("span").removeAttr("style");
				}
				return false;
			}).css({cursor: "pointer"});
		});
	}

	var initWatchEpisodes = function() {
		//Watch episodes tabbed panel
		$("#watchEpisodes .tabs a").each(function() {
			$(this).click(function() {
				if (!$(this).hasClass("selected")) {
					$("#watchEpisodes .tabs .selected").removeClass("selected");
					$("#watchEpisodes .main .selected").removeClass("selected");
					$(this).addClass("selected");
					$("#watchEpisodes .main ." + $(this).parent().attr("class")).addClass("selected");
					//$(this).removeAttr("style");
				}
				return false;
			}).css({cursor: "pointer"});
		});
	}

	var initMostPopular = function() {
		//Most Popular tabbed panel
		$("#most_popular #mp_tabs a").each(function() {
			$(this).click(function() {
				if (!$(this).hasClass("selected")) {
					$("#most_popular #mp_tabs .selected").removeClass("selected");
					$("#most_popular .main .selected").removeClass("selected");
					$(this).addClass("selected");
					$("#most_popular .main ." + $(this).parent().attr("class")).addClass("selected");
					//$(this).removeAttr("style");
				}
				return false;
			}).css({cursor: "pointer"});
		});
	}
	
	// superClick makes the entire div clickable
	var initSuperClick = function() {
		$(".superClick").click(function() {
			if ($(this).find("a:first").length>0) {
				document.location = $(this).find("a:first").attr("href");
			}
		});
	}
	
	var initShareMore = function() {
		// Share Box
		$(".shareMore").each(function() {
			var $this = $(this);
			$(this).click(function() {
				if (($("#shareMore").is(":hidden") == false) && ($("#shareMore").is(":visible") == false)) {
					// calls the HTML from jsHTML
					jsHTML.shareMore(this, urlEncodedArticleTitle, productionUrl);
					$("#shareMore .close").click(function() {
						$("#shareMore").animate({height: "hide"}, 250);
						return false;
					}).css({cursor: "pointer"});
					$("#shareMore").animate({height: "show"}, 250);
				} else if ($("#shareMore").is(":visible")) {
					$("#shareMore").animate({height: "hide"}, 125, function() {
						$(this).css({left: ($this.offset().left - 380) + 'px', top: ($this.offset().top + 15) + 'px'}).animate({height: "show"}, 125);
					});
				} else {
					$("#shareMore").css({left: ($(this).offset().left - 380) + 'px', top: ($(this).offset().top + 15) + 'px'});
					$("#shareMore").animate({height: "show"}, 250);
				}
				return false;
			}).css({cursor: "pointer"});
		});
	}

	var setGlobal = function(_variable, _value) {
		globalObj[_variable] = _value;
	}

	var getGlobal = function(_variable) {
		return globalObj[_variable];
	}
	
	var resizeFrame = function(f) {
		f.style.height = f.contentWindow.document.body.scrollHeight + "px";
	}
	
	var updateScoreboardHeight = function(num) {
		switch(num) {
			case 1:
				$("#").css({height: "63px"});
			break;
			case 2:
				$("#").css({height: "136px"});
			break;
		}
	}
	
	var initPoll = function() {
		$("#poll .pollContainer a").each(function() {
			$(this).click(function() {
				$(this).addClass("selected");
				$.get($(this).attr("href"), function(data) {
					$("#poll .pollContainer").html(data);
				});
				$("#poll .pollContainer a").each(function() {
					$(this).removeAttr("href");
					$(this).unbind("click");
				});
				return false;
			});
		});
	}
	
	var initPageControls = function() {
		// Increase Font Size
		$(".increaseFont").each(function() {
			$(this).click(function(){
				if (!$(this).parent().hasClass("disabled")) {
					var currentFontSize = $('#article-body').css('font-size');
					var newFontSize = parseInt(currentFontSize.substring(0,2))+2;
					if (newFontSize < 19) {
						$('#article-body').css('font-size', newFontSize + "px");
						jsTVNZ.Common().createCookie("TVNZ-Fontsize", newFontSize, 365);
					}
				}
				return false;
			});
		});
		 
		// Decrease Font Size
		$(".decreaseFont").each(function() {
			$(this).click(function(){
				if (!$(this).parent().hasClass("disabled")) {
					var currentFontSize = $('#article-body').css('font-size');
					var newFontSize = parseInt(currentFontSize.substring(0,2))-2;
					if (newFontSize > 9) {
						$('#article-body').css('font-size', newFontSize + "px");
						jsTVNZ.Common().createCookie("TVNZ-Fontsize", newFontSize, 365);
					}
				}
				return false;
			});
		});
		
		// Print function
		$(".tools .print").each(function() {
			$(this).click(function() {
				if (!$(this).parent().hasClass("disabled")) {
					window.print();
				}
				return false;
			});
		});

		// read the font-size cookie, and if its not null, set the font-size
		var tvnzFontSize = jsTVNZ.Common().readCookie("TVNZ-Fontsize");
		if (tvnzFontSize != null && $('#article-body').is(":visible")) {
			$('#article-body').css('font-size', tvnzFontSize + "px");
		}
	}

	var initImageGallery = function() {
		$("#imageGalleries .seeCam .imgHover").hover(function() {
			$(this).css({zIndex: "100"});
			if ($(this).hasClass("imgRight")) {
				$(this).find("div").css({display: "block"}).animate({left: "-146px"}, 250);
			} else {
				$(this).find("div").css({display: "block"}).animate({left: "140px"}, 250);
			}
		}, function() {
			if ($(this).hasClass("imgRight")) {
				$(this).find("div").animate({left: "-6px"}, 250, function() {
					$(this).parent().css({zIndex: "90"});
					$(this).css({display: "none"});
				});
			} else {
				$(this).find("div").animate({left: "0px"}, 250, function() {
					$(this).parent().css({zIndex: "90"});
					$(this).css({display: "none"});
				});
			}
		});
	}
	
	var initImageGallerySpecialEvents = function() {
		$(".quickTabModule .seeCam .imgHover").hover(function() {
			$(this).css({zIndex: "100"});
			if ($(this).hasClass("imgRight")) {
				$(this).find("div").css({display: "block"}).animate({left: "-146px"}, 250);
			} else {
				$(this).find("div").css({display: "block"}).animate({left: "140px"}, 250);
			}
		}, function() {
			if ($(this).hasClass("imgRight")) {
				$(this).find("div").animate({left: "-6px"}, 250, function() {
					$(this).parent().css({zIndex: "90"});
					$(this).css({display: "none"});
				});
			} else {
				$(this).find("div").animate({left: "0px"}, 250, function() {
					$(this).parent().css({zIndex: "90"});
					$(this).css({display: "none"});
				});
			}
		});
	}
	
	var initQuickTabModule = function() {
		// Latest news tabs
		$(".quickTabModule .mainNav a").each(function() {
			$(this).click(function(){
				var $this = $(this);
				if (!$(this).hasClass("selected")) {
					$(this).parent().parent().find(".selected").removeClass("selected");
					$(this).addClass("selected");
					$(this).parent().parent().parent().parent().find(".articles .selected").removeClass("selected");
					$(this).parent().parent().parent().parent().find(".articles ." + $this.children("span").children("span").attr("class")).addClass("selected");
					$(this).removeAttr("style");
					$(this).find("span").removeAttr("style");
					$(this).find("span").find("span").removeAttr("style");
				}
				return false;
			}).css({cursor: "pointer"});
		});
		// checks the height of the items in the read tab, and will remove any overlapping new items
		var x = 0;
		$("#latestNews .read li").each(function() {
			x += $(this).height() + parseInt(String($(this).css("padding-top")).substring(0, String($(this).css("padding-top")).length - 2)) + parseInt(String($(this).css("padding-bottom")).substring(0, String($(this).css("padding-bottom")).length - 2)) + parseInt(String($(this).css("margin-top")).substring(0, String($(this).css("margin-top")).length - 2)) + parseInt(String($(this).css("margin-bottom")).substring(0, String($(this).css("margin-bottom")).length - 2));
			if (($("#latestNews .articles").height() - x) < 0) {
				$(this).css({display: "none"});
			}
		});
	}
	
	var initTVScheduleSpecialEvent = function() {
		// TV Schedule
		if ( $("#specialEventSchedule").length > 0 ){
			$("#specialEventSchedule .dayNav a").each(function() {
				$(this).click(function() {
					if ($("#specialEventSchedule .dayNav a.selected").parent().attr("class") != $(this).parent().attr("class")) {
						var oldSelected = $("#specialEventSchedule .dayNav a.selected").parent().attr("class");
						$("#specialEventSchedule .dayNav a.selected").removeClass("selected");
						$(this).addClass("selected");
						$("#specialEventSchedule .dayScroller ." + oldSelected).animate({left: "-282px"}, 250, function() {
							$(this).css({left: "282px"}).removeClass("selected");
						});
						$("#specialEventSchedule .dayScroller ." + $(this).parent().attr("class")).css({left: "282px"}).animate({left: "0px"}, 250, function() {
							$(this).addClass("selected");
							// add's the JS Scroll Bar to the TV Schedule
							$('.dayScroller').jScrollPane({
								scrollbarWidth:17,
								scrollbarMargin:4,
								showArrows:true,
								dragMinHeight: 36,
								dragMaxHeight: 36
							});
						});
					}
					return false;
				}).css({cursor: "pointer"});
			});
		}
		
		// add's the JS Scroll Bar to the TV Schedule
		$('.dayScroller').jScrollPane({
			scrollbarWidth:17,
			scrollbarMargin:4,
			showArrows:true,
			dragMinHeight: 36,
			dragMaxHeight: 36
		});
	}
	
	var initToggleAnimation = function() {
		$(".thickbox").each(function() {
			$(this).click(function() {
				jsTVNZ.Common().stopAnimation();
			});
		});
	}

	var setCurrentDate = function() {
		$("#hpDate").html(www.serverTime.dayText + " - " + www.serverTime.monthText + " " + www.serverTime.day + ", " + www.serverTime.year).css({visibility: "visible"});
		$("#tv_shed #tv_shed_title span.date").html(www.serverTime.dayText + " " + www.serverTime.day + " " + www.serverTime.monthText).css({visibility: "visible"});
	}
	
	var disableTools = function() {
		$(".print").css("display","none");
	}


	var createCookie = function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; domain=tvnz.co.nz; path=/";
	}

	var readCookie = function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0) == ' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	var eraseCookie = function(name) {
		jsTVNZ.Common().createCookie(name,"",-1);
	}
	
	return {
		animateLoop : animateLoop,
		syncToFlash : syncToFlash,
		checkIfSync : checkIfSync,
		initLiveNews : initLiveNews,
		stopAnimation : stopAnimation,
		startAnimation : startAnimation,

		setGlobal : setGlobal,
		getGlobal : getGlobal,
		
		initPushDown : initPushDown,
		openPushDown : openPushDown,
		fireFoxRemovePushDownSWF : fireFoxRemovePushDownSWF,
		closePushDown : closePushDown,	
		initSlidePanel : initSlidePanel,
		initLatestNews : initLatestNews,
		initTabs : initTabs,
		initTVSchedule : initTVSchedule,
		initOnDemand : initOnDemand,
		initWatchEpisodes : initWatchEpisodes,
		initMostPopular : initMostPopular,
		initShareMore : initShareMore,
		initPoll : initPoll,
		initPageControls : initPageControls,
		initImageGallery : initImageGallery,
		initToggleAnimation : initToggleAnimation,
		initSuperClick : initSuperClick,

		setCurrentDate : setCurrentDate,
		disableTools : disableTools,
		resizeFrame : resizeFrame,
		createCookie : createCookie,
		readCookie : readCookie,
		eraseCookie : eraseCookie,

		initTVScheduleSpecialEvent : initTVScheduleSpecialEvent,
		initQuickTabModule : initQuickTabModule,
		initImageGallerySpecialEvents : initImageGallerySpecialEvents
		
	}
}


function displayLayer(id, value ) {
    if ( document.getElementById ) {
        document.getElementById( id ).style.display = value;
    } else if ( document.all ) {
        document.all[ id ].style.display = value;
    }
}

function hide( id ) {
    displayLayer( id, 'none' );
}

function show( id ) {
    displayLayer( id, 'block' );
}

// checks the max length of the textarea
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

// function for Close Up form to show and hide forms fields depending on user input
function onChangeSectionCloseUp() {
	var Current =
   	document.close_up_contact.subject.selectedIndex;
	if (document.close_up_contact.subject.options[Current].text == "Send Feedback about Close Up") {
		show( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
	else if (document.close_up_contact.subject.options[Current].text == "Suggest a story idea for Close Up") {
		hide( 'feedback' );
		show( 'suggest' );
		hide( 'share' );
	}
	else if (document.close_up_contact.subject.options[Current].text == "Share my own story with Close Up") {
		hide( 'feedback' );
		hide( 'suggest' );
		show( 'share' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
}
// function for Fair Go form to show and hide forms fields depending on user input
function onChangeSectionFairGo() {
	var Current =
   	document.tv_one_fair_go_feedback.subject.selectedIndex;
	if (document.tv_one_fair_go_feedback.subject.options[Current].text == "Send Feedback about Fair Go") {
		show( 'feedback' );
		hide( 'suggest' );
	}
	else if (document.tv_one_fair_go_feedback.subject.options[Current].text == "Suggest or Share a Story Idea for Fair Go") {
		hide( 'feedback' );
		show( 'suggest' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
	}
}
// function for 20 20 form to show and hide forms fields depending on user input
function onChangeSectionTwenty() {
	var Current =
   	document.twenty_contact.subject.selectedIndex;
	if (document.twenty_contact.subject.options[Current].text == "Send Feedback about 20/20") {
		show( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
	else if (document.twenty_contact.subject.options[Current].text == "Suggest a story idea for 20/20") {
		hide( 'feedback' );
		show( 'suggest' );
		hide( 'share' );
	}
	else if (document.twenty_contact.subject.options[Current].text == "Share my own story with 20/20") {
		hide( 'feedback' );
		hide( 'suggest' );
		show( 'share' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
}
// function for Sunday form to show and hide forms fields depending on user input
function onChangeSectionSunday() {
	var Current =
   	document.sunday_contact.subject.selectedIndex;
	if (document.sunday_contact.subject.options[Current].text == "Send Feedback about Sunday") {
		show( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
	else if (document.sunday_contact.subject.options[Current].text == "Suggest a story idea for Sunday") {
		hide( 'feedback' );
		show( 'suggest' );
		hide( 'share' );
	}
	else if (document.sunday_contact.subject.options[Current].text == "Share my own story with Sunday") {
		hide( 'feedback' );
		hide( 'suggest' );
		show( 'share' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
}
//function for Sunday form to show and hide forms fields depending on user input
function onChangeSectionGoodSorts() {
	var Current =
   	document.good_sorts_contact.subject.selectedIndex;
	if (document.good_sorts_contact.subject.options[Current].text == "Send feedback about a Good Sorts story") {
		show( 'feedback' );
		hide( 'nominate' );
	}
	else if (document.good_sorts_contact.subject.options[Current].text == "Nominate someone for the Good Sorts series") {
		hide( 'feedback' );
		show( 'nominate' );
	}
	else {
		hide( 'feedback' );
		hide( 'nominate' );
	}
}
//function for Q+A form to show and hide forms fields depending on user input
function onChangeSectionQandA() {
	var Current =
   	document.q_a_contact.subject.selectedIndex;
	if (document.q_a_contact.subject.options[Current].text == "Send Feedback about Q+A") {
		show( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
	else if (document.q_a_contact.subject.options[Current].text == "Suggest a story idea for Q+A") {
		hide( 'feedback' );
		show( 'suggest' );
		hide( 'share' );
	}
	else if (document.q_a_contact.subject.options[Current].text == "Share my own story with Q+A") {
		hide( 'feedback' );
		hide( 'suggest' );
		show( 'share' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
}
// function for TVNZ Contact form to show and hide forms fields depending on user input
function onChangeSection() {
 		var Current =
   	document.tvnz_contact.submit_to.selectedIndex;
 		document.tvnz_contact.subject.value = document.tvnz_contact.submit_to.options[Current].text;
	if (document.tvnz_contact.submit_to.options[Current].text == "A Programme") {
		show( 'programme_row' );
		hide( 'transmission_feedback' );
	}
	else if (document.tvnz_contact.submit_to.options[Current].text == "TV reception (transmission)") {
		show( 'transmission_feedback' );
		hide( 'programme_row' );
	}
	else {
		hide( 'programme_row' );
		hide( 'transmission_feedback' );
	}
}
// function for NZI Business form to show and hide forms fields depending on user input
function onChangeSectionNZIBusiness() {
	var Current =
   	document.nzi_business_contact.subject.selectedIndex;
	if (document.nzi_business_contact.subject.options[Current].text == "Send Feedback about NZI Business") {
		show( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
	else if (document.nzi_business_contact.subject.options[Current].text == "Suggest a story idea for NZI Business") {
		hide( 'feedback' );
		show( 'suggest' );
		hide( 'share' );
	}
	else if (document.nzi_business_contact.subject.options[Current].text == "Share my own story with NZI Business") {
		hide( 'feedback' );
		hide( 'suggest' );
		show( 'share' );
	}
	else {
		hide( 'feedback' );
		hide( 'suggest' );
		hide( 'share' );
	}
}
// Sel's iframe function
function insertIframe(src, width, height) {
	document.write('<iframe src="' + src + '" width="' + width + '" height="' + height + '" frameBorder="0" ></iframe>');
}

/*
 * This function is used update the hero panel. 
 */
function heroPanel(){
	var maxItems = 3;
	var rotationTime = 6; // time in seconds
	var maxChars = 100; //max number of words appear in the summary
	var currentHeroIndex = 0;
	var heroElements = $('#heroPanel .heroPanelNav .hero');;
	var heroMiniElements = $('#heroPanel .heroPanelNav .heroMini');
	var heroImages = $('#heroPanel .heroPanelContent a');
	var heroLinks = $('#heroPanel .heroPanelContent .heroLink');
	var arrow = $('.selectedArrow');
	var arrowYPos = 0;
	var heroHeight = $('.hero').height();
	var heroMiniHeight = $('.heroMini').height();
	var timer;
	var pre;
	
	heroPanelInit();
	performRotation();
	setTimer();
	
	$('.hero, .heroPanelContent').mouseover(function() {
		window.clearInterval(timer);
	});
	
	$('.hero, .heroPanelContent').mouseout(function() {
		setTimer();
	});
	
	$('.heroMini').click(function(){
		
		var clickedId = $(this);
		$.each( heroMiniElements, function(i, l){
			if($(this).attr("id") == $(clickedId).attr("id")){
				currentHeroIndex = i;
				performRotation();		
			}
		});
		
		return false;
	});
	
	
	function heroPanelInit(){
		$(heroMiniElements[0]).css("display","block");
		$(heroMiniElements[0]).hide();
		
		//bind the links to the arrow
		$.each( arrow, function(i, l){
			$(this).click(function(){
				var link = $(heroImages[i]).attr("href");
				window.location.replace(link);
			});
		});
		
		

	}
	
	//update the hero panel after a set interval
	function performRotation(){

		$.each( heroElements, function(i, l){
			if(currentHeroIndex == i){
				
				arrowYPos = (currentHeroIndex * heroMiniHeight) + heroHeight/2 - $(arrow).height()/2;
				$(".heroarrow"+(i+1)).css("display","block");
				$(".heroarrow"+(i+1)).animate({"left": -20}, "fast");
				$(heroElements[i]).slideDown("fast");
				$(heroMiniElements[i]).slideUp("fast");	
				
			}else{
				$(".heroarrow"+(i+1)).animate({"left": 0}, "fast");
				$(".heroarrow"+(i+1)).css("display","none");
				$(heroElements[i]).slideUp("fast");
				$(heroMiniElements[i]).slideDown("fast");
			}
			
		});
		
		if(pre == null){
			pre = heroImages[0];
			$(pre).fadeIn();
		}else{
			$(pre).hide();
			var getimg = "url("+$(pre).find('img').attr('src')+")";
			$('.heroPanelContent').css("background",getimg);
			$(heroImages[currentHeroIndex]).fadeIn(800);
			pre = heroImages[currentHeroIndex];
		}
		currentHeroIndex++;
		if(currentHeroIndex == maxItems){ currentHeroIndex = 0; }
	}
	
	function setTimer(){
		timer = window.setInterval(function() {
			performRotation();
		}, rotationTime * 1000);
	}
}
