// JavaScript Document
var block="block";
var browser=navigator.appName;
if(browser=='Netscape'){ block="table-row"; }
//
var to_preload=new Array("/zoom/preview_over.png","/zoom/next_over.png","/zoom/x_over.png");
var preImages=new Array();
var gall_images=new Array();

var preloading_container;
var pic_screen;
var large_pict;

var selected_image="";
var loadInterval="";

//
function preloadImages(){
for (i = 0; i < to_preload.length; i++) { 
		preImages[i] = new Image()
		preImages[i].src = to_preload[i];
	}
}
var preloader_animation=new Image();
	preloader_animation.src="/zoom/preloader.gif";
//
function init(){
 preloadImages();
 pic_screen=document.getElementById("pic_screen");
 large_pict=document.getElementById("large_pict");
 var n=0
 	if(document.images)
	{
		for(var i=0; i<document.images.length; i++)
		{
			if(document.images[i].className=="small_pict"){
			gall_images[n]=document.images[i].src;
			n++;
			}
		}
	}
}

//
function prevImage(){
var prevKey = my_array_search(selected_image);
	if(array_key_exists(prevKey-1)){
		switchImage(gall_images[prevKey-1])
	}
}
//
function nextImage(){
var nextKey = my_array_search(selected_image);
	if(array_key_exists(nextKey+1)){
		switchImage(gall_images[nextKey+1])
	}
}
//
function over(obj){
obj.src=obj.src.split(".png").join("_over.png");
}
//
function out(obj){
obj.src=obj.src.split("_over.").join(".");
}
//
function closeImage(){
if(loadInterval!="")
clearInterval(loadInterval);
//
reset_position();
}
//
function switchImage(oSrc){
selected_image=oSrc;
large_pict.src=preloader_animation.src;
set_position();
preloading_container=new Image();
preloading_container.src=oSrc.split("/tumbn/").join("/");
//preloading_container.src=oSrc;
loadInterval = setInterval("is_Loaded()",100);
}
//
function is_Loaded(){
	if(preloading_container.complete){
	clearInterval(loadInterval);	
	loadInterval="";
	large_pict.src=preloading_container.src;
	set_position()
	}
}
//
function set_position(){
var size=get_WHS();
pic_screen.style.left=(size[0]-pic_screen.clientWidth)/2 + "px";
pic_screen.style.top=((size[1]-pic_screen.clientHeight)/2)+size[2] + "px";
}
//
function reset_position(){
pic_screen.style.left= -1000 + "px";
pic_screen.style.top= -1000 + "px";
}
//
// control tumbnail pages
function show_gallery(prev_oId, oId)
{
	if(document.getElementById(prev_oId)!=null)
	{
	document.getElementById(prev_oId).style.display="none";
	}
	if(document.getElementById(oId)!=null)
	{
	document.getElementById(oId).style.display=block;
	}

}
//
// util functions
function get_WHS() { var W,H,S;
	if (self.innerHeight) {	W = window.innerWidth; H = window.innerHeight; S = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) {W = document.documentElement.clientWidth; H = document.documentElement.clientHeight; S = document.documentElement.scrollTop;
	} else if (document.body) {W = document.body.clientWidth; H = document.body.clientHeight; S = document.body.scrollTop;}
return Array(W,H,S);
}
//
function my_array_search(needle){
	for(var i=0; i<gall_images.length; i++){
		if(gall_images[i] == needle){
		return i;
		}
	}
}
//
function array_key_exists(key){
	for(var i=0; i<gall_images.length; i++){
		if(i==key){
		return true;
		}
	}
}
// window.onload=init();
