// JavaScript Document
function getObj(objID) {
	return document.getElementById(objID);
}

function getClient() {
	var x, y, h, w;
	if (document.documentElement) {
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if (document.body) {
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	} else {}//Netscape stuff
	return {"x":x, "y":y, "w":w, "h":h};
}

/**
 * 检查是否在规定时间内
 * dateBeg
 * dateEnd
 */
function checkShowTime(dateBeg, dateEnd){
    var strNow = Math.round(new Date().getTime() / 1000);
    var strBeg = Math.round(new Date(dateBeg).getTime() / 1000);
    if (strNow >= strBeg && dateEnd == 0) {
        return true;
    }
    var strEnd = Math.round(new Date(dateEnd).getTime() / 1000);
    if (strNow <= strEnd && strNow >= strBeg) {
        return true;
    }
    return false;
}

//******************************************************************
//撑屏广告开始
//******************************************************************
var const_slide = [
	{title:"重庆巴派红门",url:"http://ms.wst.cn/Co/Index.asp?ID=1375",img:"/FuWu/images/slide_20100605.gif",w:"960",h:"400",type:"img",strBeg:"06/05/2010 09:00:00",strEnd:"06/07/2010 09:00:00"}
];
var intervalId = null; 
function slideAd(id, nStayTime, sState, nMaxHth, nMinHth) { 
	this.stayTime  = nStayTime*1000 || 3000; 
	this.maxHeigth = nMaxHth || 90; 
	this.minHeigth = nMinHth || 1; 
	this.state     = sState || "down" ; 
	var objDraw    = getObj(id); 
	var objClose   = getObj("closeMove");
	if (objDraw == null) { return; }
	objClose.onclick = function() {
		objDraw.style.display = "none"; 
	}
	if(intervalId != null) window.clearInterval(intervalId); 
	function openBox() { 
		var h = objDraw.offsetHeight; 
		//alert(h);
		objDraw.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px"; 
		if (objDraw.offsetHeight > this.maxHeigth) { 
			window.clearInterval(intervalId); 
			intervalId = window.setInterval(closeBox,this.stayTime); 
		} 
		if (objDraw.offsetHeight < this.minHeigth) { 
			window.clearInterval(intervalId); 
			objDraw.style.display = "none"; 
			//showAlert();
		} 
	} 
	function closeBox() { 
		slideAd(id,this.stayTime,"up",nMaxHth,nMinHth); 
	} 
	intervalId = window.setInterval(openBox,10); 
}
function showSlideAdvert() {
	var intLen = const_slide.length;
	var divID = "", strHtml = "", boolShow = false;
	for (var i = 0; i < intLen; i++) {
		var objAd = const_slide[i];
		if (objAd.img != "" && checkShowTime(objAd.strBeg, objAd.strEnd)) {
			if (objAd.type == "img") {
				strHtml += "<a href=\""+objAd.url+"\" target=\"_blank\">";
				strHtml += "<img border=0 src=\""+objAd.img+"\" width=\""+objAd.w+"\" height=\""+objAd.h+"\"/></a>";
			} else {
				strHtml += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+objAd.w+"\" height=\""+objAd.h+"\" ";
				strHtml += "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\">";
				strHtml += "  <param name=\"movie\" value=\""+objAd.img+"\">";
				strHtml += "  <param name=\"quality\" value=\"high\">";
				strHtml += "  <embed src=\""+objAd.img+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" ";
				strHtml += "type=\"application/x-shockwave-flash\" width=\""+objAd.w+"\" height=\""+objAd.h+"\"></embed></object>";
			}
			boolShow = true;
			break;
		}
	}
	if (boolShow) {
		strHtml  = "<div id=\"MyMoveAd\" style=\"background:#fff;height:400px;overflow:hidden;position:relative;width:960px;margin:0 auto;\" align=\"center\">" + strHtml;
		strHtml += "<span id=\"closeMove\" style=\"position:absolute;right:5px;top:5px;border:1px #000 solid;padding:3px 3px 1px 3px;background:#CCC;filter:Alpha(Opacity=80);opacity:0.80;font-weight:bolder;height:14px;overflow:hidden;cursor:pointer;\">×关闭</span></div>";
		document.write(strHtml);
		slideAd("MyMoveAd",7,"down",400,1);
	}
}
//******************************************************************
//撑屏广告结束
//******************************************************************

//******************************************************************
//跳屏广告开始
//******************************************************************
var tpDivTop,tpDivLeft,tpDivWidth,tpDivHeight,tpDocHeight,tpDocWidth,tpObjTimer,tpintI = 0;
//["8/21/2009 08:50:00","8/22/2009 10:10:00"],
//二泉网络直播时间表
var objTimes  = [["11/07/2009 08:50:00","11/07/2009 14:00:00"],
				 ["8/22/2009 10:50:00","8/22/2009 12:10:00"],
				 ["8/22/2009 13:50:00","8/22/2009 17:30:00"],
				 ["8/23/2009 09:50:00","8/23/2009 11:10:00"],
				 ["8/23/2009 10:50:00","9/3/2009 17:10:00"]
				];
var intLen    = objTimes.length;
var intTime   = null;
var boolPopup = false; //记录弹窗是否已经激活
var boolClose = false; //记录弹窗是否已经关闭

function showAlert() {
	var boolBeg = false;
	for (var i = 0; i < intLen; i++) {
		var tmpDate = objTimes[i];
		var strBeg = Math.round(new Date(tmpDate[0]).getTime()/1000);
		var strEnd = Math.round(new Date(tmpDate[1]).getTime()/1000);
		var strNow = Math.round(new Date().getTime()/1000);
		if (strNow <= strEnd && strNow >= strBeg) {
			boolBeg = true;
			break;
		} 
	}
	if (boolBeg) {
		if (!boolPopup) {
			showPopups();
			boolPopup = true;
		}
	} else {
		if (!boolClose) {
			closeDiv();
			boolClose = true;
		}
	}
	intTime = setTimeout("showAlert()",1000);
}
function showPopups() {
	boolClose = false;
	var objMenu = document.getElementById("eMeng");
	try {
		tpDivTop    = parseInt(objMenu.style.top,10);
		tpDivLeft   = parseInt(objMenu.style.left,10);
		tpDivHeight = parseInt(objMenu.offsetHeight,10);
		tpDivWidth  = parseInt(objMenu.offsetWidth,10);
		tpDocWidth  = document.documentElement.clientWidth;
		tpDocHeight = document.documentElement.clientHeight;
		objMenu.style.top        = parseInt(document.documentElement.scrollTop,10) + tpDocHeight + 10; // tpDivHeight
		objMenu.style.left       = parseInt(document.documentElement.scrollLeft,10) + tpDocWidth - tpDivWidth;
		objMenu.style.visibility = "visible";
		var objTlt = getObj("msgTlt");
		objTlt.innerHTML = "华夏家居港杯磁砖厨卫文化节直播";
		var objMsg = getObj("msgPop");
		objMsg.innerHTML = "<object classid=\"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6\" width=\"400\" height=\"300\"><param name=\"autostart\" value=\"1\" /><param name=\"url\" value=\"mms://58.215.87.50:81/live\" /><embed src=\"mms://58.215.87.50:81/live\" autostart=\"1\" type=\"video/x-ms-wmv\" width=\"400\" height=\"300\"></embed></object>";
		tpObjTimer = window.setInterval("moveDiv()",10);
	} catch(e) {}
}

function resizeDiv() {
	var objMenu = document.getElementById("eMeng");
	tpintI += 1;
	//if (tpintI > 1300) closeDiv(); //客户想不用自动消失由用户来自己关闭所以屏蔽这句
	try {
		tpDivHeight          = parseInt(objMenu.offsetHeight,10);
		tpDivWidth           = parseInt(objMenu.offsetWidth,10);
		tpDocWidth           = document.documentElement.clientWidth;
		tpDocHeight          = document.documentElement.clientHeight;
		objMenu.style.top    = tpDocHeight - tpDivHeight + parseInt(document.documentElement.scrollTop,10);
		objMenu.style.left   = tpDocWidth - tpDivWidth + parseInt(document.documentElement.scrollLeft,10);
	} catch(e) {}
}

function moveDiv() {
	var objMenu = document.getElementById("eMeng");
	try {
		if (parseInt(objMenu.style.top, 10) <= (tpDocHeight - tpDivHeight + parseInt(document.documentElement.scrollTop, 10))) {
			window.clearInterval(tpObjTimer);
			tpObjTimer = window.setInterval("resizeDiv()", 1);
		}
		tpDivTop          = parseInt(objMenu.style.top, 10);
		objMenu.style.top = tpDivTop - 1;
	} catch(e) {}
}
function closeDiv() {
	boolPopup = true;
	var objMenu = document.getElementById("eMeng");
	objMenu.style.visibility = 'hidden';
	getObj("msgPop").innerHTML = "";
	if(tpObjTimer) window.clearInterval(tpObjTimer);
}
//******************************************************************
//跳屏广告结束
//******************************************************************


//随机改变数组的排序
function randomOrder (strPic,strLink,strText,bolRand) {
    if (!bolRand) {
		return 'pics='+strPic+'&links='+strLink+'&texts='+strText;
	}
	var picArray = strPic.split("|");
    var linArray = strLink.split("|");
    var txtArray = strText.split("|");
	var arrayLength = picArray.length
    //
    //先创建一个正常顺序的数组
    var tempArray1 = new Array();

    for (var i = 0; i < arrayLength; i ++) {
        tempArray1 [i] = i
    }
	
    //再根据上一个数组创建一个随机乱序的数组
    var tempArray2 = new Array();

    for (var i = 0; i < arrayLength; i ++)
    {
        //从正常顺序数组中随机抽出元素
        tempArray2 [i] = tempArray1.splice (Math.floor (Math.random () * tempArray1.length) , 1)
    }
    //
    //最后创建一个临时数组存储 根据上一个乱序的数组从targetArray中取得数据
    var tempArray3 = new Array();
	var strPicConn = "";
	var strLinConn = "";
	var strTxtConn = "";

    for (var i = 0; i < arrayLength; i ++) {
        if (i == arrayLength -1) {
			strSplit = "";
		} else {
			strSplit = "|";
		}
		strPicConn += picArray [tempArray2 [i]] + strSplit;
		strLinConn += linArray [tempArray2 [i]] + strSplit;
		strTxtConn += txtArray [tempArray2 [i]] + strSplit;
    }
    //
	//返回最后得出的数组	
	return "pics=" + strPicConn + "&links=" + strLinConn + "&texts=" + strTxtConn;
}

function writeFlash(objSwf) {
	var intTime   = objSwf.intTime;	 //图片停顿时间，单位为秒，为0则停止自动切换
	var intW	  = objSwf.intW;	 //宽度
	var intH	  = objSwf.intH;	 //高度
	var intTxtH   = objSwf.intTxtH;	 //标题高度
	var strAlign  = objSwf.align;	 //标题文字对齐方式(left、center、right)
	var aypics	  = objSwf.pics;	 //图片地址
	var ayhrefs	  = objSwf.hrefs;	 //相对于图片的链接地址
	var aytexts	  = objSwf.texts;	 //标题文字
	var swfPath   = objSwf.swfPath;	 //Flash地址
	var boolRand  = objSwf.boolRand;//是否随机显示
	var intSH	  = intH + intTxtH;	 //Flash高度相加之和最好是偶数,否则数字会出现模糊失真的问题
	var strValues = "interval_time=" + intTime + "&borderwidth=" + intW + "&borderheight=" + intH + "&textheight="+ intTxtH;

	var pics	  = "";
	var hrefs     = "";
	var texts     = "";
	var strUnion  = "";
	var intLen    = aypics.length;
	if (intLen <= 1) {
		if (aypics[0].indexOf(".swf") > 0) {
			document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+intW+"\" height=\""+intH+"\">");
			document.write("   <param name=\"movie\" value=\""+aypics[0]+"\" />");
			document.write("   <param name=\"quality\" value=\"high\" />");
			document.write("   <embed src=\""+aypics[0]+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+intW+"\" height=\""+intH+"\"></embed>");
			document.write("</object>");
		} else {
			document.write("<a href=\""+ayhrefs[0]+"\" target=\"_balank\" title=\""+aytexts[0]+"\"><img src=\""+aypics[0]+"\" width=\""+intW+"\" height=\""+intH+"\"/></a>");
		}
	} else {
		for (var i = 0; i < intLen; i++){
			strUnion = "";
			if (i < (intLen - 1)) {
				strUnion = "|";
			}
			pics  += aypics[i] + strUnion;
			hrefs += ayhrefs[i].replace(/&/g,"^") + strUnion;
			texts += aytexts[i] + strUnion;
		}
	
		strValues	 +=  "&text_align=" + strAlign + "&" + randomOrder (pics, hrefs, texts, boolRand);
	
		document.write("<object codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" ");
		document.write("classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\""+ intW +"\" height=\""+ intSH +"\">");
		document.write("	<param name=\"movie\" value=\"" + swfPath + "\">");
		document.write("	<param name=\"quality\" value=\"high\"><param name=\"bgcolor\" value=\"#ffffff\">");
		document.write("	<param name=\"menu\" value=\"false\"><param name=wmode value=\"opaque\">");
		document.write("	<param name=\"FlashVars\" value=\"" + strValues + "\">");
		document.write("	<embed src=\"" + swfPath + "\" wmode=\"opaque\" FlashVars=\"" + strValues + "\" menu=\"false\" bgcolor=\"#ffffff\" ");
		document.write("quality=\"high\" width=\""+ intW +"\" height=\""+ intSH +"\" allowScriptAccess=\"sameDomain\" ");
		document.write("pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" />");
		document.write("</object>");
	}
}
