﻿(function(){
	var base_url='http://bf2.boti.com:882/football-livescores.aspx'; 
	var base_url_nba='http://bf2.boti.com:882/basketball-livescores.aspx';
	get_theme=function(){
		var name='',wi=window.Windex,lc=window.Lcookie;
		if(wi || lc){
			name=wi?wi._defaultstyle||lc.get('pagestyle',wi._defaultcolor):'';
		}
		if(name=='coffer')name='coffee';
		return name;
	},
	livescore=function(url,layout,theme,title,width,height,cid,lid,eid,scrollBar){
		var params='', append=function(k,v){
			if(v && v!=''){
				if(params.length>0)params+='&';
				params+=k+'='+escape(v);
			}
		},filter=function(pars){
			if(typeof pars === 'string'){
				var i,ary=[],arr=pars.replace(/\s/g,'').split(',');
				for(i=0;i<arr.length;i++){
					if(arr[i].length>0)ary.push(arr[i]);
				}
				return ary.join(',');
			}
			return pars;
		};
		append('layout',layout);
		append('title',title);
		append('theme',theme);
		append('country',filter(cid));
		append('match',filter(lid));
		append('event',filter(eid));
		append('width',width);
		append('height',height);
		append('scrollBar',scrollBar);
		document.write('<iframe name="LiveScores" src="'+(url+(params.length>0?'?'+params:''))+'" width="'+width+'" height="'+height+'" frameborder="0" scrolling="no"></iframe>');
	};
	window.livescoreThemeChange=function(name){
		var tags=document.getElementsByTagName('iframe');
		if(name=='coffer')name='coffee';
		for(var i=0;i<tags.length;i++){
			if(tags[i].name=='LiveScores'){
				tags[i].src=tags[i].src.replace(/theme=\w+/,'theme='+name);
			}
		}
	};
	// 纵向
	window.livescoreIFR=function(title,width,height,cid,lid,eid){ //标题，宽度，高度，国家ID，联赛ID，赛事ID
		livescore(base_url,'v',get_theme()||'yellow',title,width,height,cid,lid,eid,true);
	};
	// 横向
	window.livescoreIFR2=function(title,width,height,cid,lid,eid){ //标题，宽度，高度，国家ID，联赛ID，赛事ID
		livescore(base_url,'h',get_theme()||'blue',title,width,height,cid,lid,eid,false);
	};
	
	// 纵向
	window.livescoreIFR_nba=function(title,width,height,cid,lid,eid){ //标题，宽度，高度，国家ID，联赛ID，赛事ID
		livescore(base_url_nba,'v',get_theme()||'yellow',title,width,height,cid,lid,eid,true);
	};
	// 横向
	window.livescoreIFR2_nba=function(title,width,height,cid,lid,eid){ //标题，宽度，高度，国家ID，联赛ID，赛事ID
		livescore(base_url_nba,'h',get_theme()||'blue',title,width,height,cid,lid,eid,false);
	};
	
})();
