/*
<div style="width:960;height:230px;" id="slide_div">
<xml id=slide_xml onreadystatechange="focusAd(this)">
<root loop_time="5" hide_btn_text="1" effect_index="-1" duration="0.6" title_panel_id="" content_panel_id="slide_div">
<record subject="xxx" btn_text="1" content="" url=""></record>
</root>
</xml>
</div>
foxfire浏览器在body onload中加入<BODY style="margin:0px;padding:0px;text-align:center" align=center onload="focusAd(document.getElementById('slide_xml'));">
南京集思鹏信息技术有限公司 版权所有
*/
////////////////////////////////////xml回调函数
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="#F70";//button下划线on的颜色
var buttonLineOff="#666";//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:0;left:0' width='100%' height='100%'><tr><td align=center 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){
		contentIndex=scrollAdObj.medias.length;
		scrollAdObj.medias[scrollAdObj.medias.length]=mediaobj;
		if(!mediaobj.htmlObj)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:left";
				var pos = scrollAdObj.medias[contentIndex].content.lastIndexOf(".");

				if(pos<scrollAdObj.medias[contentIndex].content.length-5){//html code
					if(scrollAdObj.medias[contentIndex].href!="")media_htmlObject.href = scrollAdObj.medias[contentIndex].href;
					media_htmlObject.target = "_blank";
					media_htmlObject.innerHTML=scrollAdObj.medias[contentIndex].content;
				}else{
					var ext_name=scrollAdObj.medias[contentIndex].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=\""+scrollAdObj.medias[contentIndex].content+"\" />";
						tmphtml+="<param name=\"quality\" value=\"high\" />";
						tmphtml+="<embed src=\""+scrollAdObj.medias[contentIndex].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 = scrollAdObj.medias[contentIndex].content;
						img.border = "0";
						img.style.cssText = "width:"+scrollAdObj.width+"px;height:"+ scrollAdObj.height+"px";
						if(scrollAdObj.medias[contentIndex].href!="")media_htmlObject.href = scrollAdObj.medias[contentIndex].href;
						media_htmlObject.target = "_blank";
						media_htmlObject.appendChild(img);
					}
				}
				mediaobj.htmlObj=media_htmlObject;
				mediaobj.loaded=true;
			}
		},10);
	};
	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;
	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:0;left:0;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;right:0;bottom:0;text-align:right;padding:2 0 0 0;height:14;font-size:14px;";
		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="padding:0 7 0 7;height:14;font-size:14px;text-align:center;color:white;cursor:hand;border-top:1 #999 solid;border-left:1 #999 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){
		var tmpobj11=this;
		this.showLoading(true);
		return setTimeout(function(){tmpobj11.showContent(contentIndex)},200);
	}
	the_content_disp_div_object.appendChild(this.medias[contentIndex].htmlObj);
	this.showLoading(false);
	if(this.browser_ver==1&&the_content_disp_div_object.filters){
		var do_transition=(effect_index1>-1?Math.min(effect_index1,this.transitions.length-1):Math.floor(Math.random() * this.transitions.length));
		the_content_disp_div_object.style.filter=this.transitions[parseInt(do_transition)].replace("(duration)",duration1);
		if(the_content_disp_div_object.filters[0]){
			the_content_disp_div_object.filters[0].Apply();
                        the_content_disp_div_object.style.display="";
			the_content_disp_div_object.style.visibility="visible";
			the_content_disp_div_object.filters[0].play();
		}else{
                        the_content_disp_div_object.style.visibility="visible";
                        the_content_disp_div_object.style.display="";
                }
	}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;
		for(var i=0;i<this.medias.length;i++)if(i!=contentIndex)document.getElementById('link_'+this.autoid+'_'+i).style.background=buttonLineOff;
	}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++){
				ad.addMedia(new Media(nodes[i].getAttribute("subject"),nodes[i].getAttribute("btn_text"),nodes[i].getAttribute("content"),nodes[i].getAttribute("url")));
			}  
			ad.play();
		}
	}catch(e){};
}
