//----------------------------------------------------------------------------
// Параметри

var ImageSite = "img_site";	// ID на тага IMG, в който се зареждат изображенията
var ImageLink = "img_link"; // ID на таг A, който обхваща изображението и дублира като линк LnkPrefix+...
var ImgTitlesSite = "img_title";  // ID на таг, който съдържа заглавие на текущото изображение 
var LnkPrefix = "lpr_";			// Префикс за идент.на линкове, които си променят стила 
var BtnPrefix = "ibtn_";  	// Префикс за идент.на бутончета за отделните изображения
var CurrentLnkClassName = "current";		// Име на допълващ клас за текущ линк
var CurrentBtnClassName = "PrtfPage_Current";		// Име на заменящ клас за текущо бутонче
var AutoDelay = 2000;						// пауза (в милисекунди) за автоматично превъртане

//----------------------------------------------------------------------------
// Оттук надолу е код, който не се променя
var Cimg=0;		 // Номер на текущото изображение
var a_tout=0;  // id за settimeout

function GalleryAutoOff() {
	if(  a_tout )  { clearTimeout(a_tout);	a_tout = 0; }  	
}

function GalleryAutoRoll() {	
	GalleryGotoImage(  Cimg == Nimg ? 1 : Cimg+1);
  a_tout = setTimeout( GalleryAutoRoll,AutoDelay);
}

function GalleryAutoOn() {
	if(  ! a_tout )	  GalleryAutoRoll();
}

function GallerySetPrev() {
	var vnew;
	if(  Cimg == 1 ) {
	  if( PrevPage )  {
	    window.location = PrevPage;  return;
	  }
	  vnew = Nimg;
	} else  vnew = Cimg-1;
	GalleryAutoOff();  GalleryGotoImage(vnew);
}

function GallerySetNext() {
	var vnew;
	if(  Cimg == Nimg ) {
	  if( NextPage )  {
	    window.location = NextPage;  return;
	  }
	  vnew = 1;
	} else  vnew = Cimg+1;
	GalleryAutoOff();  GalleryGotoImage(vnew);
}

function GalleryGotoImage(ix) {
	var v,u;
	if(  Cimg ) {
		if(  (v=document.getElementById(LnkPrefix+Cimg)) )
			v.className = v.oldClassName;
		if(  v=document.getElementById(BtnPrefix+Cimg) )  v.className = v.oldClassName;
	}
	Cimg = ix;
	if(  v=document.getElementById(LnkPrefix+Cimg) ) {
		v.oldClassName = v.className;  v.className += " "+CurrentLnkClassName;
		if(  u=document.getElementById(ImageLink) )  u.href = v.childNodes[0].href;
	}
	if(  v=document.getElementById(BtnPrefix+Cimg) ) {
	  v.oldClassName = v.className;  v.className = CurrentBtnClassName;
	}
	if(  v=document.getElementById(ImgTitlesSite) ) {
//	alert(ImageTitles);
	  v.childNodes[0].nodeValue = ImageTitles[Cimg-1];
	}
	
	if(  (u=ImageFolder) )  u += "/";
	v = document.getElementById(ImageSite);  v.src = u+JpegPrefix+Cimg+".jpg";
}

function GallerySetImage(ix) {
//	alert(btn);
//  var ix=parseInt(btn.id.substr(BtnPrefix.length));
//  if(  ix > 0 && ix <= Nimg ) {
	GalleryAutoOff();  GalleryGotoImage(ix);
//  }
}

function GalleryInit(setauto) {
	GalleryGotoImage(1);
	if(setauto)  a_tout = setTimeout( GalleryAutoRoll,AutoDelay);
}
