/*
南京集思鹏信息技术有限公司 版权所有
*/
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){
	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;

		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+";height:"+ scrollAdObj.height;
						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.all("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.insertBefore(the_content_disp_div_object);
		}

		var flash_title = this.titlePanel;//document.getElementById("flash_title");	

		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.insertBefore(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){
			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;
			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;
	};
}
////////////////////////////////////xml回调函数
function focusAd(xmlobj){
	try{
		if(xmlobj.readyState!='complete')return;
		if(document.readyState!="complete")return setTimeout(function(){focusAd(xmlobj)},200);
		if(xmlobj.parseError.errorCode!=0)return alert('XML解析错误：'+xmlobj.parseError.reason);
		var nodes=xmlobj.selectNodes('/root/record');
		if(nodes==null)return alert('数据对象获取错误,表单初始化失败!');
		var rootObj=xmlobj.selectSingleNode("/root");
		var titlePanel11Obj=document.getElementById(rootObj.getAttribute("title_panel_id"));
		var ad=new AutoContentSlider(xmlobj.parentElement,titlePanel11Obj==""?null: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();
	}catch(e){alert(e.description)};
}