// JavaScript Document
var takeOver; //Boolean value returned to Flash regarding implementation of takeOver ad
	var timeout_id; //to call showTakeover function
	var toPeriods = new Array(0,12,24); // day-part END times - 4pm=16, midnight=24

	var hour_extract = new Date();
	var current_hour = hour_extract.getHours();
	//getUTCHours would be 7 ghours ahead, everything else is UTC time
	var current_day = hour_extract.getUTCDay();
	//get the current hour to set our cookie expires Date value
	
	var cookie_expires = new Date();
	
	if(current_hour >= toPeriods[0] && current_hour < toPeriods[1])	{
		cookie_expires.setHours(toPeriods[1]);
		cookie_expires.setUTCMinutes(0);
		cookie_expires.setUTCSeconds(0);
		//if between midnight and 3am
		//alert("if between midnight and 3am cookie_expires: " + cookie_expires);
		//alert("1: current_hour: " + current_hour + ", " + cookie_expires.toUTCString());
	}
	else if(current_hour >= toPeriods[1] && current_hour < toPeriods[2])	{
		cookie_expires.setHours(toPeriods[0]);
		cookie_expires.setUTCMinutes(0);
		cookie_expires.setUTCSeconds(0);
		
		cookie_expires.setUTCDate(cookie_expires.getUTCDate() + 1);
		//increment the day 24 hours as above we have only adjusted the hour, minutes and seconds but no the day
		//if between 3am and 3pm
		//alert("if between 3am and 3pm cookie_expires: " + cookie_expires);
		//alert("2: current_hour: " + current_hour + ", " + cookie_expires.toUTCString());
	}
	
	//set our cookie_expires Date Object
	//document.write("<font color='#FFFFFF'>PST " + cookie_expires + ", GMT</font>");
	//document.write("<font color='#FFFFFF'>" + cookie_expires.toGMTString() + "</font>");

    var cookie_name = "dayTakeover";
	var cookie_value_increment;
	var cookie_value_increment_max = 200; //make 2 if ad
	var cookie_arr;
	var cookie_written_arr;
	//initilise cookie array variables
	var increment_nmb;
	//counter
	
	// Create a cookie with the specified name and value.
	// The cookie expires at the end of the 21st century.	
	function SetCookie(sName, sValue)	{
	    date = new Date();
	    //document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT;";
		document.cookie = cookie_name + "=" + escape(sValue) + "; expires=" + cookie_expires.toUTCString() + ";";
		//alert(cookie_expires.toGMTString());
	}
	
	// Get the value of the cookie with the specified name.
	function GetCookie(cookie_name)	{
	  cookie_written_arr = document.cookie.split("; ");
	  //based on the setCookie function the cookie will be written on your system something like: "cookie_name = 0". We split it so we dont' get: "; expires=Fri, 31 Dec 2099 23:59:59 GMT;", ie: the expiry date. If there are more than one cookies, then the 1st element in the array may be name/value pair in a String: "cookie_name = 0", the 2nd element: "himym_takover = 2", etc
	  
	  for (var i=0; i < cookie_written_arr.length; i++)	{
	  	  //the length is 1 in this case
	      // a name/value pair (a crumb) is separated by an equal sign
		  cookie_arr = cookie_written_arr[i].split("=");
		  //we make the name value pair: "cookie_name = 0" of the only element of array cookie_written_arr, 2 array elements in array cookie_arr: cookie_arr[0] = cookie_name, cookie_arr[1] = "1". So even numbers will contain cookie names and odd numbers will contain the cookie values in String format
		  
		  if (cookie_name == cookie_arr[0])	{
		  	 //if in the GetCookie(cookie_name); function call, the parameter equals cooke_arr element 0 which it does
		     return unescape(cookie_arr[1]);
			 //if parameter cookie_name equals the actual cookie name, return the acutal value which is in cookie_arr element 2
		  }
	  }
	
	  return null;
	  //if a cookie with the requested name does not exist, return null
	}
	
	// Delete the cookie with the specified name.
	// The value of the cookie is unnecessary.
	function DelCookie(cookie_name)	{
	  document.cookie = cookie_name + "=; expires=Fri, 21 Dec 1976 04:31:24 GMT;";
	  // we use an expiry date in the past so the cookie is automatically deleted
	}
	
	function showTakeover() {
		//alert('showTakeover has been called');
		
		//var geturl = window.location.toString();
		
		var ord_srt = ord + "";
		
		if(GetCookie(cookie_name) == null)	{
			SetCookie(cookie_name, 0);
			takeOver = true;
			thisMovie("ad_light").getTakeover(takeOver, ord_srt); //ungrey if ad
			//thisMovie("ad_light").getTakeover(false, "");
			//alert(geturl);
			//alert("1 " + GetCookie(cookie_name));
		}
		else	{
			cookie_value_increment = parseInt(cookie_arr[1]) + 1;
			SetCookie(cookie_name, cookie_value_increment);
			
			if(cookie_value_increment < cookie_value_increment_max)	{
				takeOver = true;
				thisMovie("ad_light").getTakeover(takeOver, ord_srt); //ungrey if ad
				//thisMovie("ad_light").getTakeover(false, "");
			}
			else	{
				takeOver = false;
				thisMovie("ad_light").getTakeover(takeOver, ""); //ungrey if ad
				//thisMovie("ad_light").getTakeover(false, "");
			}
		}
		//alert(GetCookie(cookie_name));
		
		clearTimeout(timeout_id);
	}

	function thisMovie(movieName) {
        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[movieName]
        }
        else {
            return document[movieName]
        }
    }
                    
    function setTakeover()	{
        //alert('setTakeover has been called');
        timeout_id = setTimeout("showTakeover()", 500);
    }
	
	document.write('<div style="position:absolute; left:-1px; right:-1px"><img src="http://images.sportsline.com/images/spacer.gif" name="dot1x1" id="dot1x1" width="1" height="1" border="0"></div>');

	function adTracker(adTrack) {
		document.dot1x1.src = adTrack; 
		return;
	}
	//1x1 image into the page (ad tracking)

	function evalThis(url) { 
		var headLoc = document.getElementsByTagName("head").item(0); 
		var scriptObj = document.createElement("script"); 
		scriptObj.setAttribute("type", "text/javascript"); 
		scriptObj.setAttribute("src", url); 
		headLoc.appendChild(scriptObj); 
	}
	//execute an external .js file after page has already loaded for survey
	
	function adTrack2(url) { 
		document.dot1x12.src=url;
		return;
	}
	//to call a 1x1 image into the page (ad tracking), pixel doesn't currently exist as 2nd ad not used
	
	function adSurvey2(url) { 
		var headLoc2 = document.getElementsByTagName("head").item(0); 
		var scriptObj2 = document.createElement("script"); 
		scriptObj2.setAttribute("type", "text/javascript"); 
		scriptObj2.setAttribute("src", url); 
		headLoc2.appendChild(scriptObj2); 
	}