//scrolling
var currentPosition=0;
var iInterval;
var iCounter=0;
var iLimit=191; //width of image
var gallery;
function scrollPrev(){
	
}
 
 function galleryScrollTo(pos){
	 imageCount=imgCollection.length;
	 // not needed if image is less than or equal to 3
	// if (imageCount<=3) {return false;}
	 
	 for(i=-2;i<=2;i++){
		 _o=document.getElementById('img_thumb_' + (i+2) );
		put_pos=pos+i;
		 // if there are no previous images show last images
		 if(put_pos<0){
			 put_pos=imageCount+put_pos
		 }
		 
		 //if there are no next images show prev images
		 if (put_pos>imageCount-1){
			  put_pos=imageCount-put_pos
		 }
		 _o.src=imgCollection[put_pos] //change src 
		 _a=document.getElementById('href_thumb_' + (i+2) )
		 _a.href=imgCollectionBig[put_pos];
		 
	 }
	 currentPosition=pos;
 }
 
function slideNext(){
// iInterval=window.setInterval("timedSlideNext()",5);
 if(hasNext()){
	currentPosition++;
	galleryScrollTo(currentPosition)
 }else{
	 galleryScrollTo(0)
 }
 return false;
}

function slidePrev(){
// iInterval=window.setInterval("timedSlideNext()",5);
 if(hasPrev()){
	currentPosition--;
	galleryScrollTo(currentPosition)
 }else{
	 imageCount=imgCollection.length;
	 galleryScrollTo(imageCount-1)
 }
 return false;
}

function timedSlideNext(){
  //by default the margin left is 320px i shift 185 more becasue the image width is set to 185px;
  document.getElementById('scroller').style.marginLeft=((-1)*(320+iCounter))+"px";
  iCounter=iCounter+1;
  if(iCounter>=iLimit){
	  window.clearInterval(iInterval);
	  galleryScrollTo(currentPosition++);
	  iCounter=0;
	  document.getElementById('scroller').style.marginLeft=((-1)*(320+iCounter))+"px";
  }
}

function showImage(i)
{
	document.getElementById('img_big').src=imgCollection[i];
	currentPosition=i;
	return false;
}

function hasNext(){
	return imgCollection.length - 1 > currentPosition
}

function hasPrev(){
	return currentPosition>0;
}

function showNext(){
	if(hasNext()){
		currentPosition++;
		showImage(currentPosition)
	
	}
return false;
}

function showPrev(){
	 if(hasPrev()){
		currentPosition--;
		showImage(currentPosition);
	 }
	return false;
}

function showArrow(o){
	if(o.id=='href_prev'){
		if(hasPrev()){
			//fixPrevNext()
			o.style.background='url(/layout/images/prev.png) no-repeat left';
			o.style.cursor="pointer";
		}else{
			o.style.cursor="default";
		}
	}
	
	if(o.id=='href_next'){
		if(hasNext()){	
			//fixPrevNext()
			o.style.background='url(/layout/images/next.png) no-repeat center right';
			o.style.cursor="pointer";
		}else{
			o.style.cursor="default";
		}
	}
}

function hideArrow(o){
	o.style.background='url(/layout/images/blank.png)';
}
function fixPrevNext(){
_p=document.getElementById("href_prev")
_n=document.getElementById("href_next")
_o=document.getElementById("img_big");

_n.style.top="0px";
_p.style.top="0px";
_p.style.width="132px";
_n.style.width="132px";


}
