/*
2010年11月19日最后修改版本，注意record标记对必须完整，否则程序不能正常工作
统一使用body onload事件触发此控件初始化显示
*/
var isIE = (navigator.appName=="Microsoft Internet Explorer");

function parseXML(st){
	if(isIE){
		var result = new ActiveXObject("Microsoft.XMLDOM");
		result.async=false;
		result.loadXML(st);
	}else if (document.implementation &&document.implementation.createDocument){//FF
		result= document.implementation.createDocument("","",null); 
		result.async=false;
		result.loadXML(st);
	}else{
		alert('浏览器不支持脚本,无法加载XML文件');
	} 
	try{result.setProperty("SelectionLanguage","XPath");}catch(exp){}
	return result;
}
/////////////////////////////////////
var GetNodeValue = function(obj){
	var str = "";
	if(window.ActiveXObject){ //IE
		str = obj.text;
	}else{ //Mozilla
		try{
			str = obj.childNodes[0].nodeValue;
		}catch(ex){
			str = "";
		}
	}
	return str;
}
if(document.implementation && document.implementation.createDocument){
	XMLDocument.prototype.loadXML = function(xmlString){
		var childNodes = this.childNodes;
		for (var i = childNodes.length - 1; i >= 0; i--)this.removeChild(childNodes[i]);
		var dp = new DOMParser();
		var newDOM = dp.parseFromString(xmlString, "text/xml");
		var newElt = this.importNode(newDOM.documentElement, true);
		this.appendChild(newElt);
	};
	// check for XPath implementation
	if(document.implementation.hasFeature("XPath", "3.0")){
		// prototying the XMLDocument
		XMLDocument.prototype.selectNodes = function(cXPathString, xNode){
			if(!xNode){xNode = this;}
			var oNSResolver = this.createNSResolver(this.documentElement);
			var aItems = this.evaluate(cXPathString, xNode, oNSResolver,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			var aResult = [];
			for( var i = 0; i< aItems.snapshotLength; i++){
				aResult[i] = aItems.snapshotItem(i);
			}
			return aResult;
		}
		// prototying the Element
		Element.prototype.selectNodes = function(cXPathString){
			if(this.ownerDocument.selectNodes){
				return this.ownerDocument.selectNodes(cXPathString, this);
			}else{
				throw "For XML Elements Only";
			}
		}
	}
	// check for XPath implementation
	if(document.implementation.hasFeature("XPath", "3.0")){
		// prototying the XMLDocument
		XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode){
			if(!xNode){ xNode = this;}
			var xItems = this.selectNodes(cXPathString, xNode);
			if(xItems.length > 0){
				return xItems[0];
			}else{
				return null;
			}
		}
		// prototying the Element
		Element.prototype.selectSingleNode = function(cXPathString){ 
			if(this.ownerDocument.selectSingleNode){
				return this.ownerDocument.selectSingleNode(cXPathString, this);
			}else{
				throw "For XML Elements Only";
			}
		}
	}
}
///////////////////////////////////////////////////////////////////////////////////
var buttonLineOn="#fcb445";//button下划线on的颜色
var buttonLineOff="#fef1d1";//button下划线off的颜色
var JspsoftAutoContentSlider_autoid=0;

