// site specific javascript

if(!$.browser.safari)
{
	$(document).ready(function(){
		behavior_binder();
	});
}
else
{
	$(window).load(function(){
		behavior_binder();
	});
}


/*
Binds behaviors
** can be re-run whenever there are DOM changes
*/
function behavior_binder(){

	$('.module_title').drawFont();
	$('.exclusive_title').drawFont();
	$('.thegrio_title').drawFont();
	$('form#header_search').submit(function(e){
		if($('input#header_search_input').val()==''){
			alert('Please enter a search term');
			e.preventDefault();
		}
	})
	if(window.create_dl!==undefined && typeof(window.create_dl)==='function'){
		create_dl();
	}
}
function refreshAds(){
	var base="/z.php?a="
	var ads={
		'top_90h':[728,90,'http://ad.doubleclick.net/adj/nbcu.thegrio/thegrio;site=thegrio;!category=thegrio;dcopt=ist;pos=1;tile=1;!category=noexpand;sz=728x90;ord='],
		'companionad':[300,250,'http://ad.doubleclick.net/adj/nbcu.thegrio/thegrio;site=thegrio;!category=thegrio;pos=7;tile=7;!category=noexpand;sz=300x250;ord=']
	}
	var ord=0;
	if(window.genSetRandDARTNumber!==undefined && typeof(window.genSetRandDARTNumber)==='function'){
		genSetRandDARTNumber();
		ord=randDARTNumber;
	}
	else{
		ord=Math.round(Math.random()*1000000000000);
	}
	
	for(var i in ads){
		if(ads.hasOwnProperty(i)){
			var node=document.getElementById(i);
			if(node){
				node.innerHTML='<iframe class="adframe" id="iframe_'+i+'"scrolling="no" frameborder="0" src="'+base+escape(ads[i][2])+'" width="'+ads[i][0]+'" height="'+ads[i][1]+'" allowTransparency="true" marginwidth="0" marginheight="0" margintop="0" marginleft="0"></iframe>';

			}
		}
	}

	if(window.s !== undefined && window.s.t!==undefined && typeof(window.s.t)==='function'){
		s.t();
	}

}


function onOutletEvent(e)
{
if(e.type == "outletInited")
{
// Set the number of target val calls by the ad engine to 0.
var embeddedPlayer = Outlet.getOutletExtension("embeddedPlayer");
if (embeddedPlayer == null) {
alert("Embedded Player not found. Please ensure name matches id in video player config.");
return;
}
var adData = { numberOfAdCalls:0};
embeddedPlayer.updateAdData(adData);
}
}