var isie = (isie6||isie7);
var iswin = BrowserDetect.OS=='Windows'?true:false;
var isnn = BrowserDetect.browser=='Netscape'?true:false;

function getAjaxContent(url,tar)
{
	var aj = new Ajax.Request(url,
		{
		onSuccess:function(t){
			Element.update(tar,t.responseText);handleTabClick(o,'ajax_2','tabs_2'); 
			var id = url.split(',')[2];
		},
		onFailure:function(t){
			Element.update(tar,'<strong>Data Not Available: '+t.statusText+'</strong>');
		},
		evalScripts:true,
		asynchronous:true,
		method:'get'
		}
	);
	//alert(aj.transport.readyState);
}

function getObjContent(url,tar)
{
	$(tar).src=url;
	}

if (lastShow==null) {
	var lastShow = 0;
}

var json;

function getShowSchedContent()
{
	if (isnn) {window.json = {"shows":[{}]};return;}
	var url = '/comp/showPromo.inc';
	var aj = new Ajax.Request(url,
		{
		onSuccess:function(t){
			json = eval('('+t.responseText+')');
			var x = window.lastShow;
			var show = json.shows[x];
			var html = '';
				html += '<div><strong><a id="show_name" href="'+show.showpath+'">'+show.showname+'</a></strong></div>';
				html += '<p>'+show.showdesc+' ('+show.showtime+')</p>';
			Element.update('show_sched_content',html);
			window.lastShow=(window.lastShow==json.shows.length-1)?0:window.lastShow+1;
			window.json=json;
		},
		onFailure:function(t){
			if (json != "") {
				json = eval('('+json+')');
				var x = window.lastShow;
				var show = json.shows[x];
				var html = '';
					html += '<div><strong><a id="show_name" href="'+show.showpath+'">'+show.showname+'</a></strong></div>';
					html += '<p>'+show.showdesc+' ('+show.showtime+')</p>';
				Element.update('show_sched_content',html);
				window.lastShow=(window.lastShow==json.shows.length-1)?0:window.lastShow+1;
				window.json=json;
			} else {
				var html = '<div style="float:left;"><strong>Data Not Available: '+t.statusText+'</strong></div>';
				Element.update('show_sched_content',html);
				window.json=null;
			}
		},
		evalScripts:true,
		asynchronous:true,
		method:'get'
		}
	);
}

function updateShowSched() {
 	if (window.json==null) {
		getShowSchedContent();
	} else {
		var x = window.lastShow;
		var show = window.json.shows[x];
		var html = '';
			html += '<div><strong><a id="show_name" href="'+show.showpath+'">'+show.showname+'</a></strong></div>';
			html += '<p>'+show.showdesc+' ('+show.showtime+')</p>';
		Element.update('show_sched_content',html);
		window.lastShow=(window.lastShow==window.json.shows.length-1)?0:window.lastShow+1;
	}
}

function handleTabClick(o,t,b){
	expandContent(o,b);
	//getAjaxContent(o.href,t);
	getObjContent(o.href,t);
}

var rs = {
	foot_tabs_a : function(t){
			var target = 'ajax_2';
			var tabs   = 'tabs_2';
			handleTabClick(t,target,tabs);
			return false;
	},
	console_tabs_a : function(t){
			var tabs = 'tabs_1';
			var e = getParent(getParent(t)).getElementsByTagName('LI').length;
			var id = t.id.substring(5);
			Element.show('tab_content_'+id);
			while (e) {
				if (e!=id) {
					Element.hide('tab_content_'+e);
				}
				e--;
			}
			expandContent(t,tabs);
			return false;
	},
	button : function(t){
			getParent(getParent(t)).submit();
			return false;
	},
	button_a : function(t){
			getParent(getParent(getParent(t))).submit();
			return false;
	},
 button_s : function(t){
			if (trim($('sponsor_searchinput1').value)=='') {
				alert('Please enter search terms');
			} else {
				if (getParent(getParent(t)).target=="win_live") {
					var win=window.open('','win_live'); 
				}
				getParent(getParent(t)).submit();
			}
			return false;
	},
	poll_vote : function(t){
			var ans = getParent(getParent(t)).getElementsByTagName('input');
			var i = ans.length;
			var x = false;
			while (i-->0) {
				if (ans[i].name=='answer'&&ans[i].checked==true) { x=true; }
			}
			if (!x) {
				alert("You must vote to submit this poll.");
			} else {
				var pp=window.open('about:blank','pp','width=550,height=400,top=100,left=100');
				getParent(getParent(t)).submit();
			}
			return false;
	},
	button_view : function(t){
			var p = t.title.split('_')[0];
			var f = t.title.split('_')[1];
			var pp = pop('http://www2.foxnews.com/polls/poll_results/bg_results_'+f+'.jpg__basic_'+p+'.htm','pp',550,400,'no','no');
			pp.focus();
			return false;
	},
	next : function(t){
			var id = t.id;
			moveNext(id.substring(5),'feature',10);
			return false;
	},
	prev : function(t){
			var id = t.id;
			movePrev(id.substring(5),'feature',10);
			return false;
	},
	mkp_a : function(t){
			$('mkt').src=t.href;
			var mkts = $A($$('#marketplace ul li a'));
			mkts.each (function(m) {
				m.className='';
			});
			t.className='current';
			return false;
	},
	mkp_ad_over : function(t){
			t.className='ad selected';
	},
	mkp_ad_out : function(t){
			t.className='ad';
	},
	tips_form_button : function(t){
			if (trim($('tipText').value)=='') {
				alert('News tips may not be blank!');
			} else {
				$('hSubject').value = $('tipText').value;
				var newsTip=window.open('','newsTip','width=350,height=250,status=no,resizable=no,scrollbars=no');
				getParent(getParent(t)).submit();
			}
			return false;
	}

};

