
// JavaScript 教育宽频
var educhina_res_lib = {
	loadCss: function (url) {
		if(document.getElementsByTagName('head')[0]){
			var css = document.createElement('link');
			css.setAttribute('rel', 'stylesheet');
			css.setAttribute('type', 'text/css');
			css.setAttribute('href', url);
			document.getElementsByTagName('head')[0].appendChild(css);
		}else{
			document.writeln("<link href=\""+url+"\" rel=\"stylesheet\" type=\"text\/css\"\/>");
		}
	},
	
	loadjs: function (url) {		
		if(document.getElementsByTagName('head')[0]){
			var ajs = document.createElement('script');	
			ajs.setAttribute('language','javascript');
			ajs.setAttribute('type','text/javascript');
			ajs.setAttribute('src',url);
			document.getElementsByTagName('head')[0].appendChild(ajs);
		}else{
			document.write('<script type=text\/javascript src="'+url+'"><\/script>');
		}
	},
	
	loadDoctypeHtml: function(){
		//var adoc = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
		//alert("write");
		//document.writeln(adoc);
	},	
	
	getElement: function (id) {
		return document.getElementById(id);
	}
};

//js参数
var q = new querystring();
//学校编号
var schoolId = q.get('schoolId','');
//去掉编号里的所有空格 
schoolId=schoolId.replace(/\s/ig,'');
//定置
var mbpos = q.get('mbpos','RD');
//音量
var edu_volume=q.get('volume','80');
//、是否自动播放
var edu_autoplay=q.get('autoplay','true');
//增加Debug模式,默认为false
var edu_debugger=q.get('debug','false');

//迷你广告版本
var miniplayer_v = 0.92;
//教育宽频版本
var player_v = 0.67;
//通用js版本
var msg_v = 0.35;
//内容版本
var ContentJS_v = 0.46;
//停止播放
var jsStopPlay=false;
//皮肤版本
var skin_v = 0.8;
//资源地址
var ipaddress="http://kp.educhina.tv/flash/";
//var ipaddress="http://192.168.1.137:5080/eduChinaMiniPlayer/flash5/";
var defaultVideo="http://ftp1.educhina.tv/upload/school/9000/3f0172c0-7bf9-4b28-bb11-0835480d6188.flv";
var skinfile=ipaddress+"res/skin/mini/spring.swf?v="+skin_v;
// loaderr2.png
var loadSwfErrorPng=ipaddress+"Assets/image/computer.png";
//
var m_player_width  = 350;
var m_player_height = 258;
//
var edu_player_w = 980;
var edu_player_h = 542;
//idType  类型（1为学校 2为单位
var edu_idType = 1;

//播放器通用属性
var attributes = {};
//迷你广告视频参数设定
var request_url="http://kp.educhina.tv/eduvideo/allpromovideo.jspx";
var request_miniclicks_url = "http://kp.educhina.tv/eduvideo/miniclicks.jspx";

//
//脚本是否准备就绪
var jsEduChinaIsReady = false;
//浏览器
var sf_mess_browser = {};
sf_mess_browser.ieVersion = /msie (\d+)/.exec(navigator.userAgent.toLowerCase());
sf_mess_browser.higherThanIE6 = sf_mess_browser.ieVersion && parseInt(sf_mess_browser.ieVersion[1]) > 6;
//alert("sf_mess_browser.ieVersion:"+sf_mess_browser.ieVersion);
sf_mess_browser.onQuirkMode = document.compatMode && document.compatMode.indexOf('Back') == 0;

//播放器视频参数设定
var flash_wmode = 'Transparent';
if ( /MSIE 6.0/ig.test(navigator.appVersion) ) {
	//flash_wmode = 'Window'; //ie6窗口模式1111
}

var flashvars_p = {"videoUrl":"","schoolId":schoolId};

var params_p ={allowFullScreen:'true',allowScriptAccess:'always',quality:'high',wmode:flash_wmode};
var flashvars = {
	request_url:request_url,
	miniclicks_url:request_miniclicks_url,
	allId:schoolId,
	idType:edu_idType,
	skinfile:skinfile,
	volume:edu_volume,
	autoplay:edu_autoplay
	};
var params ={allowFullScreen:'true',allowScriptAccess:'always',quality:'high',wmode:flash_wmode};


