//Sky sports live embed and helper functions script v1.2.21 (last updated 30 April 2009)
var live = {
	
	embed: function(p){
		//error detection
		if(!p.flashversion){p.flashversion=9}
		if(!p.width){p.width=1018}
		if(!p.height){p.height=680}
		if(p.embedlocation){live.e = document.getElementById(p.embedlocation)}
		if(!p.embedlocation){live.e = document.getElementsByTagName('body')[0]}
		if(live.getquery('config')!=undefined){p.config=live.getquery('config')}
		
		//Set global scorecentre variables
		//window.pName = p.name;
		window.skybettab = p.skybettab;
		
		
		//check for flash versions
		var isInstalled = false;
		var version = null;
		if (window.ActiveXObject) {
			var control = null;
				try {
					control = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
					
				} catch (e) {
					version=0
					
		
	    }
		
			if (control) {
		        isInstalled = true;
		        version = control.GetVariable('$version').substring(4);
		        version = version.split(',');
		        version = parseFloat(version[0] + '.' + version[1]);
				
			}

			
	} 
	
	else {
		if(navigator.plugins['Shockwave Flash']){
		    version = navigator.plugins['Shockwave Flash'].description;
			version = version.split('.')[0];
			version = parseInt(version.split('Flash ')[1]);
		}
		
		else{version=0}
		
	}
	
	if (version<p.flashversion){
		document.write("<style type='text/css'>*{padding:0px;margin:0px} .ls-alert{margin:20px;font-family:arial,sans serif;background:#dc5e68;padding:10px} .ls-alert a{color:black}</style>");
		live.e.innerHTML="<p class=ls-alert>You need flash player "+p.flashversion+" or greater to view this content. You can download the latest <a href='http://www.adobe.com/go/getflash' target='blank'>flash player plugin here</a>. Alternatively, try our <a href='http://www.skysports.com/calendar/football/' target='blank'>HMTL scores service here.</a></p>"
	}
		
	if(version>=p.flashversion){
			
			//get deeplink
			var query = p.deeplink;	
			if(window.location.hash && window.location.hash!='#hitboxdebug'){
				query=window.location.hash.split('#')[1];
			
			}
		
			if(query==""){query='home'}
			
			if(live.getquery('id')){query=live.getquery('id')}
			
			
			//create iframe and write swf
			var embedframe = document.createElement("iframe");
			embedframe.setAttribute("name", 'embediframe');
			embedframe.setAttribute("id", 'embediframe');
			embedframe.setAttribute("src", "");
			embedframe.scrolling='no';
			embedframe.frameBorder='0';
			embedframe.allowTransparency="true";

			embedframe.width = "1018px";
			embedframe.height = "680px";
			document.getElementsByTagName('body')[0].innerHTML="";
			document.getElementsByTagName('body')[0].appendChild(embedframe);
			var doc = document.getElementById('embediframe').contentWindow.document;
			doc.open();
			
			//write in styles
			doc.write("<style type='text/css'>*{padding:0px;margin:0px;font-size:100%} object{display:block;} iframe{position:absolute;z-index:2} body,html {background:"+p.bgColor+";height:100%;font-family:arial,sans-serif;} body{font-size:76%} #"+p.embedlocation+"{height:"+p.height+";width:"+p.width+";position:absolute;z-index:1} #ls-leaderboard{top:-2px;left:290px;width:728px;height:90px} #ls-sponsor1{top:490px;left:0px;width:186px;height:190px} </style>");
			
			//write content
			doc.write("<iframe scrolling=no allowTransparency=true frameborder=0 id='ls-leaderboard'></iframe>");
			
			doc.write("<script src=live.js?v="+p.date+"></script><div id=livecontainer><object id='ls-live' type='application/x-shockwave-flash' data='"+p.path+"?v="+p.date+"&config="+p.config+"&deeplink="+query+"' width='"+p.width+"' height='"+p.height+"'><param name='AllowScriptAccess' value='always'><param name='wmode' value='transparent'><param name='movie' value='"+p.path+"?v="+p.date+"&config="+p.config+"&deeplink="+query+"' /><param name='FlashVars' value='browser="+navigator.userAgent+"'><p class=ls-alert>You need flash player to view this content. You can download the latest <a href='http://www.adobe.com/go/getflash' target='blank'>flash player plugin here</a>. Alternatively, try our <a href='http://www.skysports.com/calendar/football/' target='blank'>HMTL scores service here.</a></p></object></div>");
			
			doc.close();
			
			document.write("<style type='text/css'>*{background:"+p.bgColor+"; padding:0px;margin:0px} iframe{border:0px}</style>")

			//redirects to live.skysports.com if iframed in on another site
			if (top.location!= self.location) {
				top.location = self.location.href;
			}
			
			
		
		}
	},
	
	writeBanner:function(p){
			
			if(!p){p=""}

			if(!document.getElementById('bannerAd')){
				var bannerIframe = document.createElement("iframe");
				bannerIframe.setAttribute("name", 'bannerAd');
				bannerIframe.setAttribute("id", 'bannerAd');
				bannerIframe.setAttribute("src", "");
				bannerIframe.scrolling='no';
				bannerIframe.frameBorder='0';
				bannerIframe.allowTransparency="true";
				bannerIframe.width = "728px";
				bannerIframe.height = "90px";
				
				document.getElementsByTagName('body')[0].appendChild(bannerIframe);
				bannerIframe.style.marginLeft="300px";
				bannerIframe.style.marginTop="-3px";
			}
			var doc = document.getElementById('bannerAd').contentWindow.document;
			doc.open();
			
			if (window.adgroupid == undefined) {window.adgroupid = Math.round(Math.random() * 1000);}
			
			doc.write('<html><head><style type="text/css">*{padding:0px;margin:0px} body {padding:0px;margin:0px;} #ls-leaderboard{width:728px;height:90px;background:red;margin:0px;text-align:center}</style></head><body><scr'+'ipt src="http://adserver.adtech.de/addyn|3.0|500|1404562|0|1|ADTECH;cookie=info;loc=100;target=_blank;key='+p+';grp='+window.adgroupid+';misc='+new Date().getTime()+'"></scri'+'pt></body></html>');
			
		
			
			doc.close();
},	

	hitbox: function(p){
		
		if(p.pagetitle){
		
			//set page title
			if(p.statusbar.length>1){parent.document.title = p.statusbar;}	
			else{parent.document.title = p.pagetitle;}
			
			//parent.location.hash = p.pagetitle.replace(/ /g,"+");
			
			//if(pName==undefined){pName=""}
	
			//set page and content category for hitbox
			var pslash = p.pagetitle.replace(/\s\|\s/gi,"/");
			var pPN = p.pagetitle.replace(/\s\|\s/gi," - ");
			
	
			pslash = pslash.replace('Sky Sports','SkySports');
			pPN = pPN.replace('Sky Sports','SkySports');
		
			
			if(p.auto=='auto'){
				
				parent._hbPageView(pPN + " - AUTO RELOAD","/"+pslash + " - AUTO RELOAD");
				//hitbox debugger
				if(parent.location.hash=='#hitboxdebug'){alert(pPN + " - AUTO RELOAD","/"+pslash + " - AUTO RELOAD");}
			}
			
			if(p.auto=='click'){
				
				parent._hbPageView(pPN,"/"+pslash);
				//hitbox debugger
				if(parent.location.hash=='#hitboxdebug'){alert(pPN,"/"+pslash)}
			}
			
		}
		
		
		//refresh leaderboard ad
		if(p.adrefresh){
			
			if(p.adrefresh.length>0){document.getElementById('ls-leaderboard').src="ad.html?key="+p.adrefresh;}
		
			
		}
		
		//alert(p.bettingid)
		
		if(p.bettingid){
			if(p.bettingid==0){
			
				live.bettingtab({show:'no',pagetitle:p.pagetitle})
			
			}
			
			if(p.bettingid==-1){
			
				live.bettingtab({show:'remove'})
			
			}
			
			if(p.bettingid==1){
			
				//do nothing
			
			}
			
			if(p.bettingid.length>2){
				
				live.bettingtab({show:'yes',id:p.bettingid,cache:p.cache})
			}
		
		}
		
		
		
	
	},

	css: function(p){
		var lsl = document.getElementById('ls-leaderboard');
		//var sp1 = document.getElementById('ls-sponsor1');
		
	},
	
	popUp: function(p){
		var b='no';
		
		if(screen.height<770) {b='yes';}
	
		var popLeft = Math.floor((screen.width - p.width) / 2);
		var popTop = Math.floor((screen.height - p.height) / 2);
	
		var a = document.getElementsByTagName("a");
	
		for(i=a.length-1;i>=0;--i){

			if(a[i].getAttribute('rel')==p.rel){
				a[i].onclick=function(){
				
				window.open(this.href,'livepop','width='+p.width+',height='+p.height+',top='+popTop+',left='+popLeft+',resizable=yes,type=fullWindow,channelmode='+b);return false;
			}
		}

	}
	
	
	},
	
	bettingtab: function(p){
	
		if(parent.window.skybettab!=undefined){
			
			if(p.show=='yes'){
				if(document.getElementById('ls-bettingtab')){
				
					var i=document.getElementById('ls-bettingtab');
					
					if(i.src.split('matchNum=')[1]==p.id){
						i.style.visibility="visible";
						i.className='';
					}
					
					else{
						document.getElementById('ls-bettingtab').src=i.src.split('?cache=')[0]+"?cache="+p.cache+"&matchNum="+p.id;
						i.style.visibility="visible";
						i.className='';
					}
				
				}
				
				else{
				
					var iframe = document.createElement('iframe');
					
					iframe.src=parent.window.skybettab+'?cache='+p.cache+'&matchNum='+p.id;
					iframe.id="ls-bettingtab";
					iframe.scrolling='no';
					iframe.allowTransparency="true";
					iframe.frameBorder="0";
					if(top.document.title.match(/CRICKET/i)){
						
						iframe.style.width='626px';
						iframe.style.height='437px';
						iframe.style.left='199px';
						iframe.style.top='194px';
					
					}
					
					if(top.document.title.match(/RUGBY/i)){
						
						iframe.style.width='806px';
						iframe.style.height='311px';
						iframe.style.left='199px';
						iframe.style.top='327px';
						
					}
					
					if(top.document.title.match(/FOOTBALL/i)){
						
						iframe.style.width='806px';
						iframe.style.height='311px';
						iframe.style.left='199px';
						iframe.style.top='241px';
					
					
					}
					iframe.style.position='absolute';
					iframe.className='';
				
					document.getElementsByTagName('body')[0].appendChild(iframe);
					
					
				}
			}
			
			if(p.show=='no'){
				
				if(document.getElementById('ls-bettingtab')){
					
					document.getElementById('ls-bettingtab').style.visibility='hidden';
					document.getElementById('ls-bettingtab').className='sbhidden';
				}
			
			}
			
			if(p.show=='remove'){
		
				if(document.getElementById('ls-bettingtab')){
				
					var o = document.getElementById('ls-bettingtab');
					document.getElementsByTagName('body')[0].removeChild(o);
				

				}
			
			}
		}
		
	},
	
	getquery:function(n){
		
		var query = window.location.search.substring(1);
		query = query.replace('&amp;','&');
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == n) {
				return pair[1];
				
			}
		}
	
	
	},
	
	skybetembed:function(p){

	
		var scaletype="showall";
		var params="<param name='FlashVars' value='wid="+p.width+"&hei="+p.height+"'>";
		
		if(top.document.title.match(/CRICKET/i)){
			
			scaletype="noscale";
			
			p.width='627px';
			p.height='440px';
			params = "<param name='FlashVars' value='wid=627&hei=440'>";
		
		}
		var div = document.getElementById(p.div);
		
		var matchid=live.getquery(p.matchid);
	
		var cache=live.getquery(p.cache);

		div.innerHTML="<object type='application/x-shockwave-flash' data='"+p.swf+"?matchNum="+matchid+"&config="+p.config+"&cache="+cache+"' width='"+p.width+"' height='"+p.height+"'><param name='scale' value='noscale'><param name='wmode' value='opaque'>"+params+"<param name='movie' value='"+p.swf+"?matchNum="+matchid+"&config="+p.config+"&cache="+cache+"'><p><a href='http://www.adobe.com/go/flashplayer/' target='blank'>Get the Adobe Flash Player to view this content</a></p></object>"
	
	
	},
	
	betslip: function(p){
		//affiliate codes
		if (top.document.title.match(/Sky Sports/i)) live.betaff = '2742';
		if (top.document.title.match(/Cricket/i)) live.betaff = '1573';
		if (top.document.title.match(/Rugby/i)) live.betaff = '535';
		if (top.document.title.match(/Teamtalk/i)) live.betaff = '699';
		if(!live.betaff) live.betaff = '2742';
		
		var popLeft = Math.floor((screen.width - 700) / 2);
		var popTop = Math.floor((screen.height - 500) / 2);
		
		window.open("https://www.skybet.com/secure/rbs?action=go_gmulti&ev_oc_id="+p.id+"&lp_num="+p.num+"&lp_den="+p.den+"&AFF_ID="+live.betaff+"",'SkyBetLive','width=700,height=500,scrollbars=1,top='+popTop+',left='+popLeft);
	
	},
	
	overlay: function(p){
		
		if(p=='off'){
			
			if(document.getElementById('ls-leaderboard')){document.getElementById('ls-leaderboard').style.visibility='hidden'}
			if(document.getElementById('ls-sponsor1')){document.getElementById('ls-sponsor1').style.visibility='hidden'}
			if(document.getElementById('ls-bettingtab')){document.getElementById('ls-bettingtab').style.visibility='hidden'}
		}
		
		else{
			if(document.getElementById('ls-leaderboard')){document.getElementById('ls-leaderboard').style.visibility='visible'}
			if(document.getElementById('ls-sponsor1')){document.getElementById('ls-sponsor1').style.visibility='visible'}
			if(document.getElementById('ls-bettingtab') && document.getElementById('ls-bettingtab').className!='sbhidden'){document.getElementById('ls-bettingtab').style.visibility='visible'}
		}

	},
	
	avPop: function(p){
			
			var url=p.url;
			var w;
			var h;
			
			if(p.url.match('w=')){
				w = p.url.split('w=')[1];
				w = parseInt(w.split('&')[0]);
			}
			
			if(p.url.match('h=')){
				h = p.url.split('h=')[1];
				h = parseInt(h.split('&')[0]);
			}
			

			if(p.url.match('h=') && p.url.match('w=')){
				var popLeft = Math.floor((screen.width - w) / 2);
				var popTop = Math.floor((screen.height - h) / 2);
				window.open(url,'window','width='+w+',height='+h+',top='+(popTop)+',left='+popLeft+',resizable=yes,scrollbars=no');
		}
		
		else{window.open(url)}
	},
	
	liveBrowser: function(p){
	p.sport=p.sport.replace(' ','');
	
			if(p.sport=='football'){
				
				location.reload(true)
			
			}
	
			if(p.sport=='cricket'){
				
				var url="http://home.skysports.com/livescores/cricket/";
				var w=760;
				var h=545;
				var popLeft = Math.floor((screen.width - w) / 2);
				var popTop = Math.floor((screen.height - h) / 2);
				window.open(url,'CricketScoreCentre','width='+w+',height='+h+',top='+(popTop)+',left='+popLeft);
			
			}
			
			if(p.sport=='rugbyunion'){
			
				var url="http://home.skysports.com/livescores/rugbyunion/";
				var w=700;
				var h=565;
				var popLeft = Math.floor((screen.width - w) / 2);
				var popTop = Math.floor((screen.height - h) / 2);
				window.open(url,'RugbyUnionScoreCentre','width='+w+',height='+h+',top='+(popTop)+',left='+popLeft);
			
			}
			
			if(p.sport=='rugbyleague'){
				
				var url="http://home.skysports.com/livescores/rugbyleague/";
				var w=700;
				var h=565;
				var popLeft = Math.floor((screen.width - w) / 2);
				var popTop = Math.floor((screen.height - h) / 2);
				window.open(url,'RugbyLeagueScoreCentre','width='+w+',height='+h+',top='+(popTop)+',left='+popLeft);
	
			}
			
			if(p.sport=='golf'){
			
				var url="http://www.skysports.com/golf/leaderboard_popup/0,21120,,00.html"
				var w=540;
				var h=465;
				var popLeft = Math.floor((screen.width - w) / 2);
				var popTop = Math.floor((screen.height - h) / 2);
				window.open(url,'F1ScoreCentre','width='+w+',height='+h+',top='+(popTop)+',left='+popLeft);
			
			}
			
			if(p.sport=='f1'){
				var url="http://www.skysports.com/formula1/live/0,22627,,00.html";
				var w=800;
				var h=770;
				var popLeft = Math.floor((screen.width - w) / 2);
				var popTop = Math.floor((screen.height - h) / 2);
				window.open(url,'F1ScoreCentre','width='+w+',height='+h+',top='+(popTop)+',left='+popLeft);
				
				
	
			
			}
	
	
	
	},
	
	changeIframe:function(p){
		
		for(var i = 0;i<p.iframes.length;i++){
			
			document.getElementById(p.iframes[i].id).src=p.iframes[i].url;
		
		
		}
	
	
	
	},
	
	shake:function(n){
		if (self.moveBy) {
			for (i = 10; i > 0; i--) {
				for (j = n; j > 0; j--) {
					self.moveBy(0,i);
					self.moveBy(i,0);
					self.moveBy(0,-i);
					self.moveBy(-i,0);
				}
			}
		}
	} 
	

}


