
function PhotosLiding(selfname,bigphotoarea,smallphotoarea) {
	this.selfname=selfname;
	this.smallphotoarea=document.getElementById(smallphotoarea);
	this.bigphotoarea=document.getElementById(bigphotoarea);
	this.imgarr=[];
	this.big={maxwidth:600,maxheight:600};
	this.small={showcnt:5,maxwidth:120,maxheight:84};
	this.selectIndex=0;
	this.startIndex=0;
	this.conf ={
			upimg:"img/shang.gif",
			downimg:"img/xia.gif"
	};
}
PhotosLiding.prototype={
	add:function(imageurl,title)  {
		this.imgarr[this.imgarr.length]={url:imageurl,title:title}
	},
	showlist:function() {
		
		var outstr='<div class="div_shang"><a href="javascript:'+this.selfname+'.up('+this.selfname+')"><img src="'+this.conf.upimg+'" /></a></div>'+
		'<div  class="slidingList_three_div1_img"><ul>';
		
		outstr+="";
		if (this.imgarr!=null && this.imgarr.length>0 ) {
			var len=this.imgarr.length;

			if(len < this.small.showcnt){
				var j = len;
			} else {
				var j = this.small.showcnt;
			}

			for(var i=0;i<j ;i++) {
				var now=(this.startIndex+i)%this.imgarr.length;
				var img=this.imgarr[( this.startIndex+i )%this.small.showcnt];
				
				image=this.__createSmallImg(img);
				
				 outstr+='<li id="PhotosLiding_img_'+i+'"><a href="javascript:'+this.selfname+'.show('+now+','+this.selfname+')">'+image+'</a></li>';
			}
		}	
		outstr+='</ul></div><div class="div_xia"><a href="javascript:'+this.selfname+'.down('+this.selfname+')"><img src="'+this.conf.downimg+'" /></a></div>';
		
		this.smallphotoarea.innerHTML=outstr;
		
	},
	
	show:function(ind,pl) {
		pl.selectIndex=ind;
		var img=this.imgarr[ind];
		
		
		var image=document.createElement("div");
		image.innerHTML=pl.__createBigImg(img);
		pl.bigphotoarea.innerHTML="";
		pl.bigphotoarea.appendChild(image);
		if (img.title!=undefined && img.title!=null && img.title!="") {
			var ta=document.createElement("div");
			ta.className="bigphototitle";
			ta.innerHTML=img.title;
			pl.bigphotoarea.appendChild(ta);
		}
		$('#'+pl.bigphotoarea.id).show("slow");
	},
	up:function(pl) {
		if (pl.imgarr.length<=pl.small.showcnt) {
			return;
		}
		pl.startIndex=pl.startIndex-1;
		if (pl.startIndex<0) {
			pl.startIndex=pl.imgarr.length;
		}
		pl.__showlist();
	},
	down:function(pl) {
		if (pl.imgarr.length<=pl.small.showcnt) {
			return;
		}
		pl.startIndex=pl.startIndex+1;
		if (pl.startIndex>=pl.imgarr.length) {
			pl.startIndex=0;
		}
		pl.__showlist();
	}
	,
	__showlist:function() {
		
		
		if (this.imgarr!=null && this.imgarr.length>0 ) {
			var len=this.imgarr.length;
			for(var i=0;i<this.small.showcnt ;i++) {
				var now=(this.startIndex+i)%this.imgarr.length;
				var img=this.imgarr[now];
				
				image=this.__createSmallImg(img);
				 $("#PhotosLiding_img_"+i).html('<a href="javascript:'+this.selfname+'.show('+now+','+this.selfname+')">'+image+'</a>');
			}
		}	
	
		
	},
	
	imgload:function(obj) {
		var w=obj.width;
		var h=obj.height;
		
		var maxwidth=obj.getAttribute("maxwidth");
		var maxheight=obj.getAttribute("maxheight");
		var wr=w/maxwidth;
		var hr=h/maxheight;
		if (wr>hr ) {
			w=w>maxwidth?w/wr:w;
			h=w>maxwidth?h/wr:h;
		} else  {
			w=h>maxheight?w/hr:w;
			h=h>maxheight?h/hr:h;
		}
		obj.width=maxwidth;
		obj.height=maxheight;
	}
	,
	__createSmallImg:function (img) {
		//return '<img src="'+img.url+'"  border="0" width="'+this.small.maxwidth+'" height="'+this.small.maxheight+'" maxwidth="'+this.small.maxwidth+'" maxheight="'+this.small.maxheight+'" onload="'+this.selfname+'.imgload(this)"/>'
		return '<img src="'+img.url+'"  border="0" width="120" />'
	}
	,
	__createBigImg:function (img) {
		
		//return '<img src="'+img.url+'" border="0" maxwidth="'+this.big.maxwidth+'" maxheight="'+this.big.maxheight+'"  onload="'+this.selfname+'.imgload(this)"/>'
		return '<img src="'+img.url+'" border="0" width="600" height="100%" />'
	}
	
}