/*var detect = navigator.userAgent.toLowerCase();
var isMac = (detect.indexOf('macintosh') != -1);
var isWin = (detect.indexOf('windows') != -1);
var isLin = (detect.indexOf('linux') != -1);
 
var browserName = "unknown";
var browserBuild = 0;
var browsermatch = /(msie\s|camino\/|firefox\/|safari\/|minefield\/|chrome\/)([\d]+\.?\d*)/.exec(detect);
if (browsermatch.length == 3)
{
    browserName = browsermatch[1];
    browserName = browserName.substr(0, browserName.length - 1);
    browserBuild = 0.0 + browsermatch[2];
}
 
var isIE = (browserName == "msie" && browserBuild >= 6);
var isMZ = ((browserName == "firefox" || browserName == "minefield") && browserBuild >= 2.0);
var isSF = (browserName == "safari" && browserBuild >= 523); // webkit-to-safari mapping: 523=v3.0, 525=v3.1 *and* v3.2, 528=v4.0 beta, 530=v4.0 release
var isCH = (browserName == "chrome" && browserBuild >= 2.0);
var isCam = (browserName == "camino");
 
// version ests for, e.g., loading the right clipboard interface
var isSF3 = (isSF && browserBuild <= 525);
var isSF4 = (isSF && browserBuild > 525);
var isMZ2 = (isMZ && browserBuild < 3.0);
var isMZ3 = (isMZ && browserBuild >= 3.0);
var isFM = (isMZ && isMac);*/
//延时初始化
var educhina_js_delayShow = 1000;

//alert("document.documentElement.clientHeight::"+document.documentElement.clientHeight);
educhina_res_lib.loadDoctypeHtml();
educhina_res_lib.loadCss(ipaddress+'style/eduPlayer_layout.css');
//educhina_res_lib.loadjs(ipaddress+'FlashMsg.js?v='+msg_v);
educhina_res_lib.loadjs(ipaddress+'swfobject22.js');
/**=-=-=-=-=-=-=-=-=-=-=-*/
/**校园网络电视台内容DIV	开始*/
/**=-=-=-=-=-=-=-=-=-=-=-*/
var SF_MESS_WRAP_ID 			= "eduChina_popup_msg";
var SF_MESS_BODY_ID 			= "eduChina_popup_msg_container";
var SF_MESS_PLAYER_BODY			= "eduChina_popup_player_container";
var EDUCHINA_DIV_DEBUGGER		= "eduChina_debugger_container";
var educhina_divs_layout_mod = [];
educhina_divs_layout_mod.push(
	//校园网络电视台						  
	'<div id="${SF_MESS_PLAYER_BODY}" >',
	//'<div class="player_popupWindow" id="eduChinaPlayerDiv">',		
	'<div id="eduChinaPlayer">',	
	'<iframe class=\"eduChina_iframe\" width=\"100%\" frameborder="0"></iframe>',
	'<div id="eduChinaPlayerDiv"></div>',
	
	//'<OBJECT class="eduChina_object" type="text/x-scriptlet" data="about:<body><div style=\"position:absolute;left:0;top:0;width:100%;height:100%;font:14;color:white;background:black;border:1 solid black\">eduChina_object</div>"></OBJECT>',
	'</div>',//</div></div>		
	'</div>',//</div></div>
	
	//top:1000px;迷你播放器
	'<div id="${SF_MESS_WRAP_ID}" >',
	'<div id="${SF_MESS_BODY_ID}" style="display:none;width:100%;height:100%;">',
	'<div id="myMiniPlayerContent" >',
	<!--'<p><a href="http://www.educhina.tv"><img src="${loadSwfErrorPng}" border="0" width="80%" height="80%" /></a></p>',-->
	'<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>',
	'</div>',
	'</div>',
	'</div>',
	//debuger 
	
	//'<div id="${EDUCHINA_DIV_DEBUGGER}"></div>'
	""
	);
//document.write('<script type=text\/javascript src="'+ipaddress+'eduChinaPlayerContentJS.js?v='+ContentJS_v+'"><\/script>');

/**=-=-=-=-=-=-=-=-=-=-=-*/
/**校园网络电视台内容DIV	结束*/
/**=-=-=-=-=-=-=-=-=-=-=-*/