function Media(mtitle1,btntext1,content1,mhref1){
	this.title=mtitle1;
	this.btn_text=btntext1;
	this.content=content1;
	this.href=mhref1;
	this.loaded=false;
	this.htmlObj=null;
}
function AutoContentSlider(contentPanel1,titPanel1,loop_time1,hide_btn_text1,effect_index1,duration1){
	if(!contentPanel1)return;
	try{effect_index1=parseInt(effect_index1);}catch(exp){effect_index1=-1;}
	try{hide_btn_text1=parseInt(hide_btn_text1);}catch(exp){hide_btn_text1=0;}
	try{loop_time1=parseInt(loop_time1);}catch(exp){loop_time1=-1;}
	try{duration1=parseFloat(duration1);}catch(exp){duration1=0.5;}
	this.medias=new Array();
	this.showContentIndex=-1;
	this.contentTimer=null;
	this.loop_time=3000;
	try{this.loop_time=loop_time1*1000;}catch(exp){}
	this.autoid=JspsoftAutoContentSlider_autoid++;
	this.browser_ver=1;
	this.contentPanel=contentPanel1;
	this.contentPanel.style.position="relative";
	this.contentPanel.innerHTML="<table id="+("jspsoft_init_table_"+this.autoid)+" style='position:absolute;z-index:1000;top:0px;right:0px' width='100%' height='100%'><tr><td align=right valign=middle style='color:white;font-size:16px'>缓冲中...<br><img src='/images/loading3.gif' align=absmiddle></td></tr></table>";
	this.titlePanel=titPanel1;
	this.width=parseInt(this.contentPanel.offsetWidth);
	this.height=parseInt(this.contentPanel.offsetHeight);
	var scrollAdObj=this;
	this.addMedia=function(mediaobj){
		scrollAdObj.medias[scrollAdObj.medias.length]=mediaobj;
		if(!mediaobj.htmlObj&&scrollAdObj.medias.length<2)this.loadMedia(mediaobj,scrollAdObj.medias.length);
	};
	this.loadMedia=function(mediaobj,contentIndex){
			setTimeout(new function(){
				var pos = mediaobj.content.lastIndexOf(".");
				if(pos<=mediaobj.content.length-5){
					var contentId = "__fContent"+contentIndex+"_"+scrollAdObj.autoid;
					var media_htmlObject=document.createElement("A");
					media_htmlObject.id = contentId;
					media_htmlObject.style.cssText = "display:block;width:"+scrollAdObj.width+"px;height:"+ scrollAdObj.height+"px;text-align:right";
					var pos = mediaobj.content.lastIndexOf(".");
					if(pos<mediaobj.content.length-5){//html code
						if(mediaobj.href!="")media_htmlObject.href = mediaobj.href;
						media_htmlObject.target = "_blank";
						media_htmlObject.innerHTML=mediaobj.content;
					}else{
						var ext_name=mediaobj.content.substr(pos+1).toLowerCase();
						if(ext_name=="swf"){
							var tmphtml= "<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=\""+scrollAdObj.width+"\" height=\""+scrollAdObj.height+"\">";
							tmphtml+="<param name=\"movie\" value=\""+mediaobj.content+"\" />";
							tmphtml+="<param name=\"quality\" value=\"high\" />";
							tmphtml+="<embed src=\""+mediaobj.content+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+scrollAdObj.width+"\" height=\""+scrollAdObj.height+"\"></embed>";
							tmphtml+="</object>";
							media_htmlObject.innerHTML=tmphtml;
						}else if(ext_name=="jpg"||ext_name=="gif"||ext_name=="png"||ext_name=="hawa"){
							var img = new Image();
							img.src =mediaobj.content;
							img.border = "0";
							// img.style.cssText = "width:"+scrollAdObj.width+";height:"+ scrollAdObj.height;
							if(mediaobj.href!="")media_htmlObject.href = mediaobj.href;
							media_htmlObject.target = "_blank";
							media_htmlObject.appendChild(img);
						// media_htmlObject.innerHTML="<img src='"+mediaobj.content+"' border=0>";
						}
					}
					mediaobj.htmlObj=media_htmlObject;
					mediaobj.loaded=true;
				}
			},scrollAdObj.medias.length<2?10:3000);
	}
	this.play=function(){scrollAdObj.stop();scrollAdObj.showContent(0);scrollAdObj.contentTimer=setInterval(function(){scrollAdObj.showNext();},this.loop_time)};
	this.stop=function(){clearInterval(scrollAdObj.contentTimer);scrollAdObj.contentTimer = null;};
	this.showLoading=function(showit11){var initTable=document.getElementById("jspsoft_init_table_"+this.autoid);if(initTable)initTable.style.display=(showit11?"":"none");}
	this.showNext=function(){this.showContent(this.showContentIndex+1);};
	this.showPreview=function(){this.showContent(this.showContentIndex-1);};
	this.setContentPanel=function(titPanel1){this.titlePanel=titPanel1;};
	this.setTitlePanel=function(titPanel1){this.titlePanel=titPanel1;};
	this.transitions = ["progid:DXImageTransform.Microsoft.Fade(duration=(duration))",
	"progid:DXImageTransform.Microsoft.Blinds(Duration=(duration),bands=20)",
	"progid:DXImageTransform.Microsoft.Checkerboard(Duration=(duration),squaresX=20,squaresY=20)",
	"progid:DXImageTransform.Microsoft.Strips(Duration=(duration),motion=rightdown)",
	"progid:DXImageTransform.Microsoft.Barn(Duration=(duration),orientation=vertical)",
	"progid:DXImageTransform.Microsoft.GradientWipe(duration=(duration))",
	"progid:DXImageTransform.Microsoft.Iris(Duration=(duration),motion=out)",
	"progid:DXImageTransform.Microsoft.Wheel(Duration=(duration),spokes=12)",
	"progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=(duration))",
	"progid:DXImageTransform.Microsoft.RadialWipe(Duration=(duration),wipeStyle=clock)",
	"progid:DXImageTransform.Microsoft.RandomBars(Duration=(duration),orientation=vertical)",
	"progid:DXImageTransform.Microsoft.Slide(Duration=(duration),slideStyle=push)",
	"progid:DXImageTransform.Microsoft.RandomDissolve(Duration=(duration),orientation=vertical)",
	"progid:DXImageTransform.Microsoft.Spiral(Duration=(duration),gridSizeX=40,gridSizeY=40)",
	"progid:DXImageTransform.Microsoft.Stretch(Duration=(duration),stretchStyle=push)",
	"special case"];
	try{new ActiveXObject("DXImageTransform.Microsoft.revealTrans");}catch(exp){this.browser_ver=2;};
	this.showContent=function(contentIndex){
		if(contentIndex>this.medias.length-1||contentIndex<0)contentIndex = 0;
		if(!this.medias[contentIndex] || contentIndex==this.showContentIndex)return false;
		if(!this.medias[contentIndex].loaded)this.loadMedia(this.medias[contentIndex],contentIndex);
		var the_content_disp_div_object = document.getElementById("jspsoft_content_img"+this.autoid);
		if(!the_content_disp_div_object){
			the_content_disp_div_object=document.createElement("DIV");
			the_content_disp_div_object.id="jspsoft_content_img"+this.autoid;
			the_content_disp_div_object.style.cssText="position:absolute;z-index:9;top:0px;left:0px;width:"+this.width+"px;height:"+ this.height+"px;background:transparent;visibility:hidden";
			the_content_disp_div_object.oncontextmenu=function(){return false};
			the_content_disp_div_object.onselectstart=function(){return false};
			the_content_disp_div_object.ondragstart=function(){return false};
			this.contentPanel.appendChild(the_content_disp_div_object);
		}
		var flash_title = this.titlePanel;
		var nav_btn_divObj=document.getElementById("nav_btn_div"+this.autoid);
		if(hide_btn_text1!=1&&!nav_btn_divObj){
			nav_btn_divObj= document.createElement("DIV");
			nav_btn_divObj.id="nav_btn_div"+this.autoid;
			nav_btn_divObj.style.cssText="position:absolute;z-index:9999;height:14px;line-height:14px;right:0px;bottom:5px;text-align:right;font-size:9px;";
			var funObj=this;
			for(var i=0;i<this.medias.length;i++){
				var aobj=document.createElement("A");
				aobj.id="link_"+this.autoid+"_"+i;
				aobj.innerHTML=this.medias[i].btn_text;
				aobj.idx=i;
				aobj.style.cssText="display:inline;margin:0px 2px 0px 2px;padding:0px 7px 0px 7px;height:14px!important;height:16px;background:#fef1d1;font-size:9px;text-align:center;color:#d74b00;cursor:hand;border:1px #f37504 solid;";
				nav_btn_divObj.appendChild(aobj);
				aobj.onmouseover=function(){funObj.stop();funObj.showContent(this.idx);};
				aobj.onmouseout=function(){funObj.stop();funObj.contentTimer=setInterval(function(){funObj.showNext();},funObj.loop_time);};
			}
			this.contentPanel.appendChild(nav_btn_divObj);
		}
		if(the_content_disp_div_object.childNodes.length){
			the_content_disp_div_object.removeChild(the_content_disp_div_object.childNodes[0]);
			the_content_disp_div_object.style.visibility="hidden";
		}
		if(!this.medias[contentIndex].loaded){
			this.showLoading(true);
			this.loadMedia(this.medias[contentIndex],contentIndex);
			return setTimeout(function(){scrollAdObj.showContent(contentIndex)},100);
		}
		the_content_disp_div_object.appendChild(this.medias[contentIndex].htmlObj);
		this.showLoading(false);
		
		if(this.browser_ver==1&&the_content_disp_div_object.filters){
			with(the_content_disp_div_object){
				var do_transition=(effect_index1>-1?Math.min(effect_index1,this.transitions.length):Math.floor(Math.random() * this.transitions.length));
				style.filter=this.transitions[do_transition].replace("(duration)",duration1);
				if(filters[0]){
					filters[0].Apply();
					style.visibility="visible";
					filters[0].play();
				}else style.visibility="visible";
			}
		}else{
			the_content_disp_div_object.style.visibility="visible";
		}
		var flash_show_ctl_msg = document.getElementById("flash_show_ctl_msg");
		if(flash_show_ctl_msg)flash_title=flash_show_ctl_msg;
		if(flash_title){
			flash_title.href = this.medias[contentIndex].href;
			flash_title.innerHTML = this.medias[contentIndex].title;
			flash_title.title = this.medias[contentIndex].title;
		}
		try{
			document.getElementById('link_'+this.autoid+'_'+contentIndex).style.background=buttonLineOn;
                        document.getElementById('link_'+this.autoid+'_'+contentIndex).style.color="white";
			for(var i=0;i<this.medias.length;i++){
				if(i!=contentIndex){
				      document.getElementById('link_'+this.autoid+'_'+i).style.background=buttonLineOff;
                                      document.getElementById('link_'+this.autoid+'_'+i).style.color="#d74b00";
                                }
                        }
		}catch(exp){}
		this.showContentIndex = contentIndex;
		return true;
	};
}
////////////////////////////////////
function getAttribute(name,list){
	if(!list)return false;
	for(var i=0;i<list.length;i++){
		if(list[i].nodeName.toLowerCase()==name.toLowerCase()){
			return list[i].nodeValue;
		}
	}
	return false; 
}
function focusAd(xml_element){
	try{
		if(isIE){
			//if(event.type!="readystatechange")return;
			if(xml_element.readyState!='complete')return;
			if(xml_element.parseError.errorCode!=0)return alert('XML解析错误：'+xml_element.parseError.reason);
			var nodes=xml_element.selectNodes('/root/record');
			if(nodes==null)return alert('数据对象获取错误,表单初始化失败!');
			var rootObj=xml_element.selectSingleNode("/root");
			var titlePanel11Obj=document.getElementById(rootObj.getAttribute("title_panel_id"));
			var contentPanel11Obj=null;
			try{contentPanel11Obj=xml_element.parentElement;}catch(ex11){}
			if(!contentPanel11Obj)contentPanel11Obj=document.getElementById(xml_element.getAttribute("content_panel_id"));
			var ad=new AutoContentSlider(contentPanel11Obj,titlePanel11Obj,rootObj.getAttribute("loop_time"),rootObj.getAttribute("hide_btn_text"),rootObj.getAttribute("effect_index"),rootObj.getAttribute("duration"));
			for(var i=0;i<nodes.length;i++){
				ad.addMedia(new Media(nodes[i].getAttribute("subject"),nodes[i].getAttribute("btn_text"),nodes[i].getAttribute("content"),nodes[i].getAttribute("url")));
			}
			ad.play();
		}else{
 			var xmlobj=parseXML("<?xml version=\"1.0\" encoding=\"gb2312\"?>"+xml_element.innerHTML).documentElement;
			var nodes=xmlobj.selectNodes("/root/record");
			var titlePanel11Obj=document.getElementById(xmlobj.getAttribute("title_panel_id"));
			var contentPanel11Obj=null;
			try{contentPanel11Obj=xml_element.parentElement;}catch(ex11){}
			if(!contentPanel11Obj)contentPanel11Obj=document.getElementById(xmlobj.getAttribute("content_panel_id"));
			var ad=new AutoContentSlider(contentPanel11Obj,titlePanel11Obj,xmlobj.getAttribute("loop_time"),xmlobj.getAttribute("hide_btn_text"),xmlobj.getAttribute("effect_index"),xmlobj.getAttribute("duration"));
			for(var i=0;i<nodes.length;i++){
				var mItem=new Media(nodes[i].getAttribute("subject"),nodes[i].getAttribute("btn_text"),nodes[i].getAttribute("content"),nodes[i].getAttribute("url"));
				ad.addMedia(mItem);
			}
			ad.play();
		}
	}catch(e){}
}

