var agt		= navigator.userAgent.toLowerCase();
var versInt	= parseInt(navigator.appVersion);
var is_aol	= (agt.indexOf("aol") != -1);
var cnnDomainArray = location.hostname.split( '.' );
var EditionDomain = ( cnnDomainArray.length > 1 ) ? '.' + cnnDomainArray[cnnDomainArray.length-2] + '.' + cnnDomainArray[cnnDomainArray.length-1] : '';

function CNN_goTo( url ) {
	window.location.href = url;
}

function CNN_roofBar( tableCellRef, hoverFlag ) {
	if ( hoverFlag ) {
		tableCellRef.style.backgroundImage = 'url("http://i.cnn.net/cnn/.element/img/1.0/main/roofbar_bg2.gif")';
		if ( document.getElementsByTagName ) {
			tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#c00';
		}
	} else {
		tableCellRef.style.backgroundImage = 'url("http://i.cnn.net/cnn/.element/img/1.0/main/roofbar_bg.gif")';
		if ( document.getElementsByTagName ) {
			tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#333';
		}
	}
}

function CNN_roofBarClick( tableCellRef, url ) {
	CNN_roofBar( tableCellRef, 0 );
	CNN_goTo( url );
}

function CNN_navBar( tableCellRef, hoverFlag, navStyle ) {
	if ( hoverFlag ) {
		switch ( navStyle ) {
			case 1:
				tableCellRef.style.backgroundColor = '#69c';
				break;
			default:
				if ( document.getElementsByTagName ) {
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#c00';
				}
		}
	} else {
		switch ( navStyle ) {
			case 1:
				tableCellRef.style.backgroundColor = '#036';
				break;
			default:
				if ( document.getElementsByTagName ) {
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#000';
				}
		}
	}
}

function CNN_navBarClick( tableCellRef, navStyle, url ) {
	CNN_navBar( tableCellRef, 0, navStyle );
	CNN_goTo( url );
}

// Copyright © 2005 by ETSTRATEGIC MARKETING, Inc., All Rights Reserved.

// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function canDetectPlugins() {
	if ( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
		return true;
	}
	return false;
}

function detectFlash() {
	pluginFound = detectPlugin( 'Shockwave', 'Flash' );
	// if not found, try to detect with VisualBasic
	if ( !pluginFound && detectableWithVB ) {
		pluginFound = detectActiveXControl( 'ShockwaveFlash.ShockwaveFlash.1' );
	}
	return pluginFound;
}

function detectDirector() {
	pluginFound = detectPlugin( 'Shockwave', 'Director' );
	// if not found, try to detect with VisualBasic
	if ( !pluginFound && detectableWithVB ) {
		pluginFound = detectActiveXControl( 'SWCtl.SWCtl.1' );
	}
	return pluginFound;
}

function detectQuickTime() {
	pluginFound = detectPlugin( 'QuickTime' );
	// if not found, try to detect with VisualBasic
	if ( !pluginFound && detectableWithVB ) {
		pluginFound = detectQuickTimeActiveXControl();
	}
	return pluginFound;
}

function detectReal() {
	pluginFound = detectPlugin( 'RealPlayer' );
	// if not found, try to detect with VisualBasic
	if ( !pluginFound && detectableWithVB ) {
		pluginFound = ( detectActiveXControl('rmocx.RealPlayer G2 Control') ||
			detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
			detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)')
		);
	}
	return pluginFound;
}

function detectRealOne() {
	pluginFound = detectPlugin( 'RealOne Player Version Plugin' ) || detectPlugin( 'RealPlayer Version Plugin' );
	// if not found, try to detect with VisualBasic
	if ( !pluginFound && detectableWithVB ) {
		pluginFound = detectRealOneActiveXControl();
	}
	return pluginFound;
}

function detectWindowsMedia() {
	pluginFound = detectPlugin( 'Windows Media' );
	// if not found, try to detect with VisualBasic
	if ( !pluginFound && detectableWithVB ) {
		pluginFound = detectActiveXControl( 'MediaPlayer.MediaPlayer.1' );
	}
	return pluginFound;
}

