
var appGallery=new Object();
appGallery._width=120;
appGallery._height=90;
appGallery._total=-1;
appGallery._size=2;
appGallery._sizes=2;
appGallery._i=0;
appGallery._isauto=null;
appGallery._space=0;
appGallery._autoplay=null;
appGallery.aryViewPic=new Array();

appGallery.setAutoStart=function(strBool) { this._isauto=strBool; }

appGallery.doPicLoad=function(strX,strS,strAuto)
{
	if (isInt(strX)) this._size=strX;
	if (isInt(strS) && strS>0) this._space=strS;
	if (typeof(strAuto)!="undefined") this._isauto=strAuto;
	if (this._isauto==null) this._isauto=(this._space>0) ? true : false;
	this._sizes=this._size*2+1;
	this._total=this.aryViewPic.length-1;
	this._i=1;
	dcs.form.setValue("pic_play_space",strS);
	dcs.form.getElement("pic_play_isauto").checked=this._isauto;
	this.doPicThumb(this._i);
	appGallery.doPicCheck(this._i);
	if (this._isAutoStart) this.doPicAutoLoad();
}

appGallery.doPicAutoLoad=function()
{
	if (this._autoplay!=null) window.clearTimeout(this._autoplay);
	if (this._isauto && this._space>0) this._autoplay=window.setTimeout("appGallery.doPicAutoPlay()",this._space*1000);
}

appGallery.doPicAutoPlay=function()
{
	if (!this._isauto || this._space<1) return false;
	var tmpI=this._i+1;
	if (tmpI>this._total) tmpI=1;
	this.doPicThumb(tmpI);
	this.doPicCheck(tmpI);
	this.doPicAutoLoad();
}

appGallery.doPicisAuto=function()
{
	this._isauto=(dcs.form.getValue("pic_play_isauto")=="yes") ? true : false;
	if (this._isauto) this.doPicAutoSpace();
	this.doPicAutoLoad();
}

appGallery.doPicAutoSpace=function()
{
	this._space=dcs.form.getValue("pic_play_space");
	if (!isInt(this._space)) this._space=0;
	this._isauto=(this._space>0) ? true : false;
	this.doPicAutoLoad();
}

appGallery.doPicThumb=function(strI)
{
	if (strI>this._total) return false;
	this._i=strI;
	var tmpBegin=strI-this._size;
	if (tmpBegin<1) tmpBegin=1;
	var tmpEnd=tmpBegin+(this._sizes-1);
	if (tmpEnd>this._total) tmpEnd=this._total;
	var _html="";
	var _aryPic;
	if (strI>1)
	{
		_html+="<span class=\"paging first\"><img class=\"icon hand\" src=\""+dcs.config.getURL("skin")+"images/common/paging/ico_first.gif\" alt=\"第一幅\" onclick=\"javascript:appGallery.doPicThumb(1);appGallery.doPicCheck(1);\"></span>";
		_html+="<span class=\"paging prev\"><img class=\"icon hand\" src=\""+dcs.config.getURL("skin")+"images/common/paging/ico_prev.gif\" alt=\"上一幅\" onclick=\"javascript:appGallery.doPicThumb("+(strI-1)+");appGallery.doPicCheck("+(strI-1)+");\"></span>";
	}
	for (var i=tmpBegin;i<=tmpEnd;i++ )
	{
		_aryPic=this.aryViewPic[i];
		_html+="<span class=\""+((i==strI) ? "thumbs" : "thumb")+"\"><a class=\"hand\" onclick=\"javascript:appGallery.doPicThumb("+i+");appGallery.doPicCheck("+i+");\">"+appCommon.toUploadPic(_aryPic[2],this._width,this._height,0.5,0)+"</a></span>";
	}
	if (strI<this._total)
	{
		_html+="<span class=\"paging next\"><img class=\"icon hand\" src=\""+dcs.config.getURL("skin")+"images/common/paging/ico_next.gif\" alt=\"下一幅\" onclick=\"javascript:appGallery.doPicThumb("+(strI+1)+");appGallery.doPicCheck("+(strI+1)+");\"></span>";
		_html+="<span class=\"paging last\"><img class=\"icon hand\" src=\""+dcs.config.getURL("skin")+"images/common/paging/ico_last.gif\" alt=\"最后一幅\" onclick=\"javascript:appGallery.doPicThumb("+this._total+");appGallery.doPicCheck("+this._total+");\"></span>";
	}
	if ($("PicBody")) $("PicBody").innerHTML=_html;
	if ($("PicBody0")) $("PicBody0").innerHTML=_html;
}

appGallery.doPicCheck=function(strI)
{
	if (strI>this._total) return false;
	this._i=strI;
	_aryPic=this.aryViewPic[strI];
	var tmpAry=_aryPic[3].split(".");
	var tmpPostfix=(tmpAry.length>1) ? tmpAry[tmpAry.length-1] : "";
	//alert(tmpPostfix);
	var tmpPicMain=$("PicMain");
	var tmpFlashMain=$("FlashMain");
	if (tmpFlashMain && tmpPostfix=="swf")
	{
		tmpPicMain.style.display="none";
		tmpFlashMain.style.display="";
		dcs.init.loadLib("player");
		var Per=new VDCS.libPlayer();
		Per.setType("flash");
		Per.setSize(400,300);
		Per.setID("swf_FlashMain");
		Per.setName("swf_FlashMain");
		Per.setURL(appCommon.toUploadPic(_aryPic[3],null,null,1,-1));
		Per.doParse();
		tmpFlashMain.innerHTML=Per.getHTML();
	}
	else
	{
		if (tmpFlashMain)
		{
			tmpFlashMain.style.display="none";
			tmpFlashMain.innerHTML="";
		}
		tmpPicMain.style.display="";
		var tmpImg=$("img_PicMain");
		var tmpImgHTML="<img class=\""+tmpImg.className+"\" border=\"0\" id=\""+tmpImg.id+"\" onclick=\"javascript:appGallery.doPicView();\">";
		tmpPicMain.innerHTML=tmpImgHTML;
		tmpImg=$("img_PicMain");
		tmpImg.src=appCommon.toUploadPic(_aryPic[3],this._width,this._height,1,-1);
		//dbg.obj(tmpImg);
		setTimeout("appGallery.doPicResize();",500);
	}
	var tmpTopic=$("pic_topic"); if (tmpTopic) $("pic_topic").innerHTML=_aryPic[1];
	var tmpNow=$("pic_now"); if (tmpNow) tmpNow.innerHTML=strI;
	var tmpTotal=$("pic_total"); if (tmpTotal) tmpTotal.innerHTML=this._total;
	var tmpeExplain=$("pic_explain"); if (tmpeExplain) tmpeExplain.innerHTML=_aryPic[4];
	this.doPicAutoLoad();
	return false;
}

appGallery.doPicResize=function()
{
	var tmpDiv=$("PicMain");
	var tmpMaxWidth=tmpDiv.clientWidth-15;
	var tmpImg=$("img_PicMain");
	dcs.images.doResize(tmpImg,0,0,"");
}

appGallery.doPicView=function()
{
	dcs.images.doOpen($("img_PicMain"));
}

