/***********滚动图片类***********
* 作者：袁琳(monkey-lin@163.com)
*
* 功能说明：显示网页滚动图片，可自定义样式，需配合AXJA类及COMMON类同时使用。
**********************************/
var move_Picture = function(){
	
	//********程序可控参数********//
	this.filePath="admin/application/Article_Pic.asp";	//调用XML路径
	this.actionName="";						//Action值
	this.showOBJ=null;						//显示对象
	this.ClassID=null;						//类别编号
	this.PageSize=5;						//每页显示文章条数
	this.imgUrl=new Array();				//私有对象(保存图片src)
	this.imgLink=new Array();				//私有对象(保存图片链接地址)
	this.imgTitle=new Array();				//私有对象(保存图片标题)
	this.Obj_time=null;					//私有对象(时间函数对象)
	this.OBJ_image=null;					//图片对象
	this.OBJ_title=null;					//标题对象
	
	//********基本样式参数********//
	this.typeInfo=1;						//切换按钮显示方位（1:top/2:bottom/3:left/4:right）
	this.listAtcPage="/list.html";		//显示文章列表的页面地址
	this.listClassID="ClassID";				//显示文章列表接收的类别编号名称
	this.showAtcPage="/list.html";		//显示具体文章的页面地址
	this.showAtcID="AtcID";					//显示具体文章页面接收的文章编号名称
	this.OBJ="pic";							//调用对象名
	this.btnBG=false;						//是否有按钮背景
	this.btn_Path="/image/";			//按钮图片路径
	this.btn_image="btnA";					//按钮图片前缀
	this.Name_btn="btnA";					//按钮图片对象

	//--显示效果参数--
	this.showTitle=false;		//是否显示文章标题
	this.titleType=1;			//文章标题前样式
	this.titlePic="";			//文章标题前图片（14*14）
	this.Titlenum=30;			//文章标题字数
	this.more=false;			//是否有“更多”
	
	this.adNum=0;				//初始图片
	this.pathTime=3000;			//设定图片延时时间
	this.openPath="_blank";		//图片链接打开方式("_blank":新窗口 "":本页面)
	this.pWidth=282;			//图片宽度
	this.pHeight=216;			//图片高度
}

//发送AJAX请求函数
move_Picture.prototype.sendRequest=function(){
	
	switch(this.typeInfo){
		
		//文章标题列表显示
		case 1:
			this.actionName="titlelist";
			break;
		default:break;
	}
	
	//参数组合
	//url：数据发送地址
	var url=this.filePath+"?Action="+this.actionName;
	if(this.ClassID!=null){url+="&ClassID="+this.ClassID;}
	url+="&PageSize="+this.PageSize;
	
	//发送AJAX请求
	/*this：对象本身*/
	var ajax=new Ajax();
	ajax.url=url;
	ajax.showObj=this.showOBJ;
	ajax.rtnFunObj	=this;
	ajax.rtnFunName	=this.getXML;
	//ajax.isDebug=true;
	ajax.send();
};

