/* PRZEWIJANIE */
var position = 0;
var itemWidth = 77;	
var items = descriptions.length - 1;	// ilosc elementow

if (items > 2) {
	var current_item = 3;				// aktualny element
} else {
	var current_item = items;	
}
						
var rodzic; 

window.addEvent("load", function () {

	rodzic = new Fx.Scroll("thumbs");
	setItemInfo(current_item);
	
	$("prev").addEvent("click", function (e) {
		new Event(e).stop(); // zamiast return false;
		if (current_item > 2 && (current_item + 1) < items) {
			position -= itemWidth;
			rodzic.scrollTo(position, 0);
			$('thumb_'+current_item).style.borderColor = "#D0B675";			
			current_item--; 		   // ustaw element
			setItemInfo(current_item); // aktualizuj dane elementu
		} else if (current_item > 0) {
			$('thumb_'+current_item).style.borderColor = "#D0B675";			
			current_item--; 		   // ustaw element
			if (current_item < 1)
				current_item = 1;
			setItemInfo(current_item); // aktualizuj dane elementu	
		}	
	});	
	
	$("next").addEvent("click", function (e) {
		new Event(e).stop(); // zamiast return false;
		if ((current_item + 2) < items && current_item > 1) {
			position += itemWidth;
			rodzic.scrollTo(position, 0);
			$('thumb_'+current_item).style.borderColor = "#D0B675";
			current_item++; 	       // ustaw element
			setItemInfo(current_item); // aktualizuj dane elementu				
		} else {
			$('thumb_'+current_item).style.borderColor = "#D0B675";
			current_item++; 	       // ustaw element
			if (current_item > items)
				current_item = items;
			setItemInfo(current_item); // aktualizuj dane elementu		
		} 		
	});
});

function goTo(id)
{
	if (id > current_item) { // w prawo	
		while (id > current_item) 
		{	
			if ((current_item + 2) < items && current_item > 1) {
					position += itemWidth;
					$('thumb_'+current_item).style.borderColor = "#D0B675";
					current_item++; 	       // ustaw element			
			} else {
					$('thumb_'+current_item).style.borderColor = "#D0B675";
					current_item++; 	       // ustaw element
					if (current_item > items)
					current_item = items;	
			} 
		}
		rodzic.scrollTo(position, 0);
		setItemInfo(current_item); // aktualizuj dane elementu					
	} else if (id < current_item) { // w lewo
		while (id < current_item) 
		{
			if (current_item > 2 && (current_item + 1) < items) {
				position -= itemWidth;
				$('thumb_'+current_item).style.borderColor = "#D0B675";			
				current_item--; 		   // ustaw element
			} else if (current_item > 0) {
				$('thumb_'+current_item).style.borderColor = "#D0B675";			
				current_item--; 		   // ustaw element
				if (current_item < 1)
					current_item = 1;
			}			
		}
		rodzic.scrollTo(position, 0);
		setItemInfo(current_item); // aktualizuj dane elementu
	}
	return false;
}


function setItemInfo(item) 
{
	$('numer').setHTML("<strong>NAZWA SUKNI:</strong> "+descriptions[item]);	
	$('thumb_'+item).style.borderColor = "#E50004";
	$('bigPhoto').style.display = "none";
	var start = new Image();
	start.src = "public/kolekcje/"+filenames[item];
	start.onload = 
	function() { 
		$('bigPhoto').src = "public/kolekcje/"+filenames[item];
		$('bigPhoto').style.display = "inline";
	} 
/*	
	if (start.complete) {
		$('bigPhoto').style.visibility = "visibility";
	} */	
}

