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

/* 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 */

function cnnad_createAd( dart_value, parameters, width, height, multisize ) {
	var adcode = 'http://ad.doubleclick.net/adj/' + document.cnnAdNetwork + '/';
	var adparameters = cnnad_getPath() + cnnad_getFile(); if( document.cnnAd_addon ) { if( ( cnnad_getDartValue( dart_value ) == "mainpage;" ) || ( cnnad_getDartValue( dart_value ) == "blog/main;" ) ) { adparameters += document.cnnAd_addon; } }
	var adsize = 'dcove=d;sz=' + width + 'x' + height; if( multisize != null ) adsize += ',' + multisize; adsize += ';';
	var addcopt = ''; if( document.cnnAdInterstitial != "" ) addcopt = 'dcopt=' + document.cnnAdInterstitial + ';'; if( ( document.cnnAdPathArray[0] == "POLLSERVER" ) || ( document.cnnAdPathArray[1] == "poll.exclude.html" ) ) addcopt = "";
	var adtile = 'tile=' + document.cnnAdTile + ';'; if( ( document.cnnAdPathArray[0] == "POLLSERVER" ) || ( document.cnnAdPathArray[1] == "poll.exclude.html" ) ) adtile = 'tile=3;';
	var adord = 'ord=' + document.cnnAdRandom;

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

	// if you have the cookie, write out the script file source
	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, ". " ) + '</div>' );
	}

	// write it
	document.write( adcode );
}

function cnnad_createAdHTML( dart_value, parameters, width, height, multisize ) {
	var adcode = 'http://ad.doubleclick.net/adj/' + document.cnnAdNetwork + '/';
	var adparameters = parameters + cnnad_getPath() + cnnad_getFile();
	var adsize = 'dcove=d;sz=' + width + 'x' + height; if( multisize != null ) adsize += ',' + multisize; adsize += ';';
	var addcopt = ''; if( document.cnnAdInterstitial != "" ) addcopt = 'dcopt=' + document.cnnAdInterstitial + ';';
	var adtile = 'tile=' + document.cnnAdTile + ';'; if( dart_value != "test" ) { adtile = 'p' + adtile; }
	var adord = 'ord=' + document.cnnAdRandom;

	var returnCode = '<scr'+'ipt language="JavaScript1.1" src="' + adcode + cnnad_getDartValue( dart_value ) + adparameters + segQS + quantSegs + adsize + addcopt + adtile + adord + '?"></scr'+'ipt>';
	return returnCode;
}

function cnnad_writeBlogHeaderAd( id ) {
}

function cnnad_getPath() { // given a path, split on the slash and pass each element as a value of "path" ( url minus file minus hostname )
	var retValue = "";
	var temp_path = "";
	if( document.cnnAdPathArray.length > 1 ) {
		if( document.cnnAdPathArray[0] != "si_adspaces" ) {
			temp_path += document.cnnAdPathArray.slice( 0, document.cnnAdPathArray.length - 1 ).join( "/" );
		}
	}
	var path_array = temp_path.split( "/" );
	for( var x = 0; x < path_array.length; x++ ) { retValue += 'path=' + ( path_array[x].replace( /\./g, "_" ) ).replace( /,/g, "_" ) + ';'; }
	return retValue;
}

function cnnad_getFile() { // return the file of the url
	var retValue = "";
	var fileArray = ( document.cnnAdPathArray[ document.cnnAdPathArray.length - 1] ).split( "#" );
	if( document.cnnAdPathArray[0] != "si_adspaces" ) {
		retValue = 'file=' + fileArray[0] + ';'
		if( retValue.indexOf( 'file=?eref=' ) == 0 ) {
			retValue = 'file=index.html;';
		}
	}
	return retValue.replace( /\./g, "_" );
}

function cnnad_getDartValue( input ) {  // sometimes input isn't a proper zone value, so return a proper one
	switch( document.cnnAdPathArray[1] ) {
		case '?eref=fromSI':		input = 'mainpage'; break;
		case 'index.html':		input = 'mainpage'; break;
		case 'aboutthemusic':		input = 'music'; break;
		case 'affiliate':		input = 'affiliate'; break;
		case 'affinity':		input = 'affinity'; break;
		case 'blog':			input = 'blog'; break;
		case 'blogarchive':		input = 'blog'; break;
		case 'contactdan':		input = 'contact'; break;
		case 'dictionary':		input = 'dictionary'; break;
		case 'fanclub':			input = 'club'; break;
		case 'fancomments':		input = 'comments'; break;
		case 'interviews':		input = 'interviews'; break;
		case 'photos':			input = 'photos'; break;
		case 'podcasts':		input = 'podcasts'; break;
		case 'showarchive':		input = 'archive'; break;
		case 'showblog':		input = 'blog'; break;
		case 'storyideas':		input = 'ideas'; break;
		case 'streamingaudio':		input = 'audio'; break;
		case 'tunein':			input = 'tune_in'; break;
		case 'upcomingshows':		input = 'upcoming'; break;
		case 'videos':			input = 'video'; break;
		case 'multimedia':		input = 'photos'; break;
		case 'listenlive.player.html':	input = 'audio'; break;
		case 'poll.exclude.html':	input = 'mainpage'; break;
		case 'results':		input = 'mainpage'; break;
		default:			break;
	}
	if( document.cnnAdPathArray[1] == 'index.html' ) {
		// do nothing cause you already have main in the tag
	} else if( ( document.cnnAdPathArray[1] ).indexOf( '?eref' ) == 0 ) {
	} else if( cnnad_getFile() == 'file=index_html;' ) {
		input += '/main';
	}
	return input + ';'; // all dart values should end with a semicolon
}

// 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