//XML获取处理函数
move_Picture.prototype.getXML=function(xmlDoc){
	
	//清空显示对象
	if(this.showOBJ!=null&&this.showOBJ!=""){this.showOBJ.innerHTML="";}
	
	//创建显示对象字符串
	var Sdate="";
	
	/*********通用样式设置*********/
	//设置文章标题样式
	var tType="";
	switch(this.titleType){
		case 1:
			tType="·";
			break;
		case 2:
			tType="→";
			break;
		default:break;
	}
	
	//var safeInfo = xmlDoc.getElementsByTagName("safeInfo");
	//if(this.checkSafeInfo(safeInfo)){
	if(true){
		var itemlist = xmlDoc.getElementsByTagName("itemlist");
		
		//数据显示
		if(itemlist.length>0){
			
			//构造显示列
			for(var i=0;i<itemlist.length;i++){
				
				//--------参数获取--------
				var Aid			=	itemlist[i].getElementsByTagName("ATitle")[0].attributes.getNamedItem("id").value;
				var ATitle		=	itemlist[i].getElementsByTagName("ATitle")[0].childNodes[0].nodeValue;	
				var ItemID     =   itemlist[i].getElementsByTagName("ATitle")[0].nodeValue;	
//				var Iid			=	itemlist[i].getElementsByTagName("AItem")[0].attributes.getNamedItem("id").value;
//				var AItem		=	itemlist[i].getElementsByTagName("AItem")[0].nodeValue;	
//				var Uid			=	itemlist[i].getElementsByTagName("AUser")[0].attributes.getNamedItem("id").value;
//				var AUser		=	itemlist[i].getElementsByTagName("AUser")[0].childNodes[0].nodeValue;	
//				var Cid			=	itemlist[i].getElementsByTagName("AClass")[0].attributes.getNamedItem("id").value;
//				var AClass		=	itemlist[i].getElementsByTagName("AClass")[0].childNodes[0].nodeValue;	
//				var Surl		=	itemlist[i].getElementsByTagName("ASource")[0].attributes.getNamedItem("url").value;
//				var ASource		=	itemlist[i].getElementsByTagName("ASource")[0].nodeValue;	
//				var AAuthor		=	itemlist[i].getElementsByTagName("AAuthor")[0].childNodes[0].nodeValue;	
				var APic_url	=	itemlist[i].getElementsByTagName("APic_url")[0].childNodes[0].nodeValue;	
//						var Adate		=	itemlist[i].getElementsByTagName("Adate")[0].childNodes[0].nodeValue;	
				
				//--------参数设置--------
				this.imgUrl[i]=APic_url;
				this.imgLink[i]=this.showAtcPage+"?ItemID="+ItemID+"&"+this.showAtcID+"="+Aid;
				this.imgTitle[i]=ATitle;
			}
			for(var j=itemlist.length;j<5;j++)
			{
				this.imgUrl[j]="image/tu.jpg";
				this.imgLink[j]="#";
				this.imgTitle[j]="";
			}
			//--------参数设置----------------------
			var bg_btn=""
			if(this.btnBG){bg_btn=""}
			
			//--------显示输出----------------------
			switch(this.typeInfo){
				
				//top
				case 1:
					Sdate+="<table border='0' cellpadding='0' cellspacing='0'>";
					Sdate+="<tr><td align='right'>";
					
					//显示按钮
					for(var b=0;b<this.PageSize;b++){
						Sdate+="<img id='"+this.Name_btn+"_"+b+"' src='"+this.btn_Path+this.btn_image+"_"+b+".jpg' border='0'  onClick='"+this.OBJ+".changimg("+(b)+")' style='cursor:hand;'>";
					}
					Sdate+="<tr><td align='center'><a href='javascript:"+this.OBJ+".goUrl();'>";
						Sdate+="<img src='"+this.imgUrl[0]+"' id='imgInit' style='FILTER: revealTrans(duration=1,transition=5); COLOR: #000000'";
						Sdate+=" height='"+this.pHeight+"' width='"+this.pWidth+"' border='0' onclick=''";
						Sdate+=" onmousemove='"+this.OBJ+".stopAd();' onmouseout='"+this.OBJ+".nextAd();'></a></td></tr>";
					if(this.showTitle){Sdate+="<tr><td align='center' id='imgTitle'>&nbsp;</td></tr>";}
					Sdate+="</td></tr></table>";
					break;
					
				//bottom
				case 2:
					Sdate+="<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
					Sdate+="<tr><td align='center'><a href='javascript:"+this.OBJ+".goUrl();'>";
						Sdate+="<img src='"+this.imgUrl[0]+"' id='imgInit' style='FILTER: revealTrans(duration=1,transition=5); COLOR: #000000'";
						Sdate+=" height='"+this.pHeight+"' width='"+this.pWidth+"' border='0' onclick=''";
						Sdate+=" onmousemove='"+this.OBJ+".stopAd();' onmouseout='"+this.OBJ+".nextAd();'></a></td></tr>";
					if(this.showTitle){Sdate+="<tr><td align='center' id='imgTitle'>&nbsp;</td></tr>";}
					Sdate+="<tr><td align='right'>";
					
					//显示按钮
					for(var b=0;b<this.PageSize;b++){
						Sdate+="<img id='"+this.Name_btn+"_"+b+"' src='"+this.btn_Path+this.btn_image+"_"+b+".jpg' border='0'  onClick='"+this.OBJ+".changimg("+(b)+")' style='cursor:hand;'>";
					}
					Sdate+="</td></tr></table>";
					break;
				default:break;
			}
			this.show(Sdate);
			this.OBJ_image=$("imgInit");			//图片对象
			this.OBJ_title=$("imgTitle");			//标题对象
			this.nextAd();
			
		//无记录显示结果
		}else{
			if(this.noResult!=""){this.show(this.noResult);}
		}
	}
};

