
var browser="";
var playerChecking=0;
var checker;
var playerlab;
var playerSwf;
var divAds
var divPlayer;

var WIDTH;
var HEIGHT;


	

function detectBrowser(){
	var agent=navigator.userAgent;
	if(agent.match(/Firefox.(\d.\d)/i)!=null){
		browser="FIREFOX";
	}else if(agent.match(/MSIE.(\d.\d)/i)!=null){
		browser="IE";
	}else if(agent.match(/Opera.(\d.\d)/i)!=null){
		browser="OPERA";
	}else if(agent.match(/Safari.(\d)/i)!=null){
		browser="SAFARI";
	}
}


	function initAds(){
			detectBrowser();
			
			divPlayer = document.getElementById(playerLab);
			WIDTH = divPlayer.style.width;
			HEIGHT = divPlayer.style.height;
			var TOP = divPlayer.offsetTop;
			var LEFT = divPlayer.offsetLeft;
			
			
			if(browser=="IE"){
				divAds = document.createElement('<div id="smt" style="cursor:pointer;z-index:2; border:none; top:' + TOP + 'px;left:' + LEFT + 'px;width:' + WIDTH + ';height:' + HEIGHT + ';position:absolute; z-index:2000;" onClick="makeIframe();"></div>');
			} else {
				
				divAds = document.createElement("div");
				divAds.setAttribute("id", "smt");
				divAds.setAttribute("style", 'cursor:pointer;z-index:2000;border:none; top:' + TOP + 'px;left:' + LEFT + 'px;width:' + WIDTH + ';height:' + HEIGHT + ';position:absolute;');
				divAds.setAttribute("onClick", "makeIframe();");
			}
			
			divPlayer.parentNode.appendChild(divAds);
			
			
			
			
			//document.body.appendChild(divAds);
			
			if(browser=="IE"){
				var la = document.getElementById("smt");
				//var la = divPlayer.parentNode.getElementById("smt");
				la.innerHTML="<img src='"+base_url+"/img/smartclip.gif' border='0' style='width:" + WIDTH + ";height:" + HEIGHT + "' />";
			
			}
		}
		
		function makeIframe(){
			if(browser=="IE"){
				var la = document.getElementById("smt");
				//var la = divPlayer.parentNode.getElementById("smt");
				la.innerHTML="";
			
			}
			if(browser=="IE"){
				var publiIframe = document.createElement("<iframe frameborder=\"0\" id=\"publiIframe\" width=\"100%\" height=\"100%\" src=\""+base_url+"smartclip.html\" style=\"top:0px; left:0px; float:none;\">");
			} else {				
				var publiIframe = document.createElement("iframe");
				publiIframe.setAttribute("id", "publiIframe");
				publiIframe.setAttribute("width","100%");
				publiIframe.setAttribute("height","100%");
				publiIframe.setAttribute("src",base_url+"smartclip.html");
				publiIframe.setAttribute("frameborder","0");
				publiIframe.setAttribute("style", "top:0px; left:0px; float:none;");
				
			}
			
			divAds.appendChild(publiIframe);
		}
		
		function endAd(){
			
			
			if(divAds)divPlayer.parentNode.removeChild(divAds);
			if(document.getElementById(playerLab)) $f(playerLab).play();
		}
		
		
		function smartclipInit(player){
			if(player){
				playerLab = player;
				checker = setTimeout("checkPlayer()", 1000);
			} else {
				endAd();
			}
			
		
		}
		
		function checkPlayer(){
			if(document.getElementById(playerLab + "_api")){
				clearTimeout(checker);
				playerSwf = document.getElementById(playerLab + "_api"); 
				initAds();
			} else if(playerChecking<5){
				playerChecking++;
				checker = setTimeout("checkPlayer()", 1000);
			} else {
				clearTimeout(checker);
				endAd();
			}
		
		}
