// JavaScript Document
var theWidth, theHeight, steps, ratio;

var int;

var i = 0;
var j = 0;

function dimensions() {
 // Window dimensions: 
	if (window.innerWidth) {
		theWidth=window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth=document.documentElement.clientWidth;
	}
	else if (document.body) {
		theWidth=document.body.clientWidth;
	}
	if (window.innerHeight) {
		theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) {
		theHeight=document.body.clientHeight;
	}
	//alert(theHeight);
	steps = 5819 - theWidth;
	ratio = steps/(theWidth-168);
}

function ustaw() {
	dimensions();
	document.getElementById("loader").style.marginTop = (theHeight-206)/2 + "px";
	document.getElementById("main").style.height = theHeight + "px";
	document.getElementById("strona").style.marginTop = (theHeight-1200)/2 + "px";
	document.getElementById("left").style.marginTop = (theHeight-63)/2-30 + "px";
	document.getElementById("right").style.marginTop = (theHeight-63)/2-30 + "px";
	document.getElementById("right").style.marginLeft = theWidth - 83 + "px";	
	document.getElementById("stopka").style.marginTop = -(theHeight-1200)/2 + theHeight-53 + "px";
	document.getElementById("wyspa").style.marginTop = (theHeight-1200)/2 + "px";		
	document.getElementById("parallax").style.marginTop = (theHeight-1200)/2 + "px";		
	strzalki();
}

function strzalki() {
	if($("knob").getPosition().x<=1){
		document.getElementById("left").style.display = 'none';
	}
	else {
		document.getElementById("left").style.display = 'block';
	}	
	if($("knob").getPosition().x+169==theWidth){
		//alert($("knob").getPosition().x+169);
		//alert(theWidth);
		document.getElementById("right").style.display = 'none';
	}
	else {
		document.getElementById("right").style.display = 'block';
	}
}