//JS代码显示
move_Picture.prototype.show=function(HtmlData){
	if(this.showOBJ!=null&&this.showOBJ!=""){this.showOBJ.innerHTML+=HtmlData;}
};

//*******安全检测********
move_Picture.prototype.checkSafeInfo=function(Sxml){
	try{
		if(Sxml[0]){
			var state	=	Sxml[0].getElementsByTagName("state")[0].childNodes[0].nodeValue;
			var massage	= 	Sxml[0].getElementsByTagName("massage")[0].childNodes[0].nodeValue;
			if(state==1){
				return true;
			}else{
				this.show("[提示]"+massage);
				return false;
			}
		}else{
			return false;
		}
	}catch(e){this.show("[错误]安全验证信息错误，请检查！");return false; }
}

move_Picture.prototype.setTransition = function(){
	if(document.all){
		this.OBJ_image.filters.revealTrans.Transition=Math.floor(Math.random()*20);
		this.OBJ_image.filters.revealTrans.apply();
	}
};
	
move_Picture.prototype.playTran = function(){
	if(document.all){
		this.OBJ_image.filters.revealTrans.play();
	}
};

//自动变换
move_Picture.prototype.nextAd = function(){	

	//判断当前显示的图片
	if(this.adNum<this.PageSize-1){
		this.adNum++;
	}else{
		this.adNum=0;
	}
	
	//执行滚动
	if(document.all){
		this.setTransition();
		this.playTran();
	}
	
	//图片按钮变换
	for(var a=0;a<this.PageSize;a++){
		if(a==this.adNum){
			$(this.Name_btn+"_"+a).src=this.btn_Path+this.btn_image+"_"+this.adNum+"_click.jpg";
		}else{
			$(this.Name_btn+"_"+a).src=this.btn_Path+this.btn_image+"_"+a+".jpg";
		}
	}
	
	//标题及图片变换
	//alert("sdsa"+this.OBJ_image);
	this.OBJ_image.src=this.imgUrl[this.adNum];
	if(this.showTitle){this.OBJ_title.innerHTML=this.imgTitle[this.adNum].strLength(this.Titlenum);}
	this.Obj_time=setTimeout(this.OBJ+".nextAd()",this.pathTime);
};

//自动变换
move_Picture.prototype.stopAd = function(){
	clearTimeout(this.Obj_time);
};

//手动变换
move_Picture.prototype.changimg = function(m){

	this.adNum=m;
	
	//图片按钮变换
	for(var a=0;a<this.PageSize;a++){
		if(a==this.adNum){
			$(this.Name_btn+"_"+a).src=this.btn_Path+this.btn_image+"_"+this.adNum+"_click.jpg";
		}else{
			$(this.Name_btn+"_"+a).src=this.btn_Path+this.btn_image+"_"+a+".jpg";
		}
	}
	
	//标题及图片变换
	this.OBJ_image.src=this.imgUrl[this.adNum];
	if(this.showTitle){this.OBJ_title.innerHTML=this.imgTitle[this.adNum].strLength(this.Titlenum);}
};

//图片跳转
move_Picture.prototype.goUrl = function(){
	if(this.imgLink[this.adNum]!= ""){
		if (this.openPath!= ""){
			window.open(this.imgLink[this.adNum],this.openPath);
		}else{
			window.location.href=this.imgLink[this.adNum];
		}
	}
};

