var slidesPict={
	pos:0,
	step:0,
	enlargePict:null,

	init: function(obj, step){
		if(!obj) return;
		 
		this.enlargePict = obj; 
		
		if(obj.imgslist){
			this.pos = 0;
			this.step = step;
	}	},

	next: function(obj){
		if(this.enlargePict){

			if(this.pos==0){
				var otherID = obj.onkeypress();
				
				if(otherID!=null && otherID!=''){
					var otherObj = document.getElementById(otherID);
					if(otherObj && otherObj.style.cursor=='default'){
						otherObj.style.cursor = 'pointer';
						var newimg = otherObj.ondblclick();
						var oldimg = otherObj.src;
						otherObj.src=newimg;
						otherObj.ondblclick = function(){return oldimg;};
			}	}	}
			
			
			if(Math.abs(this.pos)<(this.step*(this.enlargePict.length-1))){
				this.enlargePict.index +=1;
				this.pos -= this.step;
				if(this.enlargePict.useLeft)
					this.enlargePict.imgslist.style.left=this.pos + 'px';
				else
					this.enlargePict.imgslist.style.marginLeft=this.pos + 'px';
				
				if(Math.abs(this.pos)==(this.step*(this.enlargePict.length-1))){
					obj.style.cursor = 'default';
					var newimg1 = obj.ondblclick();
					var oldimg1 = obj.src;
					obj.src=newimg1;
					obj.ondblclick = function(){return oldimg1;};
	}	}	}	},
	
	previous: function(obj){
		if(this.enlargePict){
			
			if(Math.abs(this.pos)==(this.step*(this.enlargePict.length-1))){
				var otherID = obj.onkeypress();
				if(otherID!=null && otherID!=''){
					var otherObj = document.getElementById(otherID);
					if(otherObj && otherObj.style.cursor=='default'){
						otherObj.style.cursor = 'pointer';
						var newimg = otherObj.ondblclick();
						var oldimg = otherObj.src;
						otherObj.src=newimg;
						otherObj.ondblclick = function(){return oldimg;};
			}	}	}
			
			if(this.pos<0){
				this.enlargePict.index-=1
				this.pos += this.step;
				if(this.enlargePict.useLeft)
					this.enlargePict.imgslist.style.left=this.pos + 'px';
				else
					this.enlargePict.imgslist.style.marginLeft=this.pos + 'px';
				
				if(this.pos==0){
					obj.style.cursor = 'default';
					var newimg1 = obj.ondblclick();
					var oldimg1 = obj.src;
					obj.src=newimg1;
					obj.ondblclick = function(){return oldimg1;};
	}	}	}	}
	
};

