var CNN_FONT_COOKIE_NAME = "cnnFont";
var CNN_FONT_COOKIE = readCookie( CNN_FONT_COOKIE_NAME ) || null;
//var CNN_CSS_TITLE = CNN_FONT_COOKIE ? CNN_FONT_COOKIE : null;

function setActiveStyleSheet( CNN_CSS_TITLE ) {
	var i, a;
	for( i = 0; ( a = document.getElementsByTagName( "link" )[i] ); i++ ) {
		if( a.getAttribute( "rel" ).indexOf( "style" ) != -1 && a.getAttribute( "title" ) ) {
			a.disabled = true;
			if( a.getAttribute( "title" ) == CNN_CSS_TITLE ) a.disabled = false;
		}
	}
}
function setActiveStyleSheet2( CNN_CSS_TITLE ) {
	setActiveStyleSheet( CNN_CSS_TITLE )
	if( CNN_CSS_TITLE == 'LargeFont' ) {
		createCookie( CNN_FONT_COOKIE_NAME, 'LargeFont', 24*31 );
	} else {
		eraseCookie( CNN_FONT_COOKIE_NAME );
	}
}

/*
function getActiveStyleSheet() {
	var i, a;
	for( i = 0; ( a = document.getElementsByTagName( "link")[i] ); i++ ) {
		if( a.getAttribute( "rel" ).indexOf( "style" ) != -1 && a.getAttribute( "title" ) && !a.disabled ) {
			return a.getAttribute( "title" );
		}
	}
	return null;
}

function cnnCheckFont() {
	if( getActiveStyleSheet() != null ) {
		if( getActiveStyleSheet() != CNN_FONT_COOKIE ) {
			createCookie( CNN_FONT_COOKIE_NAME, getActiveStyleSheet(), 24*31 );
		}
	} else {
		eraseCookie( CNN_FONT_COOKIE_NAME );
	}
}
window.onbeforeunload = cnnCheckFont;
*/
	// DIGG RIGHT RAIL
	function cnnShowDiggs(tab) {
		if ($e('cnnDiggUp') == false) return false;
		var pop = 'active';
		var up = '';
		if (tab == 'up') { pop = ''; up = 'active'; }
		$e('cnnDiggUp').className = $e('cnnDiggUptab').className = up;
		up;
		$e('cnnDiggPop').className = pop;
		$e('cnnDiggPoptab').className = pop;
	}	


	// BOOK MARKS / SHARE LINKS
	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://tweet.si-sandbox.com/?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;
