var firstPageLoad = true;
function pageInit() {
	//RESET VARIABLES FOR AJAX CALLS
	currentTab=1;		//Keeps track of the current tab for rotating.
	firstLoad = true;	//Modifies the Toggle function on the first page load.
	dlFade = false;		//Keeps track of fading well it is occuring.
	if(dlRunning) {
		clearInterval(dlRotate);
		dlRunning = false;
	}
	
	//Takes care of the dynamic leads if they exist.
	if($(".rotateBox").size() != 0) {
		if($(".rotateBox.rotateFade").size() != 0) dlIsFade = true; //Checks if the tabs should fade

		dlNumTabs = $(".rotateItem").size(); //Checks how many tabs there are
		dlToggle();
		if($(".rotateBox .tabs").size != 0) { //Checks if there are tabs
			dlIsTabs = true;
			$(".rotateBox .tabs a").bind("click", function(){ //binds function to dl tabs
				if(dlRunning) dlToggle();
				dlSwitch($(this).attr("href").substring(4));
				return false;
			});
		}

		$(".rotateNav a").bind("click", function(){ //binds functions to dl nav
			if($(this).attr("href")=="#toggle"){
				dlToggle();
			} else {
				if(dlRunning) dlToggle();
				dlCycle($(this).attr("href").substring(1));
			}
			return false;
		});

		if($(".rotateCount").size() != 0) { //Checks if there is a counter that needs to be updated
			dlIsCount = true;
			$(".rotateCount").html("<span>1</span> of "+dlNumTabs)	
		}

		document.onkeydown = arrowSwitch;
		document.onkeyup = arrowCancel;
	}

	dlSlideCookie(); //Changes the default slider value for the DLs if a cookie is set
	bindSlider(); //adds the slider functionality


	if(firstPageLoad) {
	
		$('a[rel$="blank"]').click(function(){ // Sets links with the rel of "blank" to open in a new window
			this.target = "_blank";
		});
		
		$(".tabs a").bind("click", function(){ //latest/popular story tabs
			tabSwitch($(this));
			return false;
		});

		$(".contentSwap a").unbind("click").click(function(){
			contentSwap($(this),"#contentSwap");
		}).attr("href",function() { 
			return "#"+this.href.substring(this.href.lastIndexOf('/')+1).replace(".html","");
		});

/*
		if(readCookie("weatherfilea") != null) {
			$.get("includes/weather/"+readCookie("weatherfile"), function(data){
				$("#weather").html('<div id="weatherInclude">'+data+'</div>').show();
				bindChooseCity();
			});
		} else {
			$("#weather").show();
			bindChooseCity();
		}
*/	
		
/*		$(".ddBorder2").bind("click", function(){ //Bind drop down menus
			dropDown($(this).attr("rel"));
			return false;
		});
*/
		//Popup poll links
		$(".#pollForm a").bind("click", function(){
			afficheResultats($(this).attr("href"),$(this).attr("rel"));
			return false;
		});
		
		$(".sizeText a").click(function(){
			sizeText($(this),$(this).attr("class"));
			return false;
		});
	
		//bindStoryHover($("div.story"));	
		//$("div.story a").hover(function(){$(this).parents(".story").unbind("click")},function(){bindStoryClick($(this).parents(".story"))});
	
		//Widgets
	/*	var so = new FlashObject("http://www.torontosun.com/WCM/HomepageFiles/widget_tsun.swf", "ca", "570", "208", "7", "#ffffff");
		so.addVariable("config", "http://www.torontosun.com/WCM/HomepageFiles/tsun.xml");
		so.addParam("quality", "high");
		so.addParam("salign", "t");
		so.addParam("wmode", "transparent");*/
		//so.write("widgets");

		firstPageLoad = false;

		//Alternate colors on some lists
		var isAltColor = false;
		$("ul.altColors li").each(function(){
			var thisthis = $(this);
			if(thisthis.attr("class")=="sectionTitle") isAltColor = true;
			if(isAltColor) thisthis.addClass("altBG");
			isAltColor = !isAltColor;
		});
		
		//Altername colors on table rows
		$("table.altColors tbody tr:even").addClass("altBG");
		
		
		//Binds the buttons for scrolling ajax boxes
		$(".scroll").bind("click", function(){
			ajaxScroll($(this).attr("href").substring(1),$(this).parent());
			return false;
		});
		
	/*	bindSunshine(); //binds ajax calls for the sunshine girl calendar */

		try {	
			CanoeMeteo.loadMeteo(true);
		} catch(e) {
			try {
				_meteo_change(true);
			} catch(e) {}
		}
	}

	/* this portion must be always called even if it's not the first time, dhtml content swap */
	bindReferToArticleTextHover($("div.referToArticleText"));	
	$("div.referToArticleText a").hover(function(){$(this).parents(".referToArticleText").unbind("click")},function(){bindReferToArticleTextClick($(this).parents(".referToArticleText"))});

}

$(document).ready(function(){
	pageInit();	
});