var enlargePicts = {
	ONclick:[],
	MaxHeight:0,
	index:0,
	length:0,
	imgslist:null,
	Container:null,
	slidesPicts:null,
	useLeft:false,
	
	init: function(id, step)
	{
		var brouser = GetBrowser();
		var MinHeight = 65;

		if(brouser[3]){
			if(brouser[3]=='opera' && brouser[1]<9) this.useLeft=true;
			if(brouser[3]=='chrome') this.useLeft=true
			if(brouser[3]=='safari') this.useLeft=true
		}

		var images = document.getElementById(id);
		var height;
		if(images){
			var prev=null;
			var next=null;
			if(images.onclick){
				var obj = images.onclick();
				if(obj)	{
					prev = document.getElementById(obj.prevID);
					next = document.getElementById(obj.nextID);
			}	}
			
			this.imgslist = images.getElementsByTagName('div')[0];
			this.Container = images.parentNode;

			if (this.imgslist){
				var imgs = images.getElementsByTagName('img');
				for(var i = 0; i < imgs.length; i++){
					if(imgs[i].className.match(/(^|\s)enlargepict($|\s)/i)){
	
						if(imgs[i].height>this.MaxHeight)
							this.MaxHeight = imgs[i].height

						this.item(imgs[i], images, i);
				}	}
				this.length = this.ONclick.length;
				
				if(MinHeight>this.MaxHeight){
					this.MaxHeight = MinHeight;
					images.style.height = this.MaxHeight + 'px';
				}

				if(this.MaxHeight>0){
					for(var i = 0; i < imgs.length; i++){
						height = imgs[i].height;

						height = this.MaxHeight - height;
						if(height>=2){
							height = (height/2)
							imgs[i].style.marginTop=height + 'px';
					}	}
					
					if(prev){
						height = prev.height;
						height = this.MaxHeight - height;
						if(height>=2){
							height = (height/2)
							prev.style.marginTop= height + 'px';
							
							if(next) next.style.marginTop= height + 'px';
				}	}	}

				if(prev) prev.style.visibility='visible';
				if(next) next.style.visibility='visible';
				
				slidesPict.init(this, step);
				this.slidesPicts = slidesPict;
	}	}	},

	item: function(image, images, i){
		var bigimg = image.onclick();
		var container = this.Container;
		var maxHeight = this.MaxHeight;

		var evnt = function(){
			var IMG, DIV, SPAN;
			
			DIV = document.createElement('div');
			IMG = document.createElement('img');

			image.tempLoadImage=new Image();
			image.LoadBig=false;
			image.SetPadding=function(){
				if(maxHeight && image.tempLoadImage.height)
				{
					var height = maxHeight - image.tempLoadImage.height;
					if(height>=2)
					{
							height = (height/2)
							IMG.style.marginTop= height + 'px';
							IMG.style.marginBottom= height + 'px';
			}	}	}
			image.tempLoadImage.onload= function(){image.LoadBig=true; image.SetPadding(); DIV.style.visibility='visible';}
			image.tempLoadImage.src=bigimg;
			
			IMG.src=bigimg;
			IMG.id=images.id + '_Curimg_img';
			IMG.style.cursor='pointer';
			IMG.onclick = function(){document.body.removeChild(DIV);}
			
			DIV.style.visibility='hidden'
			
			DIV.id=images.id + '_Curimg_div';
			DIV.style.backgroundColor ='#ffffff';
			DIV.style.position ='absolute';
			DIV.style.border = '1px solid #D3D3D3';
			 
			var coordinate = new BlockOffset(container);
			if(coordinate){
				DIV.style.left =coordinate.left;
				DIV.style.top  =coordinate.top;
			}
			else{
				DIV.style.left =0;
				DIV.style.top  =0;
			}
			DIV.style.zIndex=200;
			DIV.style.cursor='pointer';

			SPAN = document.createElement('DIV');
			SPAN.innerHTML='уменьшить';			
			SPAN.className='textboldunderline loupe';
			SPAN.onclick = function(){document.body.removeChild(DIV);}

			DIV.appendChild(IMG);
			DIV.appendChild(SPAN);
			document.body.appendChild(DIV);
			if(image.LoadBig){
				image.SetPadding();
				DIV.style.visibility='visible';
		}	}
		
		this.ONclick[i]=evnt;
		if(image.parentNode){
			image.parentNode.style.cursor='pointer';
			image.parentNode.onclick= evnt;
		}
		else		
			image.onclick = evnt
	},
	
	enlarge:function(){this.ONclick[this.index]();}
};

function BlockOffset(elem){
	var Top=0;
	var Left=0;
	if (elem.getBoundingClientRect)	{
		var box = elem.getBoundingClientRect();
		var body = document.body;
		var docElem = document.documentElement;
		var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop;
		var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft;
		var clientTop = docElem.clientTop || body.clientTop || 0;
		var clientLeft = docElem.clientLeft || body.clientLeft || 0;
		Top  = box.top +  scrollTop - clientTop;
		Left = box.left + scrollLeft - clientLeft;
		Top = Math.round(Top);
		Left = Math.round(Left);
		this.type='rect';
	} 
	else{
		while(elem){
			Top = Top + parseInt(elem.offsetTop);
			Left = Left + parseInt(elem.offsetLeft);
			elem = elem.offsetParent;
		}
		this.type='sum';
	}
	this.top = Top;
	this.left = Left;
}

