function readCookie(name) {
	var nameEQ=name+"=",ca=document.cookie.split(';');
	for(var i=0;i<ca.length;i++){
		var c=ca[i];
		while(c.charAt(0)===' '){
			c=c.substring(1,c.length);
		}
		if(c.indexOf(nameEQ)===0){
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}
function aweDoOpen(url){
	if(awePuShown===true){
		return true;
	}
	if(browser!='chrome'){
		var aweWindow=window.open(url,"feederPu","directories=yes,toolbar=yes,status=yes,resizable=yes,scrollbars=yes,menubar=yes,location=yes,height="+screen.height+",width="+screen.width);
		setTimeout(window.focus,400);
	}
	else{
		var aweWindow=window.open(url,"feederPu","scrollbar=yes,toolbar=yes,status=yes,resizable=yes,location=yes,height="+(screen.height-100)+",width="+(screen.width-100));
		setTimeout(window.blur,400);
	}
	if(aweWindow){
		aweWindow.blur();
		awePuShown=true;
	}
	if(browser=='chrome'){
		self.focus();
	}
	return aweWindow;
}
function aweSetCookie(name,value,time){
	var expires=new Date();
	expires.setTime(expires.getTime()+time);
	document.cookie=name+"="+value+"; expires="+expires.toGMTString()+"; path=/";
}
function aweCheckTarget(e){
	if(popunderurl!==false&&readCookie('popundr')===null){
		aweDoOpen(popunderurl);
		aweSetCookie("popundr",1,24*60*60*1000);
	}
}
function aweInitPu(){
	if(document.attachEvent){
		document.attachEvent("onclick",aweCheckTarget);
	}
	else if(document.addEventListener){
		document.addEventListener("click",aweCheckTarget,false);
	}
}
function dmcaContact(){
	var name='nimda',domain='moc.reknubxxx',final=name.split('').reverse().join('')+'@'+domain.split('').reverse().join('');
	window.location.href='mailto:'+final;
}
function bookmark(u,t){
	if(document.all){
		window.external.AddFavorite(u,t);
	}
	else if(window.sidebar){
		window.sidebar.addPanel(t,u,'');
	}
	else{
		alert('please press ctrl-d to add to your bookmarks.');
	}
}
function playerReady(){
	var p=document.getElementById('player');
	p.addModelListener('STATE','handleStateChange');
}
function videoAdvertStatus(i){
	var s=(i=='hide'?'none':'block');
	document.getElementById('videoAdvert').style.display=s;
	document.getElementById('videoOverlay').style.display=s;
}
function setVideoAdvertHeader(t){
	switch(t){
		case 'BUFFERING':
			document.getElementById('videoAdvertHeader').innerHTML='<div id="bufferText">buffering, please wait ...</div><div style="float:right"><a href="javascript:void(0)" onclick="videoAdvertStatus(\'hide\')" onmouseover="showBufferInfo()" onmouseout="di()">X</a></div>';
		break;
		case 'PAUSED':
			document.getElementById('videoAdvertHeader').innerHTML='<div style="float:left">paused</div><div style="float:right"><a href="javascript:void(0)" onclick="playVideo()">resume playing</a> | <a href="javascript:void(0)" onclick="videoAdvertStatus(\'hide\')">X</a></div>';
		break;
		case 'IDLE':
			document.getElementById('videoAdvertHeader').innerHTML='<div style="float:left">brought to you by :</div><div style="float:right"><a href="javascript:void(0)" onclick="playVideo()">replay</a> | <a href="javascript:void(0)" onclick="videoAdvertStatus(\'hide\')">X</a></div>';
		break;
		case 'ERROR':
			document.getElementById('videoAdvertHeader').innerHTML='<div style="float:left"><strong style="color:red">sorry, but this video is not available at this time</strong></div><div style="float:right"><a href="javascript:void(0)" onclick="videoAdvertStatus(\'hide\')">X</a></div>';
		break;
	}
}
function handleStateChange(o){
	if(o.newstate=='BUFFERING'||o.newstate=='PAUSED'||o.newstate=='IDLE'){
		setVideoAdvertHeader(o.newstate);
		videoAdvertStatus('show');
	}
	else if(o.newstate=='PLAYING'){
		videoAdvertStatus('hide');
	}
}
function playVideo(){
	document.getElementById('player').sendEvent('PLAY','true');
}

var browser=(navigator.userAgent.indexOf('PLAYSTATION 3')!=-1?'ps3':navigator.userAgent.indexOf('Chrome')!=-1?'chrome':navigator.userAgent.indexOf('Safari')!=-1?'safari':navigator.userAgent.indexOf('Firefox')!=-1?'firefox':navigator.appName=='Netscape'?'netscape':navigator.appName.indexOf("Microsoft")!=-1?'ie':navigator.userAgent.indexOf("opera")==-1?'opera':false),popunderurl=false,awePuShown=false;

if(browser!='opera'&&browser!='ps3'){
	aweInitPu();
}