var MyNews = {
	WhatIsThis : function(){
			var newsTip=window.open('http://www.foxnews.com/story/0,2933,213890,00.html','MyNews','');
			return false;
	},
	PrivacyPolicy : function(){
			var newsTip=window.open('/other/privacy.html','MyNews','');
			return false;
	},
	Register : function(){
			var newsTip=window.open('http://www3.foxnews.com/pluck/regform.asp','MyNews','width=380,height=250,status=no,resizable=no,scrollbars=no');
			return false;
	},
	Forgot : function(){
			var newsTip=window.open('http://www3.foxnews.com/pluck/getPass.asp','MyNews','width=400,height=250,status=no,resizable=no,scrollbars=no');
			return false;
	},
	Login : function(){
	    if($("plckUserName").value == '' && $("plckPassword").value == '') {
	        alert("You must provide a Username and Password");
	        return false;
	    }
	    if($("plckUserName").value == '') {
	        alert("You must provide a Username");
	        return false;
	    }
	
	    if($("plckPassword").value == '') {
	        alert("You must provide a Password");
	        return false;
	    }
		$("frmLogin").submit();
	},
	Logout : function(){
			location.href="http://www3.foxnews.com/pluck/logout.asp";
			return false;
	}
};

var rw = {
	myWeather : function(){
			if (local_weather()) $("weatherForm").submit();
	}
};
var mktplace_ids = {
	'3':{'0':[3,5]},
	'4':{'0':[0,4],'267':[0]}
}

var ranNum = new String (Math.random());
ranNum = ranNum.substring (2, 11);