function positionIt (){
	ustaw();
	var myProducts = new ScrollBar('main', 'bar', 'knob', {
		scroll: {
			duration: 1500,
			transition: Fx.Transitions.Quad.easeInOut,
			onStart: function(){
				//int=setInterval("parallax()",5);
				//console.log('start ' + this.to[0]);
			},
			onComplete: function(){
				strzalki();
				//int=window.clearInterval(int);
			//	console.log('complete ' + this.to[0]);
			}
		},
		slider: {
			offset: -1,
			onChange: function(pos){
				strzalki();
			//	console.log('change ' + pos);
			},
			onComplete: function(pos){								
			//	console.log('complete ' + pos);
			}
		},
		knob: {
			duration: 1200,
			//transition: 'elastic:out',
			transition: Fx.Transitions.Quad.easeInOut,
			onStart: function(){
			//	console.log('start ' + this.to[0].value); // knob position
			}
		}
	});
	
	//myProducts.set(0);
		
	var x = new Array;
	var width = new Array;
	
	var products = $$('#strona div');
	//document.id('right').addEvent('click', function(){ myProducts.set(products[2]); });
	x[1] = products[1].getPosition().x;	
	x[2] = products[2].getPosition().x;	
	x[3] = products[3].getPosition().x;	
	x[4] = products[4].getPosition().x;	
	
	width[1] = products[1].getSize().x;
	width[2] = products[2].getSize().x;	
	width[3] = products[3].getSize().x;	
	width[4] = products[4].getSize().x;	
	
	//alert(x[1]);
	//alert((x[1]-(theWidth-width[1])/2)/ratio);
	//document.id('right').addEvent('click', function(){  });
	document.id('right').addEvent('click', function(){ 												
		/*if(i>=5) {
			myProducts.set(1511);
		}
		else {
			//i++;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio); 
		}*/
		if($("knob").getPosition().x < Math.round((x[1]-(theWidth-width[1])/2)/ratio)) {
			i=1;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);
		}
		if(($("knob").getPosition().x >= Math.round((x[1]-(theWidth-width[1])/2)/ratio))&&($("knob").getPosition().x < Math.round((x[2]-(theWidth-width[2])/2)/ratio))) {
			i=2;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);
		}
		if(($("knob").getPosition().x >= Math.round((x[2]-(theWidth-width[2])/2)/ratio))&&($("knob").getPosition().x < Math.round((x[3]-(theWidth-width[3])/2)/ratio))) {
			i=3;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);
		}
		if(($("knob").getPosition().x >= Math.round((x[3]-(theWidth-width[3])/2)/ratio))&&($("knob").getPosition().x < Math.round((x[4]-(theWidth-width[4])/2)/ratio))) {
			i=4;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);
		}
		if($("knob").getPosition().x >= Math.round((x[4]-(theWidth-width[4])/2)/ratio)) {
			//myProducts.set(1511);
			myProducts.set(theWidth-168);
		}
		//alert(i);
		//alert((x[i]-(theWidth-width[i])/2)/ratio);
		//alert($("knob").getPosition().x);
	});
	
	document.id('left').addEvent('click', function(){ 
		/*if(i<=0) {										   
			myProducts.set(0); 
		}
		else {
			//i--;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio); 
		}*/
		if($("knob").getPosition().x <= Math.round((x[1]-(theWidth-width[1])/2)/ratio)) {
			myProducts.set(0); 
		}
		if(($("knob").getPosition().x > Math.round((x[1]-(theWidth-width[1])/2)/ratio))&&($("knob").getPosition().x <= Math.round((x[2]-(theWidth-width[2])/2)/ratio))) {
			i=1;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);
		}
		if(($("knob").getPosition().x > Math.round((x[2]-(theWidth-width[2])/2)/ratio))&&($("knob").getPosition().x <= Math.round((x[3]-(theWidth-width[3])/2)/ratio))) {
			i=2;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);
		}
		if(($("knob").getPosition().x > Math.round((x[3]-(theWidth-width[3])/2)/ratio))&&($("knob").getPosition().x <= Math.round((x[4]-(theWidth-width[4])/2)/ratio))) {
			i=3;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);
		}
		if($("knob").getPosition().x > Math.round((x[4]-(theWidth-width[4])/2)/ratio)) {
			i=4;
			myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);
		}
		//alert(i);
	});	
	
	document.id('strzalka3').addEvent('click', function(){											
		i=1;			
		//myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);											
		//alert(i);
		
		myProducts.set(1150);
	});
	
	document.id('strzalka2').addEvent('click', function(){
		i=4;
		//myProducts.set((x[i]-(theWidth-width[i])/2)/ratio);											
		myProducts.set(900);
	});
	
	document.id('strzalka1').addEvent('click', function(){
		//myProducts.set(1511);
		//myProducts.set(theWidth-168);
		
		myProducts.set(450);
	});
	
	document.id('lipton').addEvent('click', function(){
		myProducts.set(0);											
	});
	
	document.id('strzalka1').addEvent('mouseenter', function(){
		document.id('zobacz').setStyle('background-image','url(images/strzalka_hover.png)');											
	});
	
	document.id('strzalka1').addEvent('mouseleave', function(){
		document.id('zobacz').setStyle('background-image','url(images/strzalka.png)');												
	});
	
	document.id('strzalka2').addEvent('mouseenter', function(){
		document.id('tancz').setStyle('background-image','url(images/strzalka_hover.png)');											
	});
	
	document.id('strzalka2').addEvent('mouseleave', function(){
		document.id('tancz').setStyle('background-image','url(images/strzalka.png)');												
	});
	
	document.id('strzalka3').addEvent('mouseenter', function(){
		document.id('poznaj').setStyle('background-image','url(images/strzalka_hover.png)');											
	});
	
	document.id('strzalka3').addEvent('mouseleave', function(){
		document.id('poznaj').setStyle('background-image','url(images/strzalka.png)');												
	});
}

/*function parallax () {	
	j++;
	var speed1 = -(j * 1.6);	
	$("content1").setStyles({left : $("content1").getCoordinates().left + speed1});
}*/

