document.cnnAdNetwork = "3475.vlt";
document.cnnAdPath = ( ( document.URL ).replace( /http:\/\/([^\/]+)/, "" ) ).replace( /\/\//, "/" );
if( ( document.cnnAdPath ).charAt( ( document.cnnAdPath ).length - 1 ) == "/" ) document.cnnAdPath += "index.htm"; // make sure there's always a filename
document.cnnAdPathArray = ( ( document.cnnAdPath ).substr( 1 ) ).split( "/" );

var cnn_maxRelatedTopics = 10;

/* start audience science */
var rsi_segs = [];
var segs_beg=document.cookie.indexOf('rsi_segs=');
if(segs_beg>=0){
	segs_beg=document.cookie.indexOf('=',segs_beg)+1;
	if(segs_beg>0){
		var segs_end=document.cookie.indexOf(';',segs_beg);
		if(segs_end==-1)segs_end=document.cookie.length;
			rsi_segs=document.cookie.substring(segs_beg,segs_end).split('|');
	}
}
var segLen=20
var segQS="",segArr=new Array()
if (rsi_segs.length<segLen){segLen=rsi_segs.length}
for (var i=0;i<segLen;i++){
	segArr=rsi_segs[i].split("_")
	if (segArr.length>1) segQS+=("rsi"+"="+segArr[1]+";")
}
/* end audience science */

/* start quantcast */
function _quantgc(n) {
	var c=document.cookie;
	if(!c)return '';
	var i=c.indexOf(n+"=");
	if(-1==i)return '';
	var len=i+n.length+1;
	var end=c.indexOf(";", len);
	return c.substring(len,end<0?c.length:end);
}
// Code below is customizable per publisher
quantSegs = "";
var _qsegs = _quantgc('__qseg').split('|');
for (i in _qsegs) {
	var qArr=_qsegs[i].split("_");
	quantSegs += ("qc=" + qArr[1] + ";");
}
/* end quantcast */


var cnnad_sportsData = {
	"Major_League_Baseball":		"sports/baseball_mlb",
	"National_Football_League":		"sports/football_nfl",
	"National_Football_Conference":		"sports/football_nfl",	// maybe needed
	"American_Football_Conference":		"sports/football_nfl",	// maybe needed
	"National_Basketball_Association":	"sports/basketball_nba",
	"National_Hockey_League":		"sports/hockey_nhl",
	"College_Football":			"sports/football_ncaa",
	"College_Basketball":			"sports/basketball_ncaa",
	"tennis":				"sports/tennis",
	"Tennis":				"sports/tennis",
	"soccer":				"sports/soccer",
	"Soccer":				"sports/soccer",
	"nascar":				"sports/nascar",
	"High_School_Athletics":		"sports/highschool",
	"Golf":					"sports/golf",
	"Professional_Golfers_Association":	"sports/golf",		// maybe needed
	"Summer_Olympics":			"sports/olympics",
	"Winter_Olympics":			"sports/olympics",
	"Boxing":				"sports/boxing"
};

function cnnad_createAd( width, height ) {
	// given the dimensions of the ad to be returned, generate the script call

	// set the global ad variables
	if( width != 242 ) { // temporarily remove the 242x90 ad

		document.cnnAdInterstitial = ( document.cnnAdInterstitial == undefined ? "ist" : "" );
		document.cnnAdTile = (document.cnnAdTile||0) + 1;
		document.cnnAdRandom = document.cnnAdRandom || Math.ceil(1+1E12*Math.random());

		var isTesting = false;

		var adcode = 'http://ad.doubleclick.net/adj/' + document.cnnAdNetwork + '/';
		var dart_value = cnnad_getDartValue();
		var adparameters = cnnad_getKeywords( dart_value );
		var adpath = cnnad_getPath();
		var adsize = 'dcove=d;sz=' + width + 'x' + height;
			if( width == 988 ) adsize += ',728x90';
			if( width == 300 ) adsize += ',300x600,160x600';
			adsize += ';';
		var addcopt = ''; if( document.cnnAdInterstitial != "" ) addcopt = 'dcopt=' + document.cnnAdInterstitial + ';';
		var adtile = 'tile=' + document.cnnAdTile + ';';
		var adord = 'ord=' + document.cnnAdRandom;

		// put it all together
		adcode = '<scr'+'ipt language="JavaScript1.1" src="' + adcode + dart_value + adparameters + adpath + segQS + quantSegs + adsize + addcopt + adtile + adord + '?"></scr'+'ipt>';
		adcode = adcode.replace( "'", "_" )

		// if you have the cookie, write out the script file source
		if( isTesting ) { document.write( '<div style="background-color:#333;height:' + height + 'px;overflow:hidden;">' ); }
		if( WM_readCookie( 'cnnad_solbright' ) == "set" ) {
			document.write( '<div style="background-color:#f00;color:#fff;font-family:verdana;font-size:9px;text-align:center;">' + ( ( ( adcode.substring( ( adcode ).indexOf( 'http' ), ( adcode ).lastIndexOf( '"' ) ) ).replace( /;/g, "; " ) ).replace( /\//g, " / " ) ).replace( /\./g, ". " ).replace( /-/g, "_" ) + '</div>' );
		}
		document.write( adcode );
		if( isTesting ) { document.write( '</div>' ); }
	}

}
function cnnad_getDartValue() {
	// return the dart value
	var retValue = '';
	if( ( window.location.protocol + '//' + window.location.host + window.location.pathname ) == 'http://vault.sportsillustrated.cnn.com/' ) { retValue = 'mainpage'; }
	else if( ( window.location.protocol + '//' + window.location.host + window.location.pathname ) == 'http://siwiki.sportsillustrated.cnn.com/SI_Wiki' ) { retValue = 'wiki/main'; }
	else if( ( window.location.host ) == 'siwiki.sportsillustrated.cnn.com' ) { retValue = 'wiki'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/home' ) == 0 ) { retValue = 'mainpage'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/article/home/m/1/' ) == 0 ) { retValue = 'articles/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/article' ) == 0 ) { retValue = 'articles'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/photo/home' ) == 0 ) { retValue = 'photos/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/photo' ) == 0 ) { retValue = 'photos'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/gallery/home/a/1/' ) == 0 ) { retValue = 'galleries/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/gallery' ) == 0 ) { retValue = 'galleries'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/video/home' ) == 0 ) { retValue = 'video/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/video' ) == 0 ) { retValue = 'video'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/cover/home' ) == 0 ) { retValue = 'covers/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/cover' ) == 0 ) { retValue = 'covers'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/wiki/home' ) == 0 ) { retValue = 'wiki/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/wiki' ) == 0 ) { retValue = 'wiki'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/swimsuit/home' ) == 0 ) { retValue = 'swimsuit/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/swimsuit' ) == 0 ) { retValue = 'swimsuit'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/result/home' ) == 0 ) { retValue = 'search/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/result' ) == 0 ) { retValue = 'search'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/halloffame/home' ) == 0 ) { retValue = 'hall/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/halloffame' ) == 0 ) { retValue = 'hall'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/topic/activeplayers/CBB' ) == 0 ) { retValue = 'sports/basketball_ncaa'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/topic/activeplayers/CFOOT' ) == 0 ) { retValue = 'sports/football_ncaa'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/topic/activeplayers/MLB' ) == 0 ) { retValue = 'sports/baseball_mlb'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/topic/activeplayers/NBA' ) == 0 ) { retValue = 'sports/basketball_nba'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/topic/activeplayers/NFL' ) == 0 ) { retValue = 'sports/football_nfl'; }
	else if( ( document.cnnAdPath ).indexOf( '/vault/topic/activeplayers/NHL' ) == 0 ) { retValue = 'sports/hockey_nhl'; }
	else if( ( document.cnnAdPath ).indexOf( '/home' ) == 0 ) { retValue = 'mainpage'; }
	else if( ( document.cnnAdPath ).indexOf( '/article/home/m/1/' ) == 0 ) { retValue = 'articles/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/article' ) == 0 ) { retValue = 'articles'; }
	else if( ( document.cnnAdPath ).indexOf( '/photo/home' ) == 0 ) { retValue = 'photos/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/photo' ) == 0 ) { retValue = 'photos'; }
	else if( ( document.cnnAdPath ).indexOf( '/gallery/home/a/1/' ) == 0 ) { retValue = 'galleries/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/gallery' ) == 0 ) { retValue = 'galleries'; }
	else if( ( document.cnnAdPath ).indexOf( '/video/home' ) == 0 ) { retValue = 'video/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/video' ) == 0 ) { retValue = 'video'; }
	else if( ( document.cnnAdPath ).indexOf( '/cover/home' ) == 0 ) { retValue = 'covers/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/cover' ) == 0 ) { retValue = 'covers'; }
	else if( ( document.cnnAdPath ).indexOf( '/wiki/home' ) == 0 ) { retValue = 'wiki/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/wiki' ) == 0 ) { retValue = 'wiki'; }
	else if( ( document.cnnAdPath ).indexOf( '/swimsuit/home' ) == 0 ) { retValue = 'swimsuit/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/swimsuit' ) == 0 ) { retValue = 'swimsuit'; }
	else if( ( document.cnnAdPath ).indexOf( '/result/home' ) == 0 ) { retValue = 'search/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/result' ) == 0 ) { retValue = 'search'; }
	else if( ( document.cnnAdPath ).indexOf( '/halloffame/home' ) == 0 ) { retValue = 'hall/main'; }
	else if( ( document.cnnAdPath ).indexOf( '/halloffame' ) == 0 ) { retValue = 'hall'; }
	else if( ( document.cnnAdPath ).indexOf( '/topic/activeplayers/CBB' ) == 0 ) { retValue = 'sports/basketball_ncaa'; }
	else if( ( document.cnnAdPath ).indexOf( '/topic/activeplayers/CFOOT' ) == 0 ) { retValue = 'sports/football_ncaa'; }
	else if( ( document.cnnAdPath ).indexOf( '/topic/activeplayers/MLB' ) == 0 ) { retValue = 'sports/baseball_mlb'; }
	else if( ( document.cnnAdPath ).indexOf( '/topic/activeplayers/NBA' ) == 0 ) { retValue = 'sports/basketball_nba'; }
	else if( ( document.cnnAdPath ).indexOf( '/topic/activeplayers/NFL' ) == 0 ) { retValue = 'sports/football_nfl'; }
	else if( ( document.cnnAdPath ).indexOf( '/topic/activeplayers/NHL' ) == 0 ) { retValue = 'sports/hockey_nhl'; }
	else {
		retValue = cnnad_findSportTopic();
		if( retValue != '' ) { retValue = cnnad_sportsData[ retValue ]; }
	}
	retValue += ';';
	return retValue;
}

