/*  
	Magnat Sp z o.o.
	© All rights reserved
*/


var image_mov = {
	initialized : false,
	movdiv : Object,
	movimg : Array,
	movids : Array,
	movright : 0,
	movpos : 1,
	movmax : 10,
	movobj : [Object,Object,Object,Object,Object],
	movpreimg : Object,
	movcap : [Object,Object,Object,Object,Object],
	movblockL : false,
	movblockR : false,
	name : '',
	
	init : function(tablica,links,start,max,caption) {
		this.movimg = tablica;
		this.movids = links;
		this.movmax = max;
		this.movpos = start;
		this.name = caption;
		this.movdiv = document.getElementById("movethis");
		this.movpreimg = new Image();
		for(i=1;i<6;i++)
		{
			this.movobj[i-1] = document.getElementById("img"+i);
			this.movcap[i-1] = document.getElementById("imgcaption"+i);
		}		
		if (max>4) { this.initialized = true; }
	},
	
	animatemoveleft : function()
	{
		var fader = 0;
		if(this.movright>1)
		{
		this.movright--;
		
		if(this.movright>100)
		{
			fader = 5;
		}
		else if(this.movright>80)
		{
			fader = 4;
		}	
		else if(this.movright>60)
		{
			fader = 3;
		}	
		else if(this.movright>40)
		{
			fader = 2;
		}	
		else if(this.movright>20)
		{
			fader = 1;
		} else {
			fader = 0;
		}
		
		this.movright = this.movright - fader; 
		this.movdiv.style.right = this.movright+ "px";
		setTimeout("image_mov.animatemoveleft()",10);
		} else {
			this.movdiv.style.right = "0px";
			this.movblockR = false;
		}
	},

	animatemoveright : function ()
	{
		var fader = 0;
		if(this.movright<127)
		{
		this.movright++;

		if(this.movright<30)
		{
			fader = 5;
		}
		else if(this.movright<50)
		{
			fader = 4;
		}
		else if(this.movright<70)
		{
			fader = 3;
		}
		else if(this.movright<90)
		{
			fader = 2;
		}
		else if(this.movright<110)
		{
			fader = 1;
		}
		else
		{
			fader = 0;
		}
		this.movright += fader;
		this.movdiv.style.right = this.movright+ "px";
		setTimeout("image_mov.animatemoveright()",10);
		} else {
			this.movdiv.style.right = "127px";
			this.movblockL = false;
		}
	},
	
	moveright : function ()
	{
		
		if((this.initialized)&&(this.movpos<(this.movmax-3))&&(!this.movblockR))
		{
		this.movblockL = true;
		this.movpos++;
		this.movright = 0;
			for(i=0;i<5;i++)
			{
			imgid = ((this.movpos-1)+i)-1;
			if(imgid>0){

				this.movobj[i].src = this.movimg[imgid]; 
				eval('this.movobj[i].onclick =  function() { image_box.show("'+this.movids[imgid]+'","'+this.name+'"); }');
				this.movcap[i].innerHTML = (this.movpos+i-1)+"/"+this.movmax;
				}
			}
		this.movdiv.style.right = "0px";
		this.animatemoveright();
		if((this.movpos+3)<this.movmax) { this.movpreimg.src = this.movimg[this.movpos+3]; }
		}
	},
	
	moveleft : function()
	{	
		if((this.initialized)&&(this.movpos>1)&&(!this.movblockL))
		{
		this.movblockR = true;
		this.movpos--;
		this.movright = 127;
			for(i=0;i<5;i++)
			{
			imgid = ((this.movpos-1)+i);
			
			if(imgid>=0){
				
				this.movobj[i].src = this.movimg[imgid];
				eval('this.movobj[i].onclick =  function() { image_box.show("'+this.movids[imgid]+'","'+this.name+'"); }');
				this.movcap[i].innerHTML = (this.movpos+i)+"/"+this.movmax; 
				}
			}
		this.movdiv.style.right = "127px";
		
		this.animatemoveleft();
		if((this.movpos-2)>=0) { this.movpreimg.src = this.movimg[this.movpos-2]; }
		}
	}

}

