document.cnnSwim10 = new Array();

function cnnPageOnload() {
	cnnStartList();
}

/****/
/* OMNITURE */
/****/

	var cnn_omnitureData = new Array();
	cnn_omnitureData = {
		path: cnn_omnitureGetPath(),
		server: document.domain,
		section: '2010 Swimsuit',
		pageType: null,
		branding: null,
		referrer: cnn_omnitureGetReferrer(),
		pageName: null
	}

	function cnn_omnitureGetPath() {
		// return the path of the story complete with parameters
		var retValue = document.location.pathname;
		retValue = retValue.replace( /\/\/+/, "/" ); // remove multiple slashes
		if( retValue.charAt( retValue.length - 1 ) == "/" ) retValue += "index.html"; // make sure there's always a filename
		retValue += document.location.search;
		return retValue;
	}

	function cnn_omnitureGetReferrer() {
		// return a proper string for referrer if one exists
		var retValue = '';
		var myQuery = queryString( 'eref' );
		var myQuery2 = queryString( 'xid' );
		if( myQuery != "false" ) {
			retValue += "from " + myQuery;
			if( myQuery2 != "false" ) { retValue += ", xid " + myQuery2; }
			retValue += " - " + cnn_omnitureGetPath();
			retValue = retValue.replace( 'eref=' + myQuery, "" ); // remove our eref
			retValue = retValue.replace( 'xid=' + myQuery2, "" ); // remove our xid
			retValue = retValue.replace( /\?&$/, "" ); // remove ending question mark cause there are no more parameters
		} else if( myQuery2 != "false" ) {
			retValue += "xid " + myQuery2 + " - " + cnn_omnitureGetPath();
			retValue = retValue.replace( 'xid=' + myQuery2, "" ); // remove our xid
			retValue = retValue.replace( /\?$/, "" ); // remove ending question mark cause there are no more parameters
		}
		if( retValue == '' ) retValue = null;
		return retValue;
	}

	function pageQuery( q ) {
		if( q.length > 1 ) this.q = q.substring( 1, q.length );
		else this.q = null;
		this.keyValuePairs = new Array();
		if( q ) {
			for( var i = 0; i < this.q.split( "&" ).length; i++ ) {
				this.keyValuePairs[i] = this.q.split( "&" )[i];
			}
		}
		this.getKeyValuePairs = function() { return this.keyValuePairs; }
		this.getValue = function( s ) {
			for( var j = 0; j < this.keyValuePairs.length; j++ ) {
				if( this.keyValuePairs[j].split( "=" )[0] == s )
				return this.keyValuePairs[j].split( "=" )[1];
			}
			return false;
		}
		this.getParameters = function() {
			var a = new Array( this.getLength() );
			for( var j = 0; j < this.keyValuePairs.length; j++ ) {
				a[j] = this.keyValuePairs[j].split( "=" )[0];
			}
			return a;
		}
		this.getLength = function() { return this.keyValuePairs.length; } 
	}

	function queryString( key ){
		var page = new pageQuery( window.location.search ); 
		return unescape( page.getValue( key ) ); 
	}

	function writeData() {
		document.write( '<div class="cnnOmniture"><a name="cnnOmniture"></a>' );
		document.write( '<table border="0" cellpadding="0" cellspacing="0">' );
		document.write( '<tr><th colspan="2">Omniture Values</th></tr>' );
		for( key in cnn_omnitureData ) {
			document.write( '<tr><td>' + key + '</td><td>' + cnn_omnitureData[key] + '</td></tr>' );
		}
		document.write( '</table></div>' );
	}

/****/
/* ADSPACES */
/****/

	function cnnad_determineAd( filename ) {
		var cnnad_path = 'swimsuit';
		if( document.cnnSwim10.section ) {
			if( document.cnnSwim10.section == "models" ) {
				if( document.cnnSwim10.pagetype ) {
					if( ( document.cnnSwim10.pagetype == "front" ) || ( document.cnnSwim10.pagetype == "index" ) ) {
						cnnad_path += "/models";
					}
				}
			} else if( document.cnnSwim10.section == "main" ) cnnad_path += "/main";
		}
		var retValue = '/si_adspaces/3.0/' + cnnad_path + '/' + filename + '.js';
		if( allCookies['cnnad_solbright'] == "set" ) {
			document.write( '<div class="cnnSiteDebug" style="font-weight:bold;">' + retValue + '</div>' );
		}
		document.write( '<scr' + 'ipt type="text/javascript" src="' + retValue + '"></scr' + 'ipt>' );
	}