function cnnad_findSportTopic() {
	// if one of the topics exists in cnnad_sportsData, return the string, else return an empty string
	var retValue = '';
	if( document.sivTopics ) {
		for( var x = 0; x < ( document.sivTopics ).length; x++ ) {
			var myTopic = ( document.sivTopics[x] ).replace( / /g, "_" );
			if( cnnad_sportsData[ myTopic ] ) {
				retValue = myTopic;
				x = ( document.sivTopics ).length;
			}
		}
	}
	return retValue;
}

function cnnad_getKeywords( dart_value ) {
	// return a complete list of keywords
	var retValue = '';

	// return a list of the other topics of a page
/*
	var mySportTopic = cnnad_findSportTopic();
	if( mySportTopic == "" ) { // if there is no dart value, just return every topic
*/
		var myLength = ( document.sivTopics ).length;
		if( myLength > cnn_maxRelatedTopics ) { myLength = cnn_maxRelatedTopics; }
		for( var x = 0; x < myLength; x++ ) {
			retValue += 'rel=' + ( document.sivTopics[x] ).replace( / /g, "_" ) + ';';
		}
/*
	} else { // return every topic except the matching sport one
		for( var x = 0; x < ( document.sivTopics ).length; x++ ) {
			if( mySportTopic != ( document.sivTopics[x] ).replace( / /g, "_" ) ) {
				retValue += 'rel=' + ( document.sivTopics[x] ).replace( / /g, "_" ) + ';';
			}
		}
	}
*/	
	return retValue;
}

