 var OLGgalery2=Class.create();
 
 OLGgalery2.prototype ={
 	
	mainDiv:'',
	imListUl:'',
	divImgList:'',
	scrollDiv:'',
	bigImgNavMenu:'',
	NavMenuSpan:'',
	textDiv:'',
	bgDiv:'',
	bigImg:'',
	bigImgDiv:'',
	projectID:'',
	
	bgAlert:'#262626',
	bgOpacity:'0.8',
	parentElement:'',
	imgList:[],
	imgMainSrc:[],
	imgCount:0,
	curImgOpen:0,
	phpthumb:PHPTHUMB,
	closeImgSrc:'/img/gal/close3.gif',
	nextImgSrc:'/img/gal/rightstr3.gif',
	backImgSrc:'/img/gal/leftstr3.gif',
	loadingImg:'/img/gal/loadingbar.gif',
	bigImgVisibled:false,
	loadingImgVisibled:false,
	DragStarted:false,
	mX:0,
	mY:0,
	mX1:0,
	mY1:0,
	mPos:[],
	scrollBarX:0,
	imListUlWidth:0,
	initialize:function(){
		this.loadingImg=new Image(100,100);
		this.loadingImg.src=loadingBarUrl;
		//alert(loadingBarUrl);
		//this.imL
		if (typeof arguments[0]=='string')
			this.parentElement=$(arguments[0])
		else
			this.parentElement=arguments[0];
		this.options=Object.extend({
			width:573,
			height:100,
			scrollBarHeight:19,
			imgWidth:100,
			imgHeight:100,
			imgPadding:5
		},arguments[1] || '');
		
		this.MouseDown=this.initDrag.bindAsEventListener(this);
		this.MouseMove=this.moveDrag.bindAsEventListener(this);
		this.MouseUp=this.endDrag.bindAsEventListener(this);
		
		this.mainDiv=cr('div');
		
		this.parentElement.appendChild(this.mainDiv);
		
		this.bgDiv=cr('div');
		this.bgDiv.style.display='none';
		this.bgDiv.style.zIndex='99';
		
		this.bigImg=cr('img');
		this.bigImg.id='bimg';
		this.bigImg.style.position='absolute';

		this.closeImg=cr('img');
		this.closeImg.src=this.closeImgSrc;
		this.closeImg.style.position='absolute';
		this.closeImg.style.right='5px';
		this.closeImg.style.width='17px';
		this.closeImg.style.height='22px';
		this.closeImg.style.zIndex='350';
		//this.closeImg.style.top='0px';
		this.closeImg.style.bottom='2px';
		this.closeImg.style.display='none';
		this.closeImg.style.cursor='pointer';
		
		this.textDiv=cr('div');
		this.textDiv.style.zIndex='100';
		//this.textDiv.style.position='absolute';
		this.textDiv.style.width='100%';
		//this.textDiv.style.height='20px';
		//this.textDiv.style.bottom='0px';
		//this.textDiv.style.left='90px';
		this.textDiv.style.align='center';
		
		this.nextImg=cr('img');
		this.nextImg.src=this.nextImgSrc;
		this.nextImg.style.zIndex='999';
		
		//this.nextImg.style.position='absolute';
		//this.nextImg.style.right='5px';
		//this.nextImg.style.bottom='49%';
		this.nextImg.style.display='none';
		this.nextImg.style.cursor='pointer';
		
		

		
		this.backImg=cr('img');
		this.backImg.src=this.backImgSrc;
		this.backImg.style.zIndex='999';
		//this.backImg.style.position='absolute';
		//this.backImg.style.left='5px';
		//this.backImg.style.top='49%';
		this.backImg.style.display='none';
		this.backImg.style.cursor='pointer';
		
		
		
		this.bigImgDiv=cr('div');
		this.bigImgDiv.style.position='absolute';
		this.bigImgDiv.style.zIndex='100';
		this.bigImgDiv.style.overflow='hidden';
		this.bigImgDiv.style.backgroundColor='#FFF';
		
		this.bigImgNavMenu=cr('div');
		this.bigImgNavMenu.style.zIndex='200';
		this.bigImgNavMenu.style.position='absolute';
		this.bigImgNavMenu.style.width='100%';
		this.bigImgNavMenu.style.height='20px';
		this.bigImgNavMenu.style.bottom='3px';
		this.bigImgNavMenu.style.left='5px';
		
		this.NavMenuSpanPre=cr('span');
		this.NavMenuSpan=cr('span');

		this.NavMenuSpan.style.color = "#7A7A7A";
		this.NavMenuSpan.style.fontSize = '14px';
		this.NavMenuSpan.style.fontWeight = "bold";
		this.NavMenuSpanPre.appendChild(this.NavMenuSpan);
		
		this.bigImgNavMenuPre1=cr('table');
		this.bigImgNavMenuPre1Tbody = cr('tbody');
		this.bigImgNavMenuPre1TR = cr('tr');
		this.bigImgNavMenuPre1.width = "100%";
		
		this.bigImgNavMenuPre11=cr('td');
		this.bigImgNavMenuPre11.width = "3%";
		this.bigImgNavMenuPre12=cr('td');
		this.bigImgNavMenuPre12.width = "3%";
		this.bigImgNavMenuPre12.style.padding = '2px 10px 0 10px';
		this.bigImgNavMenuPre13=cr('td');
		this.bigImgNavMenuPre13.width = "3%";
		this.bigImgNavMenuPre14=cr('td');
		this.bigImgNavMenuPre14.width = "90%";
		this.bigImgNavMenuPre14.style.padding = '2px 0 0 1px';
		this.bigImgNavMenuPre15=cr('td');
		this.bigImgNavMenuPre15.width = "1%";
		this.bigImgNavMenuPre15.innerHTML = '<img src="/img/1.gif" width="26" height="1"/>';

		this.bigImgNavMenuPre11.appendChild(this.backImg);
		this.bigImgNavMenuPre12.appendChild(this.NavMenuSpanPre);
		this.bigImgNavMenuPre13.appendChild(this.nextImg);
		this.bigImgNavMenuPre14.appendChild(this.textDiv);
		
		this.bigImgNavMenuPre1TR.appendChild(this.bigImgNavMenuPre11);
		this.bigImgNavMenuPre1TR.appendChild(this.bigImgNavMenuPre12);
		this.bigImgNavMenuPre1TR.appendChild(this.bigImgNavMenuPre13);
		this.bigImgNavMenuPre1TR.appendChild(this.bigImgNavMenuPre14);
		this.bigImgNavMenuPre1TR.appendChild(this.bigImgNavMenuPre15);
		this.bigImgNavMenuPre1Tbody.appendChild(this.bigImgNavMenuPre1TR);
		this.bigImgNavMenuPre1.appendChild(this.bigImgNavMenuPre1Tbody);
		this.bigImgNavMenu.appendChild(this.bigImgNavMenuPre1);
		
		
		this.bigImgDiv.appendChild(this.bigImgNavMenu);
		this.bigImgDiv.appendChild(this.bigImg);
		this.bigImgDiv.appendChild(this.closeImg);
		
		
		Event.observe(this.bigImg,'load',this.bigImgLoaded.bind(this));
		Event.observe(this.closeImg,'click',this.closeBigImg.bindAsEventListener(this));
		Event.observe(this.nextImg,'click',this.nextBigImg.bindAsEventListener(this));
		Event.observe(this.backImg,'click',this.backBigImg.bindAsEventListener(this));

		Event.observe(window,'load',this.afterLoad.bind(this));
		
	},
	afterLoad:function(){
			this.mPos=Position.cumulativeOffset(this.mainDiv);	
	},
	showBigImg:function(id){
		nextID = -1;
		for(i=0;i<this.imgCount;i++)
		{
			if(this.imgList[i].src.indexOf(id)!=-1) nextID = i;
		}
		
		if(nextID == -1) return true;
		var src = this.imgMainSrc[nextID];
		this.curImgOpen = nextID;
		
		
		this.NavMenuSpan.innerHTML = (1*this.curImgOpen+1)+'/'+this.imgList.length;
		//this.textDiv.innerHTML = '<div align="center" style="padding: 0 10px"><strong>ID '+this.projectID+'</strong></div>';
		document.body.appendChild(this.bgDiv);
		

		this.pageScroll=getPageScroll();
		this.pageSize=getPageSize();
		this.bgDiv.style.backgroundColor=this.bgAlert;
		Element.setOpacity(this.bgDiv,this.bgOpacity);
		
		this.bgDiv.style.position='absolute';
		
		var pageScroll=getPageScroll();
		var pageSize=getPageSize();
		
		this.bgDiv.style.width=pageSize[0]+'px';
		this.bgDiv.style.height=(pageSize[1])+'px';
		this.bgDiv.style.top='0px';
		this.bgDiv.style.left='0px';
		this.bgDiv.style.display='block';
		this.closeImg.style.display='none';
		this.nextImg.style.display='none';
		this.backImg.style.display='none';
		this.bigImg.style.display='none';
		document.body.appendChild(this.loadingImg);
		this.loadingImg.style.position="absolute";
		this.loadingImg.style.zIndex='100';
	
		this.loadingImgVisibled=true;
		
		var ImgSize={width:loadingBarHeight,height:loadingBarHeight}
		var ImgWidth=Math.round(ImgSize.width-ImgSize.width/2);
		var ImgHeight=Math.round(ImgSize.height-ImgSize.height/2);
		var ImgTop=this.pageScroll[1]+(this.pageSize[3]/2-ImgHeight/2);
		var ImgLeft=this.pageScroll[0]+(this.pageSize[2]/2-ImgWidth/2);
		this.loadingImg.style.top=ImgTop+'px';
		this.loadingImg.style.left=ImgLeft+'px';
		
		this.loadingImg.style.display='block';
		Event.observe(this.bgDiv,'click',this.closeBigImg.bindAsEventListener(this));
		//alert(src);
		this.bigImg.src=src;//this.phpthumb+'?src='+src[1]+'&w=800&h=600';
		
		
	},
	setProjectID:function(id){
		this.projectID = id;
	},
 	insertImg:function(src){
		this.imgList[this.imgCount]=cr('img');
		this.imgList[this.imgCount].src = src;
		this.imgList[this.imgCount].id = this.imgCount;
		this.imgMainSrc[this.imgCount] = this.imgList[this.imgCount].src;
		
		//this.imgList[this.imgCount].src=this.phpthumb+'?src='+src+'&w='+this.options.imgWidth+'&h='+this.options.imgHeight+'&zc=1';
		var name=src.match(/(.*?)\.(...)$/);
		this.imgList[this.imgCount].src=name[1]+'_imedthumb.'+name[2];
		this.imgList[this.imgCount].style.cursor='pointer';
		Event.observe(this.imgList[this.imgCount],'mouseover',this.imgOver.bindAsEventListener(this));
		Event.observe(this.imgList[this.imgCount],'mouseout',this.imgOut.bindAsEventListener(this));
		Event.observe(this.imgList[this.imgCount],'click',this.imgClick.bindAsEventListener(this));
		var pr_div = cr('div');
		//var li=cr('li');
		//li.style.cssFloat="left";
		//li.style.position='relative';
		pr_div.appendChild(this.imgList[this.imgCount]);
		pr_div.id=name[1]+'_imedthumb.'+name[2];
		pr_div.style.display = 'none';
		pr_div.style.visibility = 'hidden';
		//li.appendChild(pr_div);
		//this.imListUl.appendChild(li);
		try
		{
			obj = document.getElementById('div_'+pr_div.id);
			alert(obj.id);
		}
		catch(Exception){}
		
		this.mainDiv.appendChild(pr_div);
		this.imgCount++;
		//this.imListUlWidth=((this.options.imgWidth+10+(this.options.imgPadding*2))*this.imgCount);
		//this.imListUl.style.width=this.imListUlWidth+'px';
		//this.calcScrollBarWidth();
	},
	calcScrollBarWidth:function(){
		
		var widthPercent=Math.floor(this.options.width*100/((this.options.imgWidth+1+this.options.imgPadding*2)*this.imgCount));
		this.scrollBarWidth=Math.floor(this.options.width*widthPercent/100);
		this.scrollDivCenter.style.width=(this.scrollBarWidth-14)+'px';
		if (this.scrollBarWidth>=this.options.width){
			this.scrollDiv.style.display='none';
		}else{
			this.scrollDiv.style.display='block';
		}
		this.scrollDiv.style.width=this.scrollBarWidth+'px';
	},
	initDrag:function(event){
		//alert(this.options.width);
		this.DragStarted=true;
		this.mX=Event.pointerX(event);
		Event.observe(document,'mouseup',this.MouseUp);
		Event.observe(document,'mousemove',this.MouseMove);
		
		document.body.ondrag = function () { return false; };
    	document.body.onselectstart = function () { return false; };
		Event.stop(event);
	},
	moveDrag:function(event){
		this.mX1=Event.pointerX(event);
		if (this.mX1>(this.mPos[0]+this.options.width) || this.mX1<this.mPos[0])
			return;
		var razn=this.mX1-this.mX;
		this.mX=this.mX1;
		this.scrollBarX=this.scrollBarX+razn;
		if ((this.scrollBarX + this.scrollBarWidth) >= this.options.width) {
			this.scrollBarX = (this.options.width - this.scrollBarWidth);
		}else if (this.scrollBarX<=0)
			this.scrollBarX=0;
		
		this.scrollDiv.style.left=this.scrollBarX+'px';
		var scrollBarXPercent=Math.floor(this.scrollBarX*100/this.options.width);
		this.imListUl.style.left=(0-Math.floor(this.imListUlWidth*scrollBarXPercent/100))+'px';
	},
	endDrag:function(event){
		Event.stopObserving(document,'mouseup',this.MouseUp);
		Event.stopObserving(document,'mousemove',this.MouseMove);
	},
	clickScrollBar:function(event){
		if (this.scrollDiv.style.display=='none')return;
		this.moveDrag(event);
	},
	imgOver:function(event){
		/*
		var img=Event.findElement(event,'li');
		var p1=this.options.imgPadding-1;
		var p2=this.options.imgPadding+1;
		//img.style.margin='0px';
		img.style.paddingLeft=p1+'px';
		img.style.paddingTop=p1+'px';
		img.style.paddingBottom=p2+'px';
		img.style.paddingRight=p2+'px';
		*/
	},
	imgOut:function(event){
		/*
		var img=Event.findElement(event,'li');
		//img.style.padding='0px';
		img.style.margin=this.options.imgPadding+'px';
		*/
	},
	imgClick:function(event){
		document.body.appendChild(this.bgDiv);
		var img=Event.findElement(event,'img');
		//var name=img.src.match(/(.*?)\.(...)$/im);

		var src = this.imgMainSrc[img.id];
		this.curImgOpen = img.id;
		

		this.NavMenuSpan.innerHTML = (1*this.curImgOpen+1)+'/'+this.imgList.length;
		//this.textDiv.innerHTML = '<div align="center" style="padding: 0 10px"><strong>ID '+this.projectID+'</strong></div>';
		this.pageScroll=getPageScroll();
		this.pageSize=getPageSize();
		this.bgDiv.style.backgroundColor=this.bgAlert;
		Element.setOpacity(this.bgDiv,this.bgOpacity);
		
		this.bgDiv.style.position='absolute';
		
		var pageScroll=getPageScroll();
		var pageSize=getPageSize();
		
		this.bgDiv.style.width=pageSize[0]+'px';
		this.bgDiv.style.height=pageSize[1]+'px';
		this.bgDiv.style.top='0px';
		this.bgDiv.style.left='0px';
		this.bgDiv.style.display='block';
		this.closeImg.style.display='none';
		this.nextImg.style.display='none';
		this.backImg.style.display='none';
		this.bigImg.style.display='none';
		
		document.body.appendChild(this.loadingImg);
		this.loadingImg.style.position="absolute";
		this.loadingImg.style.zIndex='100';
	
		this.loadingImgVisibled=true;
		//alert(this.loadingImg.id)
		var ImgSize={width:loadingBarWidth,height:loadingBarHeight}
		var ImgWidth=Math.round(ImgSize.width-ImgSize.width/2);
		var ImgHeight=Math.round(ImgSize.height-ImgSize.height/2);
		var ImgTop=this.pageScroll[1]+(this.pageSize[3]/2-ImgHeight/2);
		var ImgLeft=this.pageScroll[0]+(this.pageSize[2]/2-ImgWidth/2);
		this.loadingImg.style.top=ImgTop+'px';
		this.loadingImg.style.left=ImgLeft+'px';
		
		this.loadingImg.style.display='block';
		Event.observe(this.bgDiv,'click',this.closeBigImg.bindAsEventListener(this));
		this.bigImg.src=src;//this.phpthumb+'?src='+src[1]+'&w=800&h=600';
	},
	nextBigImg:function(event){
		//nextID = (1*this.curImgOpen)+1;
		nextID = -1;
		for(i=(1*this.curImgOpen)+1;i<this.imgCount;i++)
		{
			if(''+this.imgMainSrc[i]!='')
			{
				nextID = i;
				i = this.imgCount;
			}
		}
		if(nextID==-1)
		{
			for(i=0; i<(1*this.curImgOpen)+1;i++){
				if(''+this.imgMainSrc[i]!='')
				{
					nextID = i;
					i = this.imgCount;
				}
			}
			
		}
		if(nextID==-1) nextID = 1*this.curImgOpen;
		
		var src = this.imgMainSrc[nextID];
		this.curImgOpen = nextID;
		
		this.NavMenuSpan.innerHTML = (1*this.curImgOpen+1)+'/'+this.imgList.length;

		this.pageScroll=getPageScroll();
		this.pageSize=getPageSize();
		this.bgDiv.style.backgroundColor=this.bgAlert;
		Element.setOpacity(this.bgDiv,this.bgOpacity);
		
		this.bgDiv.style.position='absolute';
		
		var pageScroll=getPageScroll();
		var pageSize=getPageSize();
		
		this.bgDiv.style.width=pageSize[0]+'px';
		this.bgDiv.style.height=pageSize[1]+'px';
		this.bgDiv.style.top='0px';
		this.bgDiv.style.left='0px';
		this.bgDiv.style.display='block';
		this.closeImg.style.display='none';
		this.nextImg.style.display='none';
		this.backImg.style.display='none';
		this.bigImg.style.display='none';
		
		document.body.appendChild(this.loadingImg);
		this.loadingImg.style.position="absolute";
		this.loadingImg.style.zIndex='100';
	
		this.loadingImgVisibled=true;
		//alert(this.loadingImg.id)
		var ImgSize={width:loadingBarWidth,height:loadingBarHeight}
		var ImgWidth=Math.round(ImgSize.width-ImgSize.width/2);
		var ImgHeight=Math.round(ImgSize.height-ImgSize.height/2);
		var ImgTop=this.pageScroll[1]+(this.pageSize[3]/2-ImgHeight/2);
		var ImgLeft=this.pageScroll[0]+(this.pageSize[2]/2-ImgWidth/2);
		this.loadingImg.style.top=ImgTop+'px';
		this.loadingImg.style.left=ImgLeft+'px';
		
		this.loadingImg.style.display='block';
		Event.observe(this.bgDiv,'click',this.closeBigImg.bindAsEventListener(this));
		//alert(src);
		this.bigImg.src=src;//this.phpthumb+'?src='+src[1]+'&w=800&h=600';
		
		
	},
	backBigImg:function(event){
		//nextID = (1*this.curImgOpen)+1;
		nextID = -1;
		for(i=(1*this.curImgOpen)-1;i>-1;i--)
		{
			if(''+this.imgMainSrc[i]!='')
			{
				nextID = i;
				i=-1;
			}
		}
		if(nextID==-1)
		{
			for(i=(1*this.imgCount-1); i>(1*this.curImgOpen)-1;i--){
				if(''+this.imgMainSrc[i]!='')
				{
					nextID = i;
					i = -1;
				}
			}
			
		}
		if(nextID==-1) nextID = 1*this.curImgOpen;
		
		var src = this.imgMainSrc[nextID];
		this.curImgOpen = nextID;

		this.NavMenuSpan.innerHTML = (1*this.curImgOpen+1)+'/'+this.imgList.length;
		this.pageScroll=getPageScroll();
		this.pageSize=getPageSize();
		this.bgDiv.style.backgroundColor=this.bgAlert;
		Element.setOpacity(this.bgDiv,this.bgOpacity);
		
		this.bgDiv.style.position='absolute';
		
		var pageScroll=getPageScroll();
		var pageSize=getPageSize();
		
		this.bgDiv.style.width=pageSize[0]+'px';
		this.bgDiv.style.height=pageSize[1]+'px';
		this.bgDiv.style.top='0px';
		this.bgDiv.style.left='0px';
		this.bgDiv.style.display='block';
		this.closeImg.style.display='none';
		this.nextImg.style.display='none';
		this.backImg.style.display='none';
		this.bigImg.style.display='none';
		
		document.body.appendChild(this.loadingImg);
		this.loadingImg.style.position="absolute";
		this.loadingImg.style.zIndex='100';
	
		this.loadingImgVisibled=true;
		//alert(this.loadingImg.id)
		var ImgSize={width:loadingBarWidth,height:loadingBarHeight}
		var ImgWidth=Math.round(ImgSize.width-ImgSize.width/2);
		var ImgHeight=Math.round(ImgSize.height-ImgSize.height/2);
		var ImgTop=this.pageScroll[1]+(this.pageSize[3]/2-ImgHeight/2);
		var ImgLeft=this.pageScroll[0]+(this.pageSize[2]/2-ImgWidth/2);
		this.loadingImg.style.top=ImgTop+'px';
		this.loadingImg.style.left=ImgLeft+'px';
		
		this.loadingImg.style.display='block';
		Event.observe(this.bgDiv,'click',this.closeBigImg.bindAsEventListener(this));
		//alert(src);
		this.bigImg.src=src;//this.phpthumb+'?src='+src[1]+'&w=800&h=600';
	},
	closeBigImg:function(event){
		window.clearInterval(this.tId);
		if (this.bigImgVisibled)
			document.body.removeChild(this.bigImgDiv);
		if (this.loadingImgVisibled){
			document.body.removeChild(this.loadingImg);
			document.body.removeChild(this.bgDiv);
		}
		this.bgDiv.style.display='none';
		this.bigImgVisibled=false;
		this.loadingImgVisibled=false;
	},
	bigImgLoaded:function(){
		if (this.loadingImgVisibled)
			document.body.removeChild(this.loadingImg);
		else 
			return;
		this.loadingImgVisibled=false;
		this.bigImgVisibled=true;
		this.loadingImg.style.display='none';
		this.pageScroll=getPageScroll();
		this.pageSize=getPageSize();
		document.body.appendChild(this.bigImgDiv);
		this.bigImgSize=this.bigImg.getDimensions();
		this.bigImgDivWidth=Math.round(this.bigImgSize.width-this.bigImgSize.width/2);
		this.bigImgDivHeight=Math.round(this.bigImgSize.height-this.bigImgSize.height/2);
		this.bigImgDivTop=this.pageScroll[1]+(this.pageSize[3]/2-this.bigImgDivHeight);
		this.bigImgDivLeft=this.pageScroll[0]+(this.pageSize[2]/2-this.bigImgDivWidth);
		
		this.bigImgDiv.style.width=this.bigImgDivWidth+'px';
		this.bigImgDiv.style.height=this.bigImgDivHeight+'px';
		this.bigImgDiv.style.top=this.bigImgDivTop+'px';
		this.bigImgDiv.style.left=this.bigImgDivLeft+'px';
		this.bigImg.style.display='none';
		this.tId=window.setInterval(this.slowShow.bind(this),1);
	},
	slowShow:function(){

			this.bigImgDiv.style.width=(this.bigImgSize.width+10)+'px';
			this.bigImgDiv.style.height=(this.bigImgSize.height+32)+'px';
			this.bigImg.style.left='5px';
			this.bigImg.style.top='5px';
			
			this.bigImg.style.clear='both';
			this.bigImg.style.display='inline';
			this.closeImg.style.display='inline';
			this.closeImg.style.clear='both';

			this.nextImg.style.display='inline';
			this.nextImg.style.clear='both';
			this.backImg.style.display='inline';
			this.backImg.style.clear='both';
			
			window.clearInterval(this.tId);



		}
//	}
 }
