/* from 3.0 */
// Flash Player Version Detection
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE=(navigator.appVersion.indexOf("MSIE")!=-1) ? true : false;
var isWin=(navigator.appVersion.toLowerCase().indexOf("win")!=-1) ? true : false;
var isOpera=(navigator.userAgent.indexOf("Opera")!=-1) ? true : false;
var flashVersion=0;
flashDetect(); // auto-detect flash version

function flashGetVerIE() {
	var version=0;
	var axo;
	var e;
	try {
		axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version=axo.GetVariable("$version");
	} 
	catch (e) {}
	if (!version) {
		try {
			axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			version="WIN 6,0,21,0";
			axo.AllowScriptAccess="always";
			version=axo.GetVariable("$version");
		} 
		catch (e) {}
	}
	if (!version) {
		try {
			axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version=axo.GetVariable("$version");
		} 
		catch (e) {}
	}
	return version;
}

function flashGetVer() {
	var flashVer=-1;
	if (navigator.plugins!=null && navigator.plugins.length>0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2=navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription=navigator.plugins["Shockwave Flash"+swVer2].description;			
			var descArray=flashDescription.split(" ");
			var tempArrayMajor=descArray[2].split(".");
			var versionMajor=tempArrayMajor[0];
			var flashVer=versionMajor;
		}
	}
	else if (isIE && isWin && !isOpera) {flashVer=flashGetVerIE();}	
	return flashVer;
}

function flashDetect(version) {
	var versionStr=flashGetVer();
	if (versionStr==-1) {return false;} 
	else if (versionStr!=0) {
		if(isIE && isWin && !isOpera) {
			var tempArray=versionStr.split(" "); 	
			var tempString=tempArray[1];			
			var versionArray=tempString.split(",");	
		} 
		else {var versionArray=versionStr;}
		flashVersion=versionArray[0];
		if (flashVersion>=version) {return true;}
		return false;
	}
}

function flashWrite(name,url,width,height,params,flashVars) {
	var flv='';
	for (var i in flashVars) {flv+=i+'='+flashVars[i]+'&';}
	var out='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+width+'" height="'+height+'" id="'+name+'">';
	out+='<param name="movie" value="'+url+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" />';
	out+='<param name="flashvars" value="'+flv+'" />';
	for (var i in params) {out+='<param name="'+i+'" value="'+params[i]+'" />';}
	out+='<embed src="'+url+'" quality="high" wmode="transparent" width="'+width+'" height="'+height+'" name="'+name+'" ';
	out+='flashvars="'+flv+'" ';
	out+='type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	out+='</object>';
	document.write(out);
	return out;
}

function cnnGetObject( id ) {
	var object = null;
	if (document.getElementById) object = document.getElementById( id );
	else if (document.all) object = document.all[ id ];
	return object;
}

/* from 2.0 */

function cnnAlterAllSelects(visibility)
{
	var allSelectObjs = document.getElementsByTagName('select');
	if(allSelectObjs)
	{
		for(var selectCounter = 0;selectCounter<allSelectObjs.length;selectCounter++)
		{
			var currentSelectObj = allSelectObjs.item(selectCounter);
			currentSelectObj.style.visibility=visibility;
		}
	}
}

var cnnEnableCL = true;
document.switchDocDomain = true;
if((window.location.pathname.indexOf('/')==window.location.pathname.lastIndexOf('/')) && (window.location.host == "sportsillustrated.cnn.com"))
{
	document.switchDocDomain = false;
}

//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)
{
	if(!args) { args='';}
	if(cnnUseDelayedCSI)
	{
		var newCSI = new Object();
		newCSI.src = source;
		newCSI.id  = id;
		newCSI.args = args;
		cnnCSIs[cnnCSIs.length]=newCSI;
	}
	else
	{
		var today = new Date();
		var currTime = today.getTime();
		var iframeArgs = '&time='+currTime;
		if(!document.switchDocDomain) {iframeArgs=iframeArgs+'&disableDocDom=1';}
		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="position:absolute;visibility:hidden;"></iframe>';
		document.write(iframeHtmlSrc);
	}
}

function cnnUpdateCSI(html, id)
{
	var htmlContainerObj = cnnGetObject( 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;
	}
}


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

/* for 2007 swimsuit */

function cnn07SwimPaginationChange( navId, imageName ) {
	navId.src = 'http://i.cdn.turner.com/si/features/2007_swimsuit/images/navigation/' + imageName + '.jpg';
}

var cnn07SwimMenuEntries = {
	model: {
		posX: 12,
		posXWide: 185
	},
	music: {
		posX: 97,
		posXWide: 262
	},
	video: {
		posX: 283,
		posXWide: 184
	},
	goods: {
		posX: 356,
		posXWide: 220
	},
	sweep: {
		posX: 520,
		posXWide: 165
	},
	s_model: {
		posX: 194,
		posXWide: 219
	},
	s_rooks: {
		posX: 194,
		posXWide: 200
	},
	s_paint: {
		posX: 194,
		posXWide: 205
	},
	s_onloc: {
		posX: 194,
		posXWide: 165
	}
};

var cnn07SwimCurrentVisibleNavId = ''; // The name of the current visible navbar
var cnn07SwimCurrentVisibleSubNavId = ''; // The name of the current visible navbar

