
var img_array 			= new Array(); 	

var total_slots 		= 4; 	// palju slotte kokku on
var first_shown_index  	= 0; 	// esimese n2idatava pildi index	
var active_slot_index  	= 0; 	// milline slot on hetkel aktiivne
var active_image_name  	= ''; 	// akiivse pildi nimi


function next(){
	
	if( img_array.length > (total_slots + first_shown_index )  ){	
		first_shown_index++;
	}
	move();
}

function prev(){
	
	if( first_shown_index > 0  ){	
		first_shown_index--;
	}
	move();
	
}

function move(){
	
	var slot_i = 0;
	
	for( i=0; i<img_array.length; i++ ){
		
		if(slot_i >= total_slots ) break;	
		current_image_name = img_array[i];
		
		if( i >= first_shown_index ){
			var slot_obj = document.getElementById("slot_" + slot_i);
			slot_obj.src = "/res/images/square/" + current_image_name;
			
			var slot_div_obj = document.getElementById("slot_div_" + slot_i);
			
			if( current_image_name == active_image_name ){
				slot_div_obj.className = 'slimage_active';
				active_slot_index = slot_i;
			} else {
				slot_div_obj.className = 'slimage';
			}
			
			slot_i++;
		}
	}
	
	activateSlot( active_slot_index );
	
}


function activateSlot( slot_i ){
	
	// eelmine
	var slot_div_obj = document.getElementById("slot_div_" + active_slot_index); 
	slot_div_obj.className = 'slimage';
	
	// uus
	slot_div_obj = document.getElementById("slot_div_" + slot_i); 
	slot_div_obj.className = 'slimage_active';
	
	// seame globaalseks uue slot indexi
	active_slot_index = slot_i;
	
	// milline pilt selles slotis
	var i = active_slot_index +  first_shown_index;
	var current_image_name 	= img_array[i];
	active_image_name 		= current_image_name;
	var thumb_image_obj 	= document.getElementById("gallery_image");
	thumb_image_obj.src 	= "/res/images/thumb/" + current_image_name;
	
	
}

function openImage(url,width,height) {
	
	if (window.winName && !window.winName.closed) { 
		window.winName.close(); 
		window.winName = null; 
	}
	
	
	// url = "pilt.php?p="+url + "&w="+width + "&h="+height;
	
	//width  -=4;
	//height -=4;

	winName = open(url,"winName","width="+width+",height="+height+",status=no,toolbar=no,menubar=no,scrollbars=no");

}


function showActive(){
	if( active_image_name!='' ){
		openImage( '/res/images/full/'+active_image_name, 520, 400);
	}
}


function gImage( im ){
	
	var obj = document.getElementById("gallery_image");
	
	if( obj ){
		obj.src = im;
	}
	
}

function openVideo(video,width,height) {
	
	if (window.videoWindow && !window.videoWindow.closed) { 
		window.videoWindow.close(); 
		window.videoWindow = null; 
	}
	 
	url = "/video.php?video="+video + "&w="+width + "&h="+height; 	
	videoWindow = open(url,"videoWindow","width="+width+",height="+height+",status=no,toolbar=no,menubar=no,scrollbars=no,left=300,top=200");

}

