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

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

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

	all_elems = getElementsByClassName('photos-links');
	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);
			$('thumb2_'+current_item).src = "templates/default/images/window.png";
			//$('thumb_'+current_item).style.borderColor = "#D0B675";			
			current_item--; 		   // ustaw element
			setItemInfo(current_item); // aktualizuj dane elementu
		} else if (current_item > 0) {
			$('thumb2_'+current_item).src = "templates/default/images/window.png";
			//$('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);
			$('thumb2_'+current_item).src = "templates/default/images/window.png";	
		//	$('thumb_'+current_item).style.borderColor = "#D0B675";
			current_item++; 	       // ustaw element
			setItemInfo(current_item); // aktualizuj dane elementu				
		} else {
			$('thumb2_'+current_item).src = "templates/default/images/window.png";
		//	$('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;
					$('thumb2_'+current_item).src = "templates/default/images/window.png";
					//$('thumb_'+current_item).style.borderColor = "#D0B675";
					current_item++; 	       // ustaw element			
			} else {
					$('thumb2_'+current_item).src = "templates/default/images/window.png";
				//	$('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;
				$('thumb2_'+current_item).src = "templates/default/images/window.png";
				//$('thumb_'+current_item).style.borderColor = "#D0B675";			
				current_item--; 		   // ustaw element
			} else if (current_item > 0) {
				$('thumb2_'+current_item).src = "templates/default/images/window.png";
				//$('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 getElementsByClassName(classname,tag) {
 if(!tag) tag = "*";
 var anchs =  document.getElementsByTagName(tag);
 var total_anchs = anchs.length;
 var regexp = new RegExp('\\b' + classname + '\\b');
 var class_items = new Array()
 
 for(var i=0;i<total_anchs;i++) { 
  var this_item = anchs[i];
  if(regexp.test(this_item.className)) {
   class_items.push(this_item);
  }
 }
 return class_items;
}


function setItemInfo(item) 
{
	$('numer').setHTML("<strong>"+descriptions[item]+"</strong> ");
	$('thumb2_'+current_item).src = "templates/default/images/a-window.png";

	for (var i = 1; i <= all_elems.length; i++)
	{
		$('bigPhotoLink_'+i).style.display = "none";
	}
	$('bigPhotoLink_'+item).style.display = "block";
	
		
	//$('thumb_'+item).style.borderColor = "#E50004";
	/*
	$('bigPhoto').style.display = "none";
	var start = new Image();
	start.src = "public/advgallery/"+filenames[item];
	start.onload = 
	function() { 
		$('bigPhoto').src = "public/advgallery/"+filenames[item];
		$('bigPhoto').style.display = "block";
		$('bigPhotoLink').href = "public/advgallery/"+bigfilenames[item];
	} */
/*	
	if (start.complete) {
		$('bigPhoto').style.visibility = "visibility";
	} */	
}

