// Foto script by Ojars Krumins
var fade_pos = 0;
var fade_step = 0;
var foto_version = 0;

function fotoShowInternal( nr ) 
{
	document.getElementById('divFotoLoading').style.display = "block";
	
	fade_step = -0.1;
	setTimeout("fotoFade();", 1 );

	imgLoad = new Image();
	
	imgLoad.onload=function(){
		setTimeout("fotoFadeIn();", 250 );
	}

	if( foto_version == 0 ){
		if( nr < 10 )
			file = foto_dir + "foto0" + nr + ".jpg";
		else
			file = foto_dir + "foto" + nr + ".jpg";
	}
	else {
		if( nr < 10 )
			file = foto_dir + "foto00" + nr + ".jpg";
		else if( nr < 100 )
			file = foto_dir + "foto0" + nr + ".jpg";
		else
			file = foto_dir + "foto" + nr + ".jpg";
	}
	document.getElementById('divFotoNum').innerHTML = nr + " / " + foto_num;
	
	setTimeout( "imgLoad.src = file;", 1 );
	
}
function fotoFadeIn()
{
	document.getElementById('fotoImage').src = imgLoad.src;
	fade_step = 0.2;
	fotoFade();
	document.getElementById('divFotoLoading').style.display = "none";
}
function fotoFade()
{
	fade_pos = fade_pos + fade_step;
	if( fade_pos > 0 && fade_pos < 1 )
	{
		setTimeout('fotoFade()', 50 );
	}
	if( fade_pos < 0 ) fade_pos = 0;
	if( fade_pos > 1 ) fade_pos = 1;
	document.getElementById('fotoImage').style.opacity = fade_pos;
	document.getElementById('fotoImage').style.filter = "Alpha(opacity="+fade_pos*100+");";
}
function fotoShow( nr ) 
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	fade_pos = 0;
	fotoShowInternal( nr );
//onresize="alert('You have changed the size of the window')
	if( foto_see == 0 )
	{
		// for IE add the filter style
		if( navigator.appVersion.indexOf("MSIE")!=-1 )
		{
			document.getElementById('divFotoBackground').style.filter = "alpha(opacity=80);";
		}
	
		// overlay
		document.getElementById('divFotoBackground').style.width = arrayPageSize[0] + 'px';
		document.getElementById('divFotoBackground').style.height = arrayPageSize[1] + 'px';

		// image box
		document.getElementById('divFoto').style.top = (arrayPageScroll[1] + 20 + 'px');
		document.getElementById('divFoto').style.left = (((arrayPageSize[0] - 780) / 2) + 'px');
		
		// loading image
		document.getElementById('divFotoLoading').style.top = (arrayPageScroll[1] + 25 + 'px');
		document.getElementById('divFotoLoading').style.left = (((arrayPageSize[0] - 780) / 2 + 5) + 'px');

		// show all
		document.getElementById('divFoto').style.display = "block";
		document.getElementById('divFotoBackground').style.display = "block";
	}
	foto_see = nr;
}
function fotoHide() 
{
	foto_see = 0;
	document.getElementById('fotoImage').src = "bildes/1x1.gif";
	document.getElementById('divFoto').style.display = "none";
	document.getElementById('divFotoBackground').style.display = "none";
	document.getElementById('divFotoLoading').style.display = "none";
}
function fotoPrev() 
{
	if( foto_see > 1 )
	{
		foto_see--;
		fotoShowInternal( foto_see );
	}
}
function fotoNext() 
{
	if( foto_see < foto_num )
	{
		foto_see++;
		fotoShowInternal( foto_see );
	}
}
// END Foto script by Ojars Krumins



/// functions by other people ////////////


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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;
	if (self.innerHeight) {	// all except Explorer
		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;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