var onload_shell = function() {
	renderWeather();
	if (location.search == "?auth=1") { alert("Either your Username or Password are incorrect"); }
	 var du = $('logo_txt');
	 
	if ( du != null ) {
		if (secTimeStamp != "")du.appendChild(document.createTextNode("Updated "+getUpdatedTime(secTimeStamp)));
	}
	 var els,kdz,kdw,lnx,sc;

	 els = $A(document.getElementsByClassName('feature_content','*'));
	els.each (function(el) {
		kdz = el.getElementsByTagName("li");
		if (isie) {
			   kdw = Math.ceil(parseFloat(getElementStyle(kdz[0],'width')));
			kdm = Math.ceil(parseFloat(getElementStyle(kdz[0],'margin-left')))+Math.ceil(parseFloat(getElementStyle(kdz[0],'margin-right')));
			kdz = kdz.length;
			
			 el.style.width = ((kdz*(kdw+kdm))+(2*kdz))+'px';
			  } else {
			kdw = parseInt(getElementStyle(kdz[0],'width'))+parseInt(getElementStyle(kdz[0],'margin-left'))+parseInt(getElementStyle(kdz[0],'margin-right'));
			 kdz = kdz.length;
			el.style.width = ((1/11)*((kdz*kdw)+kdz))+'em';
			 }
	});

	 sc = $A(document.getElementsByClassName('scroll_count','*'));
	sc.each (function(counter) {
	
		var cs=counter.id.split("_");
		var o=$(cs[0]+'_content_'+cs[2]);
		updateCount(counter.id,1,Math.floor(o.offsetWidth/speed),"/");
	});

	    
	
	  var mkts = [];
	var mnmk = [];
	var new_mkt_id;
	var mktls = $A($$('#marketplace ul li a'));
	
	var mkt_len = mktls.length;



	if (mkt_len>0) {
		for (var mktid=0;mktid<mktls.length;mktid++){
			new_mkt_id = mktls[mktid].href.split(',')[2];
			mkts[new_mkt_id] = mktls[mktid];
			 mnmk[mnmk.length] = new_mkt_id;
		}
		var mkt  = 0;
		m_sec_id = (section_id || "0");
		m_sub_id = (subsection_id || "0");
		if (mktplace_ids[m_sec_id]) {
			if (mktplace_ids[m_sec_id][m_sub_id]) {
				var mkta = mktplace_ids[m_sec_id][m_sub_id];
			} else {
				var mkta = mktplace_ids[m_sec_id][0];
			}
			mkt = mkta[Math.floor(Math.random()*mkta.length)];
			mkt = mkta[Math.floor(Math.random()*mkta.length)];
		} else {
			mkt = mnmk[Math.floor(Math.random()*mnmk.length)] }
	    if(mkts[mkt]!=null){
			mkts[mkt].className='current';
			$('mkt').src=mkts[mkt];
		}
//		mkts[mkt].className='current';
//		$('mkt').src=mkts[mkt];
	}
	    entertainmentBlog();

	   
	jQuery.ad.init({channel: pdata.breadcrumb, ptype: pdata.page_type, ctype: pdata.channel_type, pageid: pdata.page_id, categories: pdata.categories}, "server");
	};

Event.observe(window,'load',function(){onload_shell();try{loadSponsor();}catch(e){}},false);


//weather

function resetWeatherData() {

	p = '; domain=foxnews.com; path=/; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	c = 'weatherloc='+p;
	document.cookie = c;

	c = 'weatherdata='+p;
	document.cookie = c;
	renderWeather();
}

function clearDefault(el,default_value) {
  if (el.value==default_value) {
  	el.value = "";
  }
}

