/**
 * @author Lart
 */

function cr(name){	return document.createElement(name);}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}




 var OLGgalery=Class.create();
 
 OLGgalery.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.mainDiv.style.width=this.options.width+'px';
		//this.mainDiv.style.height=(this.options.height+this.options.scrollBarHeight+this.options.imgPadding*2)+'px';
		//this.mainDiv.style.overflow='hidden';
		//this.mainDiv.style.position='relative';
		//this.mainDiv.style.border='1px solid #000';

		//this.imListUl=cr('ul');
		//this.imListUl.style.height=this.options.height+'px';
		//this.imListUl.style.position='absolute';
		//this.imListUl.className='Galery';
		
		//this.scrollDivBg=cr('div');
		//this.scrollDivBg.style.width='100%';
		//this.scrollDivBg.style.height='17px';
		//this.scrollDivBg.style.backgroundColor="#000";
		//this.scrollDivBg.style.position = 'relative';
		//Event.observe(this.scrollDivBg,'click',this.clickScrollBar.bindAsEventListener(this));
		//this.scrollDivBg.style.top = (this.options.height + this.options.imgPadding * 2) + 'px';
		//this.scrollDiv=cr('div');
		//this.scrollDivCenter=cr('div');
		 
		//this.scrollDivCenter.style.height='17px';
		//this.scrollDivCenter.className="Galery_center_Scroll";
		
			
			//this.scrollDiv.style.height = (this.options.scrollBarHeight) + 'px';
			//var l=cr('div');l.style.width='7px';l.style.height='17px';
			//l.className='Galery_left_Scroll';
			
			//this.scrollDiv.appendChild(l);
			//this.scrollDiv.appendChild(this.scrollDivCenter);
			//l=cr('div');l.style.width='7px';l.style.height='17px';
			//l.className='Galery_right_Scroll';
			//this.scrollDiv.appendChild(l);
			//this.scrollDiv.style.position = 'absolute';
			//this.scrollDiv.style.left="0px";
		
		//this.scrollDivBg.appendChild(this.scrollDiv);
		//Event.observe(this.scrollDiv,'mousedown',this.MouseDown);
		
		//this.mainDiv.appendChild(this.imListUl);
		//this.mainDiv.appendChild(this.scrollDivBg);
		//this.mainDiv.appendChild(this.scrollDiv);
		
		
		
		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.NMTable=cr('table');
		this.NMTable.border=1;
		this.NMTableTR = cr('tr');
		this.NMTableTD1 = cr('td');
		this.NMTableTD1.appendChild(this.backImg);
		this.NMTableTD2 = cr('td');
		this.NMTableTD2.innerHTML = '123';
		this.NMTableTD3 = cr('td');
		this.NMTableTD3.appendChild(this.nextImg);
		this.NMTableTR.appendChild(this.NMTableTD1);
		this.NMTableTR.appendChild(this.NMTableTD2);
		this.NMTableTR.appendChild(this.NMTableTD3);
		this.NMTable.appendChild(this.NMTableTR);
		*/
		this.NavMenuSpanPre=cr('span');
		//this.NavMenuSpanPre.style.width = "40px";
		//this.NavMenuSpanPre.innerHTML = ';';
		this.NavMenuSpan=cr('span');
		//this.NavMenuSpan.innerHTML = this.curImgOpen+'/'+this.imgList.length;
		//this.NavMenuSpan.style.position='absolute';
		//this.NavMenuSpan.style.top='+3px';
		//this.NavMenuSpan.style.left = "+20px";
		//this.NavMenuSpan.style.padding = '0px 10px';
		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.bigImgNavMenu.appendChild(this.textDiv);
		this.bigImgNavMenu.appendChild(this.backImg);
		this.bigImgNavMenu.appendChild(this.NavMenuSpanPre);
		this.bigImgNavMenu.appendChild(this.nextImg);
		*/
		
		
		
		//this.bigImgNavMenu.innerHTML="12341234..."
		
		
		this.bigImgDiv.appendChild(this.bigImgNavMenu);
		this.bigImgDiv.appendChild(this.bigImg);
		this.bigImgDiv.appendChild(this.closeImg);
		//this.bigImgDiv.appendChild(this.nextImg);
		//this.bigImgDiv.appendChild(this.backImg);
		
		
		
		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;
		}
		
		try
		{
		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;color:#3D444B;font-size:10px;">'+this.imgList[nextID].alt+'</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';
		}
		catch(Exception){alert('error!!!');}
		
	},
	setProjectID:function(id){
		this.projectID = id;
	},
 	insertImg:function(src,alt){
		this.imgList[this.imgCount]=cr('img');
		this.imgList[this.imgCount].src = src;
		this.imgList[this.imgCount].alt = alt;
		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;color:#3D444B;font-size:10px;">'+this.imgList[img.id].alt+'</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';
		this.textDiv.innerHTML = '<div align="center" style="padding: 0 10px;color:#3D444B;font-size:10px;">'+this.imgList[nextID].alt+'</div>';
		
	},
	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';
		this.textDiv.innerHTML = '<div align="center" style="padding: 0 10px;color:#3D444B;font-size:10px;">'+this.imgList[nextID].alt+'</div>';
	},
	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(){
/*		if (this.bigImgDivWidth < this.bigImgSize.width+10) {
			this.bigImgDivWidth = this.bigImgDivWidth + 6;
			this.bigImgDivLeft=this.bigImgDivLeft-3;
			this.bigImgDiv.style.width = this.bigImgDivWidth + 'px';
			this.bigImgDiv.style.left = this.bigImgDivLeft + 'px';
		}
		if (this.bigImgDivHeight < this.bigImgSize.height+10 && this.bigImgDivWidth >= this.bigImgSize.width+10) {
			this.bigImgDivHeight = this.bigImgDivHeight + 6;
			this.bigImgDivTop=this.bigImgDivTop-3;
			this.bigImgDiv.style.height = this.bigImgDivHeight + 'px';
			this.bigImgDiv.style.top = this.bigImgDivTop + 'px';
		}
		
		if (this.bigImgDivWidth>=this.bigImgSize.width+10 && this.bigImgDivHeight >= this.bigImgSize.height+10){*/


			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);



		}
//	}
 }