function cnn07SwimNavShow( navId ) {
	if ( cnn07SwimCurrentVisibleNavId && ( cnn07SwimCurrentVisibleNavId != navId ) ) {
		cnn07SwimNavHide( cnn07SwimCurrentVisibleNavId );
	}
	var menu = cnn07SwimMenuEntries[ navId ];
	if ( menu ) {
		var subnav = cnnGetObject( 'cnn07SwimSubnav_' + navId );
		if( subnav && subnav.style ) {
			subnav.style.left = menu.posX;
//			subnav.style.width = menu.posXWide;
			subnav.style.visibility = 'visible';
			cnnAlterAllSelects( 'hidden' )
		}
		cnn07SwimCurrentVisibleNavId = navId;
	}
	var imgnav = cnnGetObject( 'img_' + navId );
	if( imgnav ) {
		imgnav.src = 'http://i.cdn.turner.com/si/features/2007_swimsuit/images/navbar/' + navId + '_on.jpg';
	}
}

function cnn07SwimNavHide( navId ) {
	var subnav = cnnGetObject( 'cnn07SwimSubnav_' + navId );
	if( subnav ) {
		subnav.style.visibility = 'hidden';
//		subnav.style.width = '0px';
		cnnAlterAllSelects( 'visible' )
	}
	var imgnav = cnnGetObject( 'img_' + navId );
	if( imgnav ) {
		imgnav.src = 'http://i.cdn.turner.com/si/features/2007_swimsuit/images/navbar/' + navId + '_off.jpg';
	}
}

function cnn07SwimSubNavShow( navId ) {
	if ( cnn07SwimCurrentVisibleSubNavId && ( cnn07SwimCurrentVisibleSubNavId != navId ) ) {
		cnn07SwimSubNavHide( cnn07SwimCurrentVisibleSubNavId );
	}
	var menu = cnn07SwimMenuEntries[ navId ];
	if ( menu ) {
		var subnav = cnnGetObject( 'cnn07SwimSubnav_' + navId );
		if(subnav && subnav.style) {
			subnav.style.left = menu.posX;
//			subnav.style.width = menu.posXWide;
			subnav.style.visibility = 'visible';
			cnnAlterAllSelects( 'hidden' );
		}
		cnn07SwimCurrentVisibleSubNavId = navId;
	}
}

function cnn07SwimSubNavHide( navId ) {
	var subnav = cnnGetObject( 'cnn07SwimSubnav_' + navId );
	if( subnav ) {
		subnav.style.visibility = 'hidden';
//		subnav.style.width = '0px';
		cnnAlterAllSelects( 'visible' )
	}
}

function cnn07SwimShowNavArrow( navId ) {
	var subnav = cnnGetObject( navId + '_row' );
	if( subnav ) {
		if( subnav.className != "row_arrow" ) {
			subnav.className = "row_arrow";
		}
	}
}

function cnn07SwimHideNavArrow( navId ) {
	var subnav = cnnGetObject( navId + '_row' );
	if( subnav ) {
		if( navId == 'location' ) {
			subnav.className = "row2";
		} else {
			subnav.className = "row1";
		}			
	}
}

function cnn07SwimChangeModelImage( imageId, modelId ) {
	switch( imageId ) {
		case "1": document.subsubnav1.src = 'http://i.cdn.turner.com/si/features/2007_swimsuit/images/navbar/thumb_' + modelId + '.jpg';break;
		case "2": document.subsubnav2.src = 'http://i.cdn.turner.com/si/features/2007_swimsuit/images/navbar/thumb_' + modelId + '.jpg';break;
		case "3": document.subsubnav3.src = 'http://i.cdn.turner.com/si/features/2007_swimsuit/images/navbar/thumb_' + modelId + '.jpg';break;
		default: break;
	}
}

var myimages = new Array()
function preloadimages(){
	for (i=0;i<preloadimages.arguments.length;i++){
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
	}
}
preloadimages( "http://i.cdn.turner.com/si/images/misc/gray_pixel.gif" );

document.write("<scr"+"ipt type=\"text/javascript\" language=\"JavaScript1.2\" src=\"http://i.cdn.turner.com/si/.element/ssi/story/2.0/features/2007_swimsuit/adcode.js\"><\/scr"+"ipt>");

//Hover function for IE css nav
cnnHover = function() {
	var sfEls = document.getElementById("cnnSwm07Nv").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" cnnOver";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" cnnOver\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", cnnHover);

// Hide selects from Dropdown on IE rollover
function cnnToggleSelect(state) {
	var dom = (document.getElementById) ? true : false;
	var windows = (navigator.userAgent.toLowerCase().indexOf("windows")>-1) ? true : false;
	var ie5 = ((navigator.userAgent.toLowerCase().indexOf("msie")>-1) && dom) ? true : false;
	var cnn_selects = document.getElementsByTagName("select");
	if (windows && ie5) {
		for (i=0; i<cnn_selects.length; i++) {
			cnn_selects[i].style.visibility = state;
		}
	}
}

document.write("<scr"+"ipt type=\"text/javascript\" language=\"JavaScript1.2\" src=\"http://i.cdn.turner.com/si/.element/js/3.0/cnnSLads.js\"><\/scr"+"ipt>");

//This must always be at the very bottom
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.switchDocDomain) {document.domain = cnnDocDomain;}

