function getPageSize(){

	var xScroll, yScroll;


	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

var imgId=0;

function hide_pick(){
var objOverlay = document.getElementById('photogal');
var objLightbox = document.getElementById('lightbox');
document.getElementById('photogal_img').style.display='none';
objOverlay.style.display='none';
objLightbox.style.display = 'none';
showSelectBoxes();
objLightbox.style.width=150;
objLightbox.style.height=200;
document.getElementById('photogal_pagesdiv').style.display='none';
document.getElementById('photogal_img').innerHTML ='';
}


var endWidth=820;
var endHeight=620;
var step=10;
var interval=10;
var stop=0;

function show_img(step){
var f=1;
var count=document.getElementById('photogal_count').value;
var nid=imgId+step;
if(nid>count)f=0;
if(nid<1)f=0;
if(f){
imgId=nid;
var img=document.getElementById('img_'+nid).src;
img=img.replace("/preview/","/");
var title=document.getElementById('imgtitle_'+nid).innerHTML;
document.getElementById('photogal_pagesdiv').style.display='none';
document.getElementById('lightbox').style.height=endHeight;
document.getElementById('photogal_img').innerHTML = '<img src='+img+' width=800 height=600></img>';
document.getElementById('photogal_img').style.display='block';
//document.getElementById('photogal_title').innerHTML = title;
show_pick(0);
}
}

function mkPages(){
	var count=document.getElementById('photogal_count').value;
	document.getElementById('photogal_title').innerHTML=document.getElementById('imgtitle_'+imgId).innerHTML;
	document.getElementById('photogal_pages').innerHTML = imgId+' <font color="#000000">θη '+count+'</font>';
	document.getElementById('photogal_pagesdiv').style.display='block';
}


function start(id){
var sizes=getPageSize();
var objOverlay = document.getElementById('photogal');
var objLightbox = document.getElementById('lightbox');
objOverlay.style.width=sizes[0];
objOverlay.style.height=sizes[1];

objLightbox.style.top=(sizes[3]-620)/2+document.body.scrollTop;
objLightbox.style.left=(sizes[0]-150)/2+document.body.scrollLeft;
hideSelectBoxes();
document.getElementById('lightbox').style.display = 'block';
document.getElementById('photogal').style.display = 'block';
imgId=id;
animate(endHeight);
}



function animate(){
	var box=document.getElementById('lightbox');
	//alert(box.offsetHeight);
	if(box.offsetHeight>=endHeight){
	if(box.offsetWidth>=endWidth){stop=1;}else{box.style.left=box.offsetLeft-step/2;box.style.width=box.offsetWidth+step;}
	}else{box.style.height=box.offsetHeight+step;}
	if(stop){stop=0;show_img(0);}else{setTimeout("animate();", interval);}
}

function show_pick(op){
var nop=op+2;
imgdiv=document.getElementById('photogal_img');
imgdiv.style.filter='alpha(opacity='+nop+')';
//imgdiv.style.opacity=nop;
//imgdiv.style.-moz-opacity=nop;
//imgdiv.style.filters["alpha"].opacity=nop; //IE
imgdiv.style.MozOpacity=nop/100; //Mozilla
imgdiv.style.opacity=nop/100 //Opera
if(nop>=100){stop=1;}
var box=document.getElementById('lightbox');
	if(box.offsetHeight<endHeight+50){box.style.height=box.offsetHeight+1;}

if(stop){stop=0;mkPages();}else{setTimeout("show_pick("+nop+");", interval);}
}

function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}