/****/
/* ADCODE */
/****/

	/* 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+=("rsseg"+"="+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 cnnCreateAd( width, height ) {
		// if this is a 260px or 1px wide ad, only make the call for the special models.  for any other ad, continue as normal
		// document.write( '<div class="cnnAdHolder" style="height:' + height + 'px;line-height:' + height + 'px;width:' + width + 'px;">' + width + 'x' + height + '</div>' );
		if( width == 260 ) {
			if( document.cnnSwim10.subsection && ( ( document.cnnSwim10.subsection == "bar-refaeli" ) || ( document.cnnSwim10.subsection == "brooklyn-decker" ) || ( document.cnnSwim10.subsection == "esti-ginzburg" ) || ( document.cnnSwim10.subsection == "buy" ) ) ) {
				cnnCreateAnAd( width, height );
			} else if( document.cnnSwim10.section && ( ( document.cnnSwim10.section == "oneshot" ) || ( document.cnnSwim10.section == "clock" ) || ( document.cnnSwim10.section == "winter" ) || ( document.cnnSwim10.section == "bracket" ) ) ) {
				cnnCreateAnAd( width, height );
			} else {
			}
		} else if( width == 1 ) {
			if( document.cnnSwim10.pagetype && ( document.cnnSwim10.pagetype != "player" ) ) {
				if( document.cnnSwim10.subsection && ( ( document.cnnSwim10.subsection == "bar-refaeli" ) || ( document.cnnSwim10.subsection == "brooklyn-decker" ) || ( document.cnnSwim10.subsection == "esti-ginzburg" ) ) ) {
					cnnCreateAnAd( width, height );
				} else if( document.cnnSwim10.section && ( ( document.cnnSwim10.section == "bracket" ) || ( document.cnnSwim10.section == "oneshot" ) ) ) {
					cnnCreateAnAd( width, height );
				} else {
				}
			}
		} else {
			cnnCreateAnAd( width, height );
		}
	}

	function cnnCreateAnAd( width, height ) {
		var retValue = "http://ad.doubleclick.net/adj/3475.si/" + cnnAdGetDart() + "/;";
		retValue += cnnAdGetParams(); // append page specific params
		retValue += cnnAdGetFolders(); // append the folders as path variables
		retValue += "file=" + ( document.cnnSwim10.filename ).replace( /\./, "_" ) + ";" // append filename
		retValue += "dcove=d;" // append dcove
		retValue += segQS // append revenue science
		retValue += quantSegs // append quantcast
		retValue += "sz=" + width + "x" + height; if( width == 988 ) retValue += ",728x90"; else if( ( width == 300 ) && ( height == 600 ) ) retValue += ",300x250"; retValue += ";"; // append sizes
		retValue += ""; document.cnnAdInterstitial = ( document.cnnAdInterstitial == undefined ? "ist" : "" ); if( document.cnnAdInterstitial != "" ) retValue += 'dcopt=' + document.cnnAdInterstitial + ';'; // append dcopt on first ad request
		if( ( document.cnnSwim10.section == "video" ) && ( document.cnnSwim10.section != "index.html" ) ) {
			document.cnnAdTile = (document.cnnAdTile||1) + 1; // account for the preroll as tile 1
		} else {
			document.cnnAdTile = (document.cnnAdTile||0) + 1; // otherwise start with 0
		}
		retValue += ""; retValue += "tile=" + document.cnnAdTile + ";"; // append tile which increments on each ad request
		retValue += ""; document.cnnAdRandom = document.cnnAdRandom || Math.ceil(1+1E12*Math.random()); retValue += "ord=" + document.cnnAdRandom + "?"; // append random number (always last)
		if( allCookies['cnnad_solbright'] == "set" ) {
			document.write( '<div class="cnnSiteDebug">' + cnnAdWriteDebug( retValue ) + '</div>' );
		}
		document.write( '<scr'+'ipt language="JavaScript1.1" src="' + retValue + '"></scr'+'ipt>' );
	}

	function cnnCreateVideoAd( file, dc_seed ) {
		var retValue = "http://ad.doubleclick.net/adj/3475.si/video.swimsuit/;spt=swimsuit;file=" + file +";dcove=d;sz=300x600;tile=3;dc_seed=" + dc_seed;
		document.write( '<scr'+'ipt language="JavaScript1.1" src="' + retValue + '"></scr'+'ipt>' );
	}

	function cnnAdGetDart() {
		var retValue = "swimsuit";
		if( document.cnnSwim10.section ) {
			if( document.cnnSwim10.section == "models" ) retValue += "." + document.cnnSwim10.section;
			else if( document.cnnSwim10.section == "main" ) retValue += "/" + document.cnnSwim10.section;
			else if( document.cnnSwim10.section == "painting" ) retValue += ".bodypainting";
		}
		return retValue;
	}

	function cnnAdGetParams() {
		var retValue = "spt=swimsuit;";
		if( document.cnnSwim10.subsection ) { retValue += "kw=" + document.cnnSwim10.subsection + ";"; }
		if( document.cnnSwim10.pagetype ) { retValue += "ptyp=" + document.cnnSwim10.pagetype + ";"; }
		return retValue;
	}

	function cnnAdGetFolders() {
		var retValue = "";
		if( document.cnnSwim10.section ) {
			if( document.cnnSwim10.section != "" ) {
				retValue += "path=" + document.cnnSwim10.section + ";";
			}
		}
		if( document.cnnSwim10.subsection ) {
			if( document.cnnSwim10.subsection != "" ) {
				retValue += "path=" + document.cnnSwim10.subsection + ";";
			}
		}
		return retValue;
	}

	function cnn10Swim_isRookie() {
		var retValue = false;
		if( document.cnnSwim10.subsection ) {
			switch( document.cnnSwim10.subsection ) {
				case 'sonia-dara': retValue = true; break;
				case 'zoe-duchesne': retValue = true; break;
				case 'genevieve-morton': retValue = true; break;
				case 'julie-ordon': retValue = true; break;
				case 'dominique-piek': retValue = true; break;
				case 'christine-tiegen': retValue = true; break;
				default: break;
			}
		}
		return retValue;
	}

	function cnnAdWriteDebug( input ) {
		return ( ( input.replace( /;/g, "; " ) ).replace( /\//g, " / " ) ).replace( /\./g, ". " );
	}

	function cnnAdWriteSpecialAd() {
		if( document.cnnSwim10.subsection && ( document.cnnSwim10.subsection == "brooklyn-decker" ) ) {
			document.write( '<li class="cnnItem3"><div id="cnnAdSpecialAd"></div></li>' );
			var cnnAdSpecialAd_params = {
				quality: "high",
				scale: "noscale",
				wmode: "transparent",
				bgcolor: "#000000",
				allowfullscreen: "true"
			};
			var cnnAdSpecialAd_flashvars = {
				isIE: "0",
				flashMedia: "full/images/"
			};
			var cnnAdSpecialAd_attributes = {
				id: "cnnAdSpecialAd",
				name: "cnnAdSpecialAd"
			};
			swfobject.embedSWF( "http://i.cdn.turner.com/si/2010_swimsuit/models/brooklyn-decker/full/brooklyn_fullScreenGallery.swf", "cnnAdSpecialAd", "240", "38", "9.0.124", "http://i.cdn.turner.com/si/.e/swf/4.1/global/expressInstall.swf", cnnAdSpecialAd_flashvars, cnnAdSpecialAd_params, cnnAdSpecialAd_attributes );
		}
	}

/****/
/* SPONSORED LINKS */
/****/

	function cnnCreateSL() {
		document.write( '<scr'+'ipt type="text/javascript">adsonar_placementId=1489951;adsonar_pid=769767;adsonar_ps=-1;adsonar_zw=800;adsonar_zh=108;adsonar_jv=\'ads.tw.adsonar.com\';</scr'+'ipt><scr'+'ipt language="JavaScript" src="http://js.adsonar.com/js/tw_cnn_adsonar.js"></scr'+'ipt>' );
	}