function detectPlugin() {
	// allow for multiple checks in a single pass
	var daPlugins = arguments;
	// consider pluginFound to be false until proven true
	var pluginFound = false;
	// if plugins array is there and not fake
	if ( navigator.plugins && navigator.plugins.length > 0 ) {
		var pluginsArrayLength = navigator.plugins.length;
		// for each plugin...
		for ( var pluginsArrayCounter = 0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
			// loop through all desired names and check each against the current plugin name
			var numFound = 0;
			for ( var namesCounter = 0; namesCounter < daPlugins.length; namesCounter++ ) {
				// if desired plugin name is found in either plugin name or description
				if ( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
					(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
					// this name was found
					numFound++;
				}
			}
			// now that we have checked all the required names against this one plugin,
			// if the number we found matches the total number provided then we were successful
			if ( numFound == daPlugins.length ) {
				pluginFound = true;
				// if we've found the plugin, we can stop looking through at the rest of the plugins
				break;
			}
		}
	}
	return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ( (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) ) {
	document.writeln( '<script language="VBscript">' );

	document.writeln( '\'do a one-time test for a version of VBScript that can handle this code' );
	document.writeln( 'detectableWithVB = False' );
	document.writeln( 'If ScriptEngineMajorVersion >= 2 then' );
	document.writeln( '  detectableWithVB = True' );
	document.writeln( 'End If' );

	document.writeln( '\'this next function will detect most plugins' );
	document.writeln( 'Function detectActiveXControl( activeXControlName )' );
	document.writeln( '  on error resume next' );
	document.writeln( '  detectActiveXControl = False' );
	document.writeln( '  If detectableWithVB Then' );
	document.writeln( '     detectActiveXControl = IsObject( CreateObject( activeXControlName ) )' );
	document.writeln( '  End If' );
	document.writeln( 'End Function' );

	document.writeln( '\'and the following function handles QuickTime' );
	document.writeln( 'Function detectQuickTimeActiveXControl()' );
	document.writeln( '  on error resume next' );
	document.writeln( '  detectQuickTimeActiveXControl = False' );
	document.writeln( '  If detectableWithVB Then' );
	document.writeln( '    detectQuickTimeActiveXControl = False' );
	document.writeln( '    hasQuickTimeChecker = false' );
	document.writeln( '    Set hasQuickTimeChecker = CreateObject( "QuickTimeCheckObject.QuickTimeCheck.1" )' );
	document.writeln( '    If IsObject( hasQuickTimeChecker ) Then' );
	document.writeln( '      If hasQuickTimeChecker.IsQuickTimeAvailable( 0 ) Then ' );
	document.writeln( '        detectQuickTimeActiveXControl = True' );
	document.writeln( '      End If' );
	document.writeln( '    End If' );
	document.writeln( '  End If' );
	document.writeln( 'End Function' );

	document.writeln( '\'and the following function handles RealOne' );
	document.writeln( 'Function detectRealOneActiveXControl()' );
	document.writeln( '  on error resume next' );
	document.writeln( '  detectRealOneActiveXControl = False' );
	document.writeln( '  If detectableWithVB Then' );
	document.writeln( '    detectRealOneActiveXControl = False' );
	document.writeln( '    hasRealOneVersionPlugin = false' );
	document.writeln( '    Set hasRealOneVersionPlugin = CreateObject( "IERPCtl.IERPCtl.1" )' );
	document.writeln( '    If IsObject( hasRealOneVersionPlugin ) Then' );
	document.writeln( '      If hasRealOneVersionPlugin.RealPlayerVersion Then ' );
	document.writeln( '        detectRealOneActiveXControl = True' );
	document.writeln( '      End If' );
	document.writeln( '    End If' );
	document.writeln( '  End If' );
	document.writeln( 'End Function' );

	document.writeln( '<\/scr' + 'ipt>' );
}


// ________________________________________________________________ LaunchVideo

function LV_getRealOneStatus() {	// returns ('undetermined'|'installed'|'notinstalled'|'using')
	var RealOneInst = "undetermined";

	if ( canDetectPlugins() ) {
		if ( detectRealOne() ) {
			RealOneInst = "installed";
			if ( agt.indexOf( "(r1 " ) != -1 ) {
				RealOneInst = "using";
			}
		} else {
			RealOneInst = "notinstalled";
		}
	}

	return RealOneInst;
}

function LV_getVideoUrl( videoUrlPath, format, realOneStatus ) {
	var fullUrl;
	var preferredEdition = "www";
	var selectedEdition = WM_readCookie( "SelectedEdition" );
	var premiumUrlPrefix = "http://premium.cnn.com/pr/video";
	var premiumEdition = "premium.cnn.com";
	
	if ( selectedEdition ) {
		preferredEdition = selectedEdition;
	}
	
	if ( preferredEdition == "asia" || preferredEdition == "europe" ) {
		preferredEdition = "edition";
	}
	
	if ( preferredEdition != "www" ) {
		premiumEdition = "premium." + preferredEdition + ".cnn.com";
		premiumUrlPrefix = "http://" + premiumEdition + "/pr/video";
	}
	
	switch( realOneStatus ) {
		case "using":
			fullUrl = premiumUrlPrefix + "/meta" + videoUrlPath + "r1.smil"; 
			break;
		case "installed":
			fullUrl = premiumUrlPrefix + "/meta" + videoUrlPath + "np.smil"; 
			break;
		case "notinstalled":
		default:
			fullUrl = premiumUrlPrefix + videoUrlPath + "exclude.html";
			if ( format == "public" ) {
				fullUrl = "http://premium.cnn.com/video" + videoUrlPath + "exclude.html";
			}
			break;
	}
	
	return ( fullUrl );
}

function LaunchVideo( videoPath, videoFormat ) {
	var VIDEO_POPUP_WIDTH = 620;
	var VIDEO_POPUP_HEIGHT = 480;
	var realOneStatus = LV_getRealOneStatus();
	var videoUrl;

	if ( realOneStatus != "using" ) {	// if you're not using RealOne..
		var isSynacor = WM_readCookie( "synacor" );
		if ( is_aol || isSynacor ) {	// if you're using AOL or from Synacor, you're getting the popup
			realOneStatus = "notinstalled";
		} else {	// let's check your cookie
			var playerPref = WM_readCookie( "player" );
			if ( playerPref ) {
				switch ( playerPref.toUpperCase() ) {
					case "REALONE":
					case "REAL":	// if your preference is Real, but it's not installed..
						if ( realOneStatus != "installed" ) {
							realOneStatus = "notinstalled";	// ..you'll get the popup
						}
						break;
					case "WINDOWS MEDIA":
					case "QUICKTIME":
					default:
						realOneStatus = "notinstalled";	// popup window
						break;
				}
			}
		}
	}
		
	videoUrl = LV_getVideoUrl( videoPath, videoFormat, realOneStatus );
	
	if ( videoUrl.indexOf( ".exclude.html" ) > 0 ) {
		CNN_openPopup( videoUrl, '' + VIDEO_POPUP_WIDTH + 'x' + VIDEO_POPUP_HEIGHT, 'width=' + VIDEO_POPUP_WIDTH + ',height=' + VIDEO_POPUP_HEIGHT + ',scrollbars=no,resizable=no' );
	} else {
		top.location.href = videoUrl;
	} 
}


function med_vod( vidlocation ) {
	if ( ( agt.indexOf( "r1" ) != -1 ) && ( vidlocation.indexOf( "med.exclude.html" ) != -1 ) ) {
		var url = vidlocation.replace( "med.exclude.html", "r1.smi" );
		location.href = url;
	} else {
		CNN_openPopup( vidlocation, '620x460', 'width=620,height=460' );
	}
}


// _____________________________________________________ Netscape Hat

var NS_HAT_COOKIE_NAME = "nsHat";
var NS_HAT_COOKIE_HOURS = '';
var NS_HAT_COOKIE_PATH = "/";
var NS_HAT_COOKIE_DOMAIN = EditionDomain;

if ( !WM_readCookie( NS_HAT_COOKIE_NAME ) && document.referrer && WM_browserAcceptsCookies() )
{
	var referrerMatchArray = document.referrer.toLowerCase().match( "^[^:]+[:/]+([^@]+@)?([^:/]+)[:/]" );
	if ( referrerMatchArray && referrerMatchArray.length > 2 )
	{
		var referrerHostname = referrerMatchArray[2];
		if ( referrerHostname.match( "channels.netscape.com$" ) || referrerHostname.match( "cnn.netscape.cnn.com$" ) )
		{
			WM_setCookie( NS_HAT_COOKIE_NAME, "netscape", '', NS_HAT_COOKIE_PATH, NS_HAT_COOKIE_DOMAIN, '' );
		}
		else
		{
			WM_setCookie( NS_HAT_COOKIE_NAME, "cnn", '', NS_HAT_COOKIE_PATH, NS_HAT_COOKIE_DOMAIN, '' );
		}
	}
}

function displayHat()
{
	var imageDir = ( arguments.length > 0 ) ? ( '/' + arguments[0] + '/' ) : '/white/';
	var referrerHost = WM_readCookie( NS_HAT_COOKIE_NAME );
	switch ( referrerHost )
	{
		case "netscape":
			document.write( '<a href="http://www.netscape.com/" target="new"><img src="http://i.cnn.net/cnn/.element/img/1.1/nshat' + imageDir + 'ns.logo.gif" width="95" height="27" hspace="0" vspace="0" border="0"><\/a><a href="http://www.netscape.com/" target="new"><img src="http://i.cnn.net/cnn/.element/img/1.1/nshat' + imageDir + 'ns.home.gif" width="53" height="27" hspace="0" vspace="0" border="0"><\/a><a href="http://cnn.netscape.cnn.com/news/default.jsp" target="new"><img src="http://i.cnn.net/cnn/.element/img/1.1/nshat' + imageDir + 'ns.news.gif" width="51" height="27" hspace="0" vspace="0" border="0"><\/a><a href="http://sportsillustrated.netscape.cnn.com/" target="new"><img src="http://i.cnn.net/cnn/.element/img/1.1/nshat' + imageDir + 'ns.sports.gif" width="61" height="27" hspace="0" vspace="0" border="0"><\/a><a href="http://channels.netscape.com/ns/pf/default.jsp" target="new"><img src="http://i.cnn.net/cnn/.element/img/1.1/nshat' + imageDir + 'ns.money.gif" width="63" height="27" hspace="0" vspace="0" border="0"><\/a>' );
			break;
		default:
			document.write( '<a href="http://www.netscape.com/" target="new"><img src="http://i.cnn.net/cnn/.element/img/1.1/nshat' + imageDir + 'ns.logo.standalone.gif" width="91" height="27" hspace="2" vspace="0" border="0"><\/a>' );
			break;
	}
}

//CSI functions
var cnnCSIs = new Array();
var cnnUseDelayedCSI = 0;
var localUserAgent = navigator.userAgent.toLowerCase();
if((localUserAgent.indexOf('msie')>-1) && (localUserAgent.indexOf('mac')>-1)){cnnUseDelayedCSI = 1;}

function cnnAddCSI(id,source,args,breakCache)
{
	if(!args) { args='';}
	breakCache = ( !breakCache && ( source.charAt( 0 ) == '/' ) ) ? false : true;
	if(cnnUseDelayedCSI)
	{
		var newCSI = new Object();
		newCSI.src = source;
		newCSI.id  = id;
		newCSI.args = args;
		newCSI.breakCache = breakCache;
		cnnCSIs[cnnCSIs.length]=newCSI;
	}
	else
	{
		var today = new Date();
		var currTime = today.getTime();
		var iframeArgs = ( breakCache ) ? '&time='+currTime : '';
		if(args)
		{
			iframeArgs=iframeArgs+'&'+args;
		}
		var iframeHtmlSrc='<iframe src="'+source+'?domId='+id+iframeArgs+'" name="iframe'+id+'" id="iframe'+id+'" width="0" height="0" align="right" style="visibility:hidden"></iframe>';
		document.write(iframeHtmlSrc);
	}
}

function cnnUpdateCSI(html, id)
{
	var htmlContainerObj = document.getElementById( id ) || document.all[ id ];
	if(htmlContainerObj)
	{
		htmlContainerObj.innerHTML = html;
	}
	//force a refresh of the content area
	var htmlContentArea = document.body;
	if(htmlContentArea)
	{
		var previousTopVal = htmlContentArea.style.top || '0px';
		htmlContentArea.style.top = '1px';
		htmlContentArea.style.top = previousTopVal;
	}
}

function cnnHandleCSIs()
{
	if(document.body && document.body.innerHTML && cnnUseDelayedCSI)
	{
		var iframeOwner = document.getElementById( 'csiIframe' ) || document.all[ 'csiIframe' ];
		var iframeHtmlSrc = '';

		for(var incCounter=0;incCounter<cnnCSIs.length;incCounter++)
		{
			var src = cnnCSIs[incCounter].src;
			var id = cnnCSIs[incCounter].id;
			var today = new Date();
			var breakCache = cnnCSIs[incCounter].breakCache;
			var currTime = today.getTime();
			var args = ( breakCache ) ? '&time='+currTime : '';
			if(cnnCSIs[incCounter].args)
			{
				args=args+'&'+cnnCSIs[incCounter].args;
			}
			
			iframeHtmlSrc+='<iframe src="'+src+'?domId='+id+args+'" name="iframe'+id+'" id="iframe'+id+'" width="0" height="0" align="right"></iframe>';
		}
		if(iframeOwner)
		{
			iframeOwner.innerHTML=iframeHtmlSrc;
		}
	}
}

var cnnEnableCL = true;
if(window.location.hostname.indexOf('cnnstudentnews.')>-1) { cnnEnableCL = false; }
if(window.location.hostname.indexOf('edition.')>-1) { cnnEnableCL = false; }
// End CSI functions

// end

var cnnDocDomain = '';
if(location.hostname.indexOf('cnn.com')>0) {cnnDocDomain='cnn.com';}
if(location.hostname.indexOf('turner.com')>0) {if(document.layers){cnnDocDomain='turner.com:'+location.port;}else{cnnDocDomain='turner.com';}}
if(cnnDocDomain) {document.domain = cnnDocDomain;}