/**=-=-=-=-=-=-=-=-=-=-=-*/
/**校园网络电视台内容DIV	Layout 开始*/
/**=-=-=-=-=-=-=-=-=-=-=-*/
var educhina_divs_layout = {
	module: null,
	getModule: function () {
		return educhina_divs_layout_mod.join('');
	},

	createLayout: function () {
		showDebugMsg('创建播放器...');
		//var _lbody  = document.getElementsByTagName('body')[0];
		//alert("_lbody:"+_lbody);
		//if(_lbody){
			//var div1 = document.createElement("div");  
			//document.write(this.getModule().replace(/\$\{[.\w]+\}/g, this.__layoutVarReplacer));
			//_lbody.innerHTML += (this.getModule().replace(/\$\{[.\w]+\}/g, this.__layoutVarReplacer));
			//alert(this.getModule().replace(/\$\{[.\w]+\}/g, this.__layoutVarReplacer));
			//div1.innerHTML = this.getModule().replace(/\$\{[.\w]+\}/g, this.__layoutVarReplacer);
			//_lbody.appendChild(div1);
		//}else{
			document.write(this.getModule().replace(/\$\{[.\w]+\}/g, this.__layoutVarReplacer));	
		//}
		 
		var page = document.documentElement;
		if(page.clientHeight==0){
			page = document.body;
		}
		
		this.mbWrap = educhina_res_lib.getElement(SF_MESS_WRAP_ID);
		this.mbWrap.style.clientWidth = m_player_width;
		this.mbWrap.style.width = m_player_width+'px';
		this.mbWrap.style.clientHeight = m_player_height;
		this.mbWrap.style.height = m_player_height+'px';
		//this.mbWrap.style.display = 'none';	
		this.mbWrap.style.position = 'absolute';
		
		this.cbPlayer = educhina_res_lib.getElement(SF_MESS_PLAYER_BODY);
		this.cbPlayer.style.display = 'none';	
		//alert("this.cbPlayer ::"+this.cbPlayer );
	},
	
	__layoutVarReplacer: function (str) {
		if (str.indexOf('$') == 0) {
			try {
				return eval(str.substr(2, str.length - 3));
			} catch(e) {
				return '';
			}
		}
		return str;
	},
	
	initFormStyle: function() {
		showDebugMsg('初始化播放器...');
		var mbBody = educhina_res_lib.getElement(SF_MESS_BODY_ID);
		var page = document.documentElement;
		if(page.clientHeight==0){
			page = document.body;	
		}
		//var playerBody = educhina_res_lib.getElement(SF_MESS_PLAYER_BODY);
		
		mbBody.style.overflow = 'hidden';
		mbBody.style.display = 'block';	
		//		
		//playerBody.style.overflow = 'hidden';
		//playerBody.style.display = '';	
		//加载迷你播放器
		
		try{
			showDebugMsg('正在加载迷你播放器...');
			swfobject.embedSWF(ipaddress+"eduChinaMiniPlayer.swf?v="+miniplayer_v, "myMiniPlayerContent","100%", "100%" , "10", "expressInstall.swf",flashvars,params,attributes);
			//加载教育宽频
			showDebugMsg('正在加载校园网络电视台...');
			swfobject.embedSWF(ipaddress+"EduVideo.swf?v="+player_v, "eduChinaPlayerDiv", "100%", "100%", "9", "expressInstall.swf",flashvars_p,params_p,attributes);
			
		}catch(e){
			showDebugMsg(e.message);	
		}
		//
		
		//IE6以下
		if(!sf_mess_browser.higherThanIE6){
			if(this.cbPlayer){			
				//this.cbPlayer.style.overflow = 'hidden';
				this.cbPlayer.style.display = 'none';				
			}
		}
		
		
		//debug:this.mbWrap.clientHeight=0		
		this.mbWrap.style.top = page.clientHeight - this.mbWrap.clientHeight  + 'px';
		//alert("top:"+this.mbWrap.style.top);
		
		
		if (window.addEventListener || sf_mess_browser.higherThanIE6 && (!sf_mess_browser.onQuirkMode)) {
			//alert("1");
			//this.mbWrap.style.top = '';
			if(mbpos=="RD"){	//右下角
				this.mbWrap.style.bottom = '0';
				this.mbWrap.style.right = '0';
			}else if(mbpos=="LD"){
				this.mbWrap.style.left = '0';
				this.mbWrap.style.bottom = '0';
			}else if(mbpos=="LT"){
				this.mbWrap.style.left = '0';
				this.mbWrap.style.top = '0';
			}else if(mbpos=="RT"){
				this.mbWrap.style.top = '0';
				this.mbWrap.style.right = '0';
			}
			
			if(page.clientHeight>0){
				this.mbWrap.style.position = 'fixed';
				this.cbPlayer.style.position = 'fixed';	
			}
				
			//this.mbWrap.style.filter =  'alpha(opacity:90)';
			//this.cbPlayer.style.top = '';
			//this.cbPlayer.style.left = '';
			
		} else {
			
			//alert("2 mbpos="+mbpos);
			this.mbWrap.style.position = 'absolute';			
			//
			//this.cbPlayer.style.left = '0';			
			//this.cbPlayer.style.position = 'absolute';	
			//
			window.attachEvent('onscroll', this.fixMessageBoardPosition);
			window.attachEvent('onresize', this.fixMessageBoardPosition);			
			
			this.fixMessageBoardPosition();
			
		}
		
		jsEduChinaIsReady = true;
		
		//sf_mess_tween.initTween();
	},
	
	fixMessageBoardPosition: function () {
		var self = educhina_divs_layout;
		var page = document.documentElement;
		//ie7,ie8以上
		if(!sf_mess_browser.higherThanIE6 || page.clientHeight==0){
			//alert("page::"+page);
			page = 	document.body;
		}
		
		
		if (!sf_mess_browser.onQuirkMode) {
			//alert("sf_mess_browser.onQuirkMode::"+sf_mess_browser.onQuirkMode);
			page = page.parentNode;
			
		}		
		
		
		if(mbpos=="RD"){	//右下角
			self.mbWrap.style.top = parseInt(page.clientHeight) + parseInt(page.scrollTop) - self.mbWrap.offsetHeight + 'px';
			self.mbWrap.style.bottom = '0';
			self.mbWrap.style.right = '0';
		}else if(mbpos=="LD"){//左下角
			//alert("fixMessageBoardPosition mbpos="+mbpos);
			self.mbWrap.style.top = parseInt(page.clientHeight) + parseInt(page.scrollTop) - self.mbWrap.offsetHeight + 'px';
			self.mbWrap.style.left = '0';
			self.mbWrap.style.bottom = '0';
			
		}else if(mbpos=="LT"){//左上角
			self.mbWrap.style.top = parseInt(page.scrollTop) + 'px';
			self.mbWrap.style.left = '0';			
		}else if(mbpos=="RT"){//右上角
			self.mbWrap.style.top = parseInt(page.scrollTop) + 'px';
			self.mbWrap.style.right = '0';
		}
		//self.mbWrap.style.bottom = '0px';
		//alert(self.cbPlayer.offsetHeight);
		
	}
}