/****/
/* GALLERY */
/****/

	function cnnCreateWatermark() {
		// grab the anchor tag of id cnnWatermark, grab the alt tag from the image inside said anchor, and append the code for the overlay (a blank pixel with the same alt tag as the real photo to mimic the hover state) to the anchor's innerHTML.
		try {
			var title = document.getElementById("cnnWatermark").getElementsByTagName("IMG")[0].alt;
			document.getElementById("cnnWatermark").innerHTML += '<img src="http://i.cdn.turner.com/si/.e/img/4.0/global/pixels/blank_pixel.gif" border="0" alt="' + title + '" title="' + title + '" class="cnnImageWatermark"/>';
		} catch( e ) {
			// do nothing
		}
	}

	var siPhotoGallery = function() {
		var that = {};
		var bodyId = '#sipg';
		/**
		 * Initializes the photo gallery page
		 */
		that.init = function(urlPrev, urlNext) {
			// make sure dom has fully loaded before performing
			$(document).ready(function(){
				cnnCreateWatermark();
				// initialize image nav arrow functionality
				initPhotoArrows(urlPrev, urlNext);
			});
		};
		/**
		 * Initializes left/right arrow nav over large photo
		 */
		initPhotoArrows = function(urlPrev, urlNext) {
			$('#cnnImage').arrowNav({prevUrl:urlPrev,nextUrl:urlNext,showArrows:false,arrowHeight:107,arrowWidth:35});
		};
		return that;
	};

/****/
/* NAVBAR */
/****/

	function cnnStartList() {
		if (document.all&&document.getElementById) {
			navRoot = document.getElementById("cnnSwim10Nav");
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" cnnOver";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" cnnOver", "");
					}
				}
			}
		}
	}