function updateWeatherData() 
{
	var z = getCookieValue('weatherloc');
	var d = getCookieValue('weatherdata');
	if (z&&!d) {
		var wif = document.createElement('script');		
		wif.setAttribute("type", "text/javascript");
		wif.setAttribute('src', "http://www2.foxnews.com/weather/set_weather_js.asp?loc_id=" + getWeatherLocation(z).loc_id);
		return wif;
	} else if (!z||!d) {
		var wfo, wfs, win, win2, wsb, wlp, wlk, wul;
		wfo = document.createElement('form');
		wfo.setAttribute('action','http://www2.foxnews.com/weather/get_weather.asp?ref=root');  wfo.setAttribute('method','post');
		wfo.setAttribute('id','weather-form');
		wfs = document.createElement('fieldset');
		win = document.createElement('input');
		win.setAttribute('name','zip');
		 win.setAttribute('value', 'Enter your zip code');
		 win.onclick = function() { clearDefault(this, 'Enter your zip code'); }
		 win.style.width = '10em';
		win2 = document.createElement('input');
		win2.setAttribute('type','hidden');
		win2.setAttribute('name','source');
		win2.setAttribute('value','root');
	 win2 = document.createElement('input');
		win2.setAttribute('type','hidden');
		win2.setAttribute('name','referer');
		win2.setAttribute('value',escape(document.location));
	 if (z) {
			win.setAttribute('value',getWeatherLocation(z).zip);
		}
		wsb = document.createElement('a');
		wsb.className = 'button no_spon';
		wsb.setAttribute('href','#');
		wsb.onclick = function(){if(win.value==''){alert('Please enter your zip code');return false;}else{document.getElementById('weather-form').submit();}}; 
//		wsb.appendChild(document.createTextNode('Get Weather'));
//		wfo.appendChild(document.createTextNode('Enter your zip code:'));
		wfs.appendChild(win);
		wfs.appendChild(win2);
		wfs.appendChild(wsb);
		wfo.appendChild(wfs);

/*
		wlp = document.createElement("p");
		wlp.className = 'note';
		wlk = document.createElement("a");
		wlk.setAttribute("href","http://www2.foxnews.com/weather/weather_personal.asp");

		wul = document.createElement("span");
		wul.style.textDecoration="underline";
		wul.appendChild(document.createTextNode("Click Here"));
		wlk.appendChild(document.createTextNode("Don't know your zip code? "));
		wlk.appendChild(wul);
		wlp.appendChild(wlk);
		wfo.appendChild(wlp);
*/
		return wfo;
	}

	var wul, wli, wh2, wdf, wdi, wdv, whi, wlo, wpa, i, day, d, h, l, w;
	wul = document.createElement('ul');
	
	var wd = eval('('+unescape(d)+')');
	days = wd.days; 
	
 for (i=0;i<1;i++) {	
		day = days[i]
		d = i==0?"TODAY":"TOMORROW";
		wli = document.createElement('li');

		var wWeatherLink = document.createElement('a');
		  wWeatherLink.setAttribute('href', 'http://www2.foxnews.com/weather/weather_city.asp?zip='+getWeatherLocation(z).zip);

		wdi = document.createElement('img');
		wdi.setAttribute('src','http://www.foxnews.com/i/weather/'+day.image+'.gif');
		wdi.className = 'forecast';

		wWeatherLink.appendChild(wdi);
		
		wh2 = document.createElement('h2');
		wh2.appendChild(document.createTextNode(d));

		wpa = document.createElement('p');		
		wpa.className = 'hi'; 
//		wpa.appendChild(document.createTextNode(day.forecast.replace(/\+/g, " ")));
		wpa.appendChild(document.createTextNode(day.hi));
		wpa.appendChild(document.createTextNode(String.fromCharCode(176)));

		wlo = document.createElement('span');
		wlo.className = 'lo';
		wlo.appendChild(document.createTextNode(day.low));
		wlo.appendChild(document.createTextNode(String.fromCharCode(176)));
		
		wpa.appendChild(wlo);
		
		wdesc = document.createElement('p');
		wdesc.className="description";
		   wdesclink = document.createElement('a');
		wdesclink.setAttribute('href', 'http://www2.foxnews.com/weather/weather_city.asp?zip='+getWeatherLocation(z).zip);
		wdesclink.appendChild(document.createTextNode("10 Day Forecast"));
		wdesc.appendChild(wdesclink);

		wli.appendChild(wWeatherLink);
		wli.appendChild(wh2);
		wli.appendChild(wpa);
		wli.appendChild(wdesc);
		wul.appendChild(wli);
	}
	return wul;
	}

function getWeatherLocation(z) {
	var lo = eval('('+unescape(z).replace(/\+/g, " ")+')');
	return lo.location[0];
}

function addWeatherLinks() {
	var z = getCookieValue('weatherloc');
	var d = getCookieValue('weatherdata');

	if (d&&z) {
		var lo = getWeatherLocation(z);
		var st = '<p style="width:240px; text-align:right;"><a class="action" href="http://www2.foxnews.com/weather/weather_city.asp?zip='+lo.zip+'">'+ lo.city+'</a>';
		if (window.location!='http://www2.foxnews.com/weather/weather_personal.asp') { st += '&nbsp;<a style="color:#0000FF" class="action" href="#" onclick="resetWeatherData();return false;">(change)</a>'; }
		st += '</p>';
		return st;
	}
	return '';
}

var thirty_days = (30*24);
var thirty_mins = (30/60);
var one_minute  = (1/60);

var weather_zipcode_cookie = new Cookie(document,"weatherloc",thirty_days,'','foxnews.com');
var weather_data_cookie = new Cookie(document,"weatherdata",1,'','foxnews.com');

function renderBiz() {
	if (!window.indexdata) {
		setTimeout(renderBiz,500);
	} else {
		  }
}

 function renderWeather() {
	//Element.update('weather_header','<h1 class="compact first">My Weather</h1>');

	var weather_links = addWeatherLinks();
	if (weather_links) { 
		document.getElementById('weather_header').className = 'fore';
	} else {
		document.getElementById('weather_header').className = '';
	}
	document.getElementById('weather_header').innerHTML=weather_links;
	
	//$('weather').appendChild(updateWeatherData());
	document.getElementById('weather_header').appendChild(updateWeatherData());
	
	 //new Insertion.Top('weather_header', addWeatherLinks());
}

function entertainmentBlog(){
  jQuery('#entertainment-blog ul li b a').each(function(){
  	var $obj = jQuery(this);
  	var textToAdd = '<span class="raquo">&raquo;</span>';
  	var textBefore = $obj.text();
  	$obj.html($obj.text()+' '+textToAdd);
  });
} 