/**=-=-=-=-=-=-=-=-=-=-=-*/
/**校园网络电视台内容DIV	Layout 结束*/
/**=-=-=-=-=-=-=-=-=-=-=-*/



/**=-=-=-=-=-=-=-=-=-=-=-*/
/**校园网络电视台 JS函数定义*/
/**=-=-=-=-=-=-=-=-=-=-=-*/
function getServer(){
	//return "";	
	return ipaddress;
}

function isEduChinaJSReady(){	
	return jsEduChinaIsReady;
}

function showeduChinaPlayer(purl){
	//alert(purl);
	hideLayer("myMiniPlayerContent");			//隐藏迷你播放器
	//eduChinaPlayer.x = doument.
	showLayer(SF_MESS_PLAYER_BODY);		//显示教育宽频
}

function hideeduChinaPlayer(){	
	showLayer("myMiniPlayerContent");		//显示迷你播放器
	//setSwfplayerStop();				//停止教育宽频播放
	hideLayer(SF_MESS_PLAYER_BODY);	//隐藏教育宽频
}

function showmessage_trace(msg){
	alert("msg:"+msg);	
}

function showDebugMsg(msg){	
	//
	if(educhina_res_lib.getElement("debugtx2")){
		educhina_res_lib.getElement("debugtx2").innerHTML += msg+"<br/>";
	}	
}


