//Combobox redirection - onChange event
	function GalleryRedirect(){
		oForm = document.frmGalleryRedirect;
		oForm.submit();
	}
	//Display gallery
	function GalleryDisplay(){		
		if (! GalleryDisplayCostumPicture(sPic)){
			//Display small list
			GalleryGenSmallList();			
			//Display first picture		
			oFirstPic = document.getElementById("GallerySmallPic1");
			if(oFirstPic) GalleryDisplayImage(oFirstPic);			
		}
	}
	function GalleryDisplayEx(arGalleryList){
	    arSmallPics = arGalleryList;
	    GalleryDisplay();
	}
	
	function GalleryDisplayInPopup(arGalleryList, divGalleryID, iRecordID){
	    GalleryDisplayEx(arGalleryList);	
		Div_CopyContent("Gallery_Title" + iRecordID,"Gallery_Title");
		Div_CopyContent("Gallery_Summery" + iRecordID,"Gallery_Summery");
		Div_CopyContent("Gallery_Description" + iRecordID,"Gallery_Description");
		
			
		var screenWidth = 0, screenHeight = 0;
        
        if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
            screenWidth = window.innerWidth;
            screenHeight = window.innerHeight;
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            screenWidth = document.documentElement.clientWidth;
            screenHeight = document.documentElement.clientHeight;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            screenWidth = document.body.clientWidth;
            screenHeight = document.body.clientHeight;
        }
		
		document.getElementById('Popup_Gallery_Container_Table').style.height = screenHeight + "px";
		document.getElementById('Popup_Gallery_Container_Table').style.width = screenWidth + "px";
		
		
		var docHeight = GetDocumentHeight();
		var docWidth = GetDocumentWidth();
		
		var shadowHeight;
		
		if (docHeight < screenHeight) {
		shadowHeight = screenHeight;
		}
		else{
		shadowHeight = docHeight;
		}
		
				
		document.getElementById('Popup_Gallery_Shadow').style.height = shadowHeight + "px";
		document.getElementById('Popup_Gallery_Shadow').style.width = docWidth + "px";
		
		self.scrollTo(0,0);
		PagePopup_Show(true, divGalleryID);
	}


  

	
	function GalleryDisplayCostumPicture(sPicture){
		var iPos = -1;
		
		sPicture = sPicture.toLowerCase();
		for(var i = 0; i< arSmallPics.length; i++){
			var arRecord = arSmallPics[i];
			if (arRecord[1].toLowerCase() == sPicture){
				iPos = i;
			}
		}
		//Calc page
		if (iPos > -1){
		
			iPage = Math.floor(iPos / iGallerySmallPicsRecords);	
			//Set new start pos for display
			iGallerySmallPicsStart = iPage * iGallerySmallPicsRecords;
			//Display small list
			GalleryGenSmallList();	
			var oPicture = document.getElementById("GallerySmallPic"+(iPos - iGallerySmallPicsStart + 1));
			if(oPicture) GalleryDisplayImage(oPicture);
		}
		
		return (iPos > -1);
	}
	
	
	//Display small list from array
	function GalleryGenSmallList(){
		//Display navigation
		GalleryNavDisplay();
		//Small pics
		var oSmallPic = null;
		var arSmallPic = null;
		var iSmallPicIndex = 1;		
		for(var i = 1 ; i <= iGallerySmallPicsRecords; i++){					
			oSmallPic = document.getElementById("GallerySmallPic" + i);	
			
			if (oSmallPic){	
			
				iSmallPicIndex = i + iGallerySmallPicsStart;						
				if(iSmallPicIndex <= arSmallPics.length) {
						
					arSmallPic = arSmallPics[iSmallPicIndex - 1];					
					GallerySmallPicDisplay(oSmallPic, arSmallPic);
					//oSmallPic.style.visibility = '';
				}else{
					arSmallPic = null;
					GallerySmallPicHide(oSmallPic);	
					//oSmallPic.style.visibility = 'hidden';				
				}				
			}
			else{
				//Napaka - logika ni nala objekta / slike, ce pride do tega logika ne naredi nic
				oSmallPic = null;
			}
		}
	}
	
	//Show small image
	function GallerySmallPicDisplay(oSmallPic, arData){
		oSmallPic.src = sGalleryPicsDir + arData[0];		
		oSmallPic.setAttribute("imgpath", arData[1]);
		oSmallPic.setAttribute("imgdesc", arData[2]);
		oSmallPic.setAttribute("imgenabled", 1);
		oSmallPic.className = "gallerysmallimage";
	}
	
	//Hide small image
	function GallerySmallPicHide(oSmallPic){
		oSmallPic.src = "images/1px.gif";
		oSmallPic.className = "gallerysmallimagehidden";
		oSmallPic.setAttribute("imgenabled", 0);
	}
	
	//Display big image - details (on small image click)
	function GalleryDisplayImage(oSmallPic){		
		//Read data
		var sPicSrc = oSmallPic.getAttribute("imgpath");
		var sPicDesc = oSmallPic.getAttribute("imgdesc");
		var sPicEnabled = oSmallPic.getAttribute("imgenabled");
		
		//Exit if picture is desabled
		if (parseInt(sPicEnabled) != 1) return false;
		//Set data
			//Picture
			
		var oPic = document.getElementById("galleryimage");
		oPic.src = sGalleryPicsDir + sPicSrc;
		oPic.className = "galleryimage";
			//Description
		var oPicDesc = document.getElementById("Gallery_Image_Description");		
		oPicDesc.innerHTML = sPicDesc;
			//Current status
		var oPicCurrentStatus = document.getElementById("gallerycurrentstatus");
		var iPicNo = parseInt(oSmallPic.getAttribute("imgno"));
		var iPicNoWithCurrPage = iGallerySmallPicsStart + iPicNo;
		oPicCurrentStatus.innerHTML = "Slika <b>" + iPicNoWithCurrPage + "</b> od " + GalleryPicsCount();
			//Current pic number (next, priv button)
		iCurrentPicture = iPicNo; 
			//Display next/priv button
		GaleryNextDisplay();		
		return true;	
	}
	
	//Display image from small image index - only shell, logic in GalleryDisplayImage
	function GalleryDisplayImageIndex(iIndex){
		var sSmallPicID = "GallerySmallPic" + iIndex;
		var oSmallPic = document.getElementById(sSmallPicID);
		//Samo ce mala slika obstaja zazenes prikaz velike - do tega naj ne bi prislo
		if (oSmallPic)GalleryDisplayImage(oSmallPic);
	}
	
	//Small pictures count
	function GalleryPicsCount(){
		return arSmallPics.length;
	}	
	
	//Left navigation - sets indexes and refresh small list
	function GalleryNavLeft(){
		//Set start index
		iShiftLeft = iGallerySmallPicsStart - iGallerySmallPicsRecords;			
		if(iShiftLeft >=0 ){
			iGallerySmallPicsStart = iShiftLeft;
			//Refresh list
			GalleryGenSmallList();
			//Display last image
			var oLastEnabledPic = GalleryLastEnabledPic();
			if (oLastEnabledPic) GalleryDisplayImage(oLastEnabledPic);
						
		}
		else if(iShiftLeft < 0){//!!!Mislim da ta del ni pomemben
			//Refresh list
			//GalleryGenSmallList();
		}
	}
	
	//Right navigation - sets indexes and refresh small list
	function GalleryNavRight(){		
		//Set start index
		iShiftRight = iGallerySmallPicsStart + iGallerySmallPicsRecords;		
		if (iShiftRight < GalleryPicsCount()){
			iGallerySmallPicsStart = iShiftRight;
			//Refresh list
			GalleryGenSmallList();
			//Display first picture if exists
			GalleryDisplayImageIndex(1);
		}				
	}
	
	//Enable / Disable navigation - only display, indexes are set in GalleryNavLeft, GalleryNavRight
	function GalleryNavDisplay(){
		//Objects
		var oNavLeft = document.getElementById("gallerynavleft");
		var oNavRight = document.getElementById("gallerynavright");
		if (!oNavLeft) return false;
		if (!oNavRight) return false;
		
		//Left navigation
		if (iGallerySmallPicsStart <=0 ){//Disable			
			oNavLeft.src = "images/standardGallery/gallery_button_left.gif";
			oNavLeft.className = "";			
		}else{//Enable
			oNavLeft.src = "images/standardGallery/gallery_button_left_selected.gif";
			oNavLeft.className = "link";
		}
		
		//Right navigation
		if ( (iGallerySmallPicsStart +  iGallerySmallPicsRecords) >= GalleryPicsCount() ){//Disable			
			oNavRight.src = "images/standardGallery/gallery_button_right.gif";
			oNavRight.className = "";			
		}else{//Enable
			oNavRight.src = "images/standardGallery/gallery_button_right_selected.gif";
			oNavRight.className = "link";
		}		
	}
	
	//Return last small picture, that's enabled in list
	function GalleryLastEnabledPic(){
		var oSmallPic = null;
		var oLastEnabledPic = null;
		
		for(var i = 1 ; i <= iGallerySmallPicsRecords; i++){					
			oSmallPic = document.getElementById("GallerySmallPic" + i);			
			if (oSmallPic){
				//Exit if picture is desabled
				var sPicEnabled = oSmallPic.getAttribute("imgenabled");
				//Picture is enabled
				if (parseInt(sPicEnabled) == 1) oLastEnabledPic = oSmallPic;
			}
			else{
				//Napaka - logika ni nala objekta / slike, ce pride do tega logika ne naredi nic
				oSmallPic = null;
			}
		}
		return oLastEnabledPic;
	}
	
	//Next / Prev pic navigation
	//Priv. button
	function GalleryNextLeft(){
		//Prejsnja slika
		var iPrevPic = iCurrentPicture - 1;
		//Trenutna slika je prva, potrebno je se ugotoviti, ali smo na prvi ali na naslednji strani
		if(iPrevPic <= 0){			
			if (iGallerySmallPicsStart <= 0){ //Trenutna slika je prva, tako da prejsnja ne obstaja
				return;}
			else{//
				GalleryNavLeft();
				iPrevPic = iGallerySmallPicsRecords;
			}
		}				
		//Display prev pic		
		GalleryDisplayImageIndex(iPrevPic);	
		return;
	}
	//Next button
	function GalleryNextRight(){
		//Naslednja slika
		var iNextPic = iCurrentPicture + 1;
		//Trenutna slika je zadnja, tako da naslednja ne obstaja		
		if ((iGallerySmallPicsStart + iNextPic) > GalleryPicsCount()){ return;}
		//Naloi naslednjo stran, ter prikazi prvo sliko
		if (iNextPic > iGallerySmallPicsRecords){
			GalleryNavRight();
			iNextPic = 1;
			}
		//Display next pic		
		GalleryDisplayImageIndex(iNextPic);		
		return;
	}	
	//Display button
	function GaleryNextDisplay(){
		//Objects
		var oNextLeft = document.getElementById("gallerynextleft");
		var oNextRight = document.getElementById("gallerynextright");
		if (!oNextLeft) return false;
		if (!oNextRight) return false;
		//Left button
		if(((iCurrentPicture - 1) + iGallerySmallPicsStart) <= 0){//Disable
			oNextLeft.innerHTML = '<span class="galleryTextNavigation">&laquo; Prejšnja slika</span>';
			//oNextLeft.innerHTML = '&nbsp;';
		}else{//Enable
			oNextLeft.innerHTML = '<a href="javascript:GalleryNextLeft();">&laquo; Prejšnja slika</a>';
		}
		//Right		
		if((iCurrentPicture + iGallerySmallPicsStart) >= GalleryPicsCount()){//Disable
			oNextRight.innerHTML = '<span class="galleryTextNavigation">Naslednja slika &raquo;</span>';
			//oNextRight.innerHTML = '&nbsp;';
		}else{//Enable
			oNextRight.innerHTML = '<a href="javascript:GalleryNextRight();">Naslednja slika &raquo;</a>';
		}
	}
	
	
	
	// It's time for this frog to hop
	//function initGallery(){ GalleryDisplay(); }
	//Event.observe(window, 'load', initGallery, false);