/****/
/* SHARE */
/****/

	var cnnShare = {
		"t" : document.title, // title
		"t2" : "", // title, shorter
		"l" : document.location.href, //link
		"m" : "", //media (news, video, image)
		"d" : "", //description
		"c1" : "", // digg category
		"rss":"http://rss.cnn.com/rss/si_topstories.rss"
	}
	cnnShare.o = function(t, add) { 
		out = this[t];
		// if add is present, append as a query parameter
		if (add != null) {
			out = out.replace(/\#/,'');
			if (out.indexOf('?') > 0) out = out + '&' + add;
			else out = out + '?' + add;
		}
		return encodeURIComponent(out); 
	}

	cnnShare.popup = function(url, opt) { 
		if (opt) { window.open(url, 'si_bookmark', opt);
		} else { window.open(url, 'si_bookmark'); }
	}

	cnnShare.init = function() {
		if (cnnShare.t2) { return; }
		// Grab Short Title
		var tmp = document.getElementsByTagName("h1");
		if (tmp[0]) { cnnShare.t2 = tmp[0].innerHTML;  } else { cnnShare.t2 = cnnShare.t; }
		// Grab Page Description
		tmp = document.getElementsByTagName("meta");
		for (var i=0; i<tmp.length; i++){
			if (tmp[i].name.toLowerCase() == 'description') { cnnShare.d = tmp[i].getAttribute('content'); }
		}
		// Grab RSS
		tmp = document.getElementsByTagName("link");
		for (var i=0; i<tmp.length; i++){
			if (tmp[i].getAttribute('type') == 'application/rss+xml') { cnnShare.rss = tmp[i].href; }
		}
		// WRITER RSS
		if (document.location.href.indexOf('/writers/') > 0) {
			cnnShare.rss = document.location.href.replace(/^.*\/writers\//i,'').replace(/\/.*$/,'');
			cnnShare.rss="http://rss.cnn.com/rss/si_"+cnnShare.rss+".rss";
		}
	}

	cnnShare.addRef = function(add) {
		link = this.l.replace(/\#/,'');
		if (link.indexOf('?') > 0) { link = link + '&' + add; }
		else { link = link + '?' + add; }
		return link;
	}

	cnnShare.submit = function(t) {
		var url = '';
		var media = 'news';
		// FACEBOOK
		if (t == 'facebook') {
			this.popup('http://www.facebook.com/sharer.php?u='+cnnShare.o('l','eref=shareFB')+'&t='+cnnShare.o('t2'), 'width=500,height=400');
		}
		if (t == 'digg') {
			this.popup('http://digg.com/submit?title='+this.o('t2')+'&url='+this.o('l','eref=shareDigg')+'&media='+media+'&bodytext='+this.o('d'), 'width=900,height=600,scrollbars=yes');
		}
		if (t == 'twitter') {
			this.popup('http://www.sikids.com/tweet/?t='+this.o('t2')+'&l='+this.o('l'));
		}
		if (t == 'rss') {
			document.location = cnnShare.rss;
		}
	}
	// AddThis Params
	var addthis_pub   = 'sicom';
	var addthis_url = cnnShare.addRef('eref=shareAdd');
	var addthis_brand = 'SI';
	var addthis_logo  = 'http://s7.addthis.com/custom/si/si_com.gif';
	var addthis_options = 'stumbleupon,delicious,google,reddit,myspace,more';
	var addthis_exclude = 'facebook,twitter,digg,email,live,tehnorati';
	// Yahoo Buzz
	var yahooBuzzArticleHeadline = cnnShare.t;
	var yahooBuzzArticleSummary = cnnShare.d;
	var yahooBuzzArticleCategory = "sports";
	var yahooBuzzArticleType = "text";
	var yahooBuzzArticleId = cnnShare.l;


/****/
/* COOKIES */
/****/

	function CNN_getCookies() {
		var hash = new Array;
		if ( document.cookie ) {
			var cookies = document.cookie.split( '; ' );
			for ( var i = 0; i < cookies.length; i++ ) {
				var namevaluePairs = cookies[i].split( '=' );
				hash[namevaluePairs[0]] = unescape( namevaluePairs[1] ) || null;
			}
		}
		return hash;
	}

	function CNN_parseCookieData( cookieDataString ) {
		var cookieValues = new Object();
		var separatePairs = cookieDataString.split( '&' );
		for ( var i = 0; i < separatePairs.length; i++  ) {
			var separateValues = separatePairs[i].split( ':' );
			cookieValues[separateValues[0]] = separateValues[1] || null;
		}
		return cookieValues;
	}

	function CNN_setCookie( name, value, hours, path, domain, secure ) {
			var numHours = 0;

			if ( hours) {
				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.

	}


	function CNN_killCookie( name, path, domain ) {
		var allCookies = CNN_getCookies();

		var theValue = allCookies[ name ] || null; // 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
		}
	}

	var allCookies = CNN_getCookies();