//call back
function setSwfplayerStop(){
// 	getSWF("eduChinaPlayer").playerStop();
	var flashTarget=swfobject.getObjectById("eduChinaPlayer");
	flashTarget.playerStop();
	//alert("停止成功");
}



function showLayer(id) { 
	document.getElementById(id).style.display = "block";
}
function hideLayer(id) { 
	document.getElementById(id).style.display = "none";
}



function _message_close_play(act){
	//显示迷你播放器
	hideeduChinaPlayer();
}


function getClientWidth(){
	return document.documentElement.clientWidth;
}

function getClientHeight(){
	return document.documentElement.clientHeight;	
}

function getJSScreenSize(){
	var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;
	if(typeof(window.pageXOffset)=='number')
	{
		 scrollX=window.pageXOffset;
		 scrollY=window.pageYOffset;
	}
	else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
	{
		 scrollX=document.body.scrollLeft;
		 scrollY=document.body.scrollTop;
	}
	else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
	{
		 scrollX=document.documentElement.scrollLeft;
		 scrollY=document.documentElement.scrollTop;
	}
	
	if(typeof(window.innerWidth)=='number')
	{
		 width=window.innerWidth;
		 height=window.innerHeight;
	}
	else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
	{
		 width=document.documentElement.clientWidth;
		 height=document.documentElement.clientHeight;
	}
	else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
	{
		 width=document.body.clientWidth;
		 height=document.body.clientHeight;
	}
	
	if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight))
	{
		 if(document.documentElement.scrollHeight>document.documentElement.offsetHeight){
			  contentWidth=document.documentElement.scrollWidth;
			  contentHeight=document.documentElement.scrollHeight;
		 }
		 else
		 {
			  contentWidth=document.documentElement.offsetWidth;
			  contentHeight=document.documentElement.offsetHeight;
		 }
	}
	else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))
	{
		 if(document.body.scrollHeight>document.body.offsetHeight)
		 {
			  contentWidth=document.body.scrollWidth;
			  contentHeight=document.body.scrollHeight;
		 }else{
			  contentWidth=document.body.offsetWidth;
			  contentHeight=document.body.offsetHeight;
		 }
	}
	else
	{
		 contentWidth=width;
		 contentHeight=height;
	}
	
	if(height>contentHeight) height=contentHeight;
	if(width>contentWidth) width=contentWidth;
	
	var rect=new Object();
	rect.ScrollX=scrollX;
	rect.ScrollY=scrollY;
	rect.Width=width;
	rect.Height=height;
	rect.ContentWidth=contentWidth;
	rect.ContentHeight=contentHeight;
	return rect;
}

function getJSSkin(){	
	return skinfile;	
}

function getDefaultVideo(){
	return defaultVideo;	
}

function _message_setSwfSize(){
	var rect = getJSScreenSize();
	var flashTarget=swfobject.getObjectById("myMiniPlayerContent");
	//alert("flashTarget:"+flashTarget);
	
	flashTarget.getScreenSize(m_player_width,m_player_height);	
}

function querystring(){
	this.params = new Object();
	this.initialize = function(){
		var param=this.paramstring(); 
		if(param.length == 0) return;
		if(param.substring(0,1)=='?'){ 
			 param=param.substring(1);
		}
		param = param.replace(/\+/g, ' ');
		var args = param.split('&');
		for (var i=0;i<args.length;i++){
			var value;
			var pair = args[i].split('=');
			var name = unescape(pair[0]);
			if (pair.length == 2)
				value = unescape(pair[1]);
			else
				value = name; 
			this.params[name] = value;
		}
	};
	this.get = function(key, defvalue){
		return this.params[key]==null?defvalue:this.params[key];	
	};
	this.paramstring = function(){
		var col=document.getElementsByTagName("script");
		var jsrc=col.item(col.length-1).src;
		var i=jsrc.indexOf("?");
		var words=jsrc.substr(i+1,jsrc.length);
		return(words);
	};
	this.initialize(); 
}

//未加载完成
if (!window.is_sf_mess_loaded) {
	window.is_sf_mess_loaded = true;
	//写内容
	
	educhina_divs_layout.createLayout();
	
	//document.write('<script type=text\/javascript src="'+ipaddress+'buildnormal.js?v='+ContentJS_v+'"><\/script>');
	setTimeout(function(){educhina_divs_layout.initFormStyle();}, educhina_js_delayShow);

}