function cnnad_getPath() {
	// take the path and return each folder from start to the file as a path attribute
	var retValue = "";
	for( var x = 0; x < ( document.cnnAdPathArray ).length - 1; x++ ) {
		retValue += 'path=' + ( document.cnnAdPathArray )[ x ] + ';';
	}
	return retValue;
}




// Cookies
function WM_browserAcceptsCookies() {
	var WM_acceptsCookies = false;
	if ( document.cookie == '' ) {
		document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
		if ( document.cookie.indexOf( 'WM_acceptsCookies=yes' ) != -1 ) {
			WM_acceptsCookies = true;
		} // If it succeeds, set variable
	} else { // there was already a cookie
		WM_acceptsCookies = true;
	}

	return ( WM_acceptsCookies );
}

function WM_setCookie( name, value, hours, path, domain, secure ) {
	if ( WM_browserAcceptsCookies() ) { // Don't waste your time if the browser doesn't accept cookies.
		var numHours = 0;
		var not_NN2 = ( navigator && navigator.appName
					&& (navigator.appName == 'Netscape')
					&& navigator.appVersion
					&& (parseInt(navigator.appVersion) == 2) ) ? false : true;

		if ( hours && not_NN2 ) { // NN2 cannot handle Dates, so skip this part
			if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
				numHours = hours;
			} else if ( typeof(hours) == 'number' ) { // calculate Date from number of hours
				numHours = ( new Date((new Date()).getTime() + hours*3600000) ).toGMTString();
			}
		}

		document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
	}
} // WM_setCookie

function WM_readCookie( name ) {
	if ( document.cookie == '' ) { // there's no cookie, so go no further
		return false;
	} else { // there is a cookie
		var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
		var NN2Hack = firstChar + name.length;
		if ( (firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=') ) { // if you found the cookie
			firstChar += name.length + 1; // skip 'name' and '='
			lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
			if (lastChar == -1) lastChar = theBigCookie.length;
			return unescape( theBigCookie.substring(firstChar, lastChar) );
		} else { // If there was no cookie of that name, return false.
			return false;
		}
	}
} // WM_readCookie

function WM_killCookie( name, path, domain ) {
	var theValue = WM_readCookie( name ); // We need the value to kill the cookie
	if ( theValue ) {
		document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
	}
} // WM_killCookie
