var fotocollectie = ( function()
{

var shade ;
var zoomer ;
var div_image ;
var p_titel ;

var preloaded_images = new Array() ;
var current_index = 0 ;

window .onload = init ;

function init()
{
	shade = document .getElementById( 'div_shade' ) ;	
	zoomer = document .getElementById( 'fieldset_zoomer' ) ;	
	div_image = document .getElementById( 'div_image' ) ;	
	p_titel = document .getElementById( 'p_titel' ) ;	

	init_shade() ;
	preload_images() ;	
}

function init_shade()
{
	shade .style .height = get_page_height() + 'px' ;

	if ( shade .style .MozOpacity != undefined )
	{
		shade .style .MozOpacity = 0.75 ; 
	}
	else if ( shade .style .filter != undefined )
	{
		shade .style .filter = "alpha(opacity=55)" ;
	}

	shade .onclick = function()
			 {
				shade .style .visibility = 'hidden' ;
				zoomer .style .visibility = 'hidden' ;
			 }
}

function preload_images()
{
	var images = document .getElementById( 'hidden_images' ) .value .split( ';;' ) ;
	for ( var t = 0 ; t < images .length ; t+=2 )
	{
		if ( images[ t ] != '' )
		{
			var img = document .createElement( 'img' ) ;
			img .src = site_url + '/beyond_files/get_image/' + images[ t ] ;
			img .alt = images[ t ] ;

			preloaded_images .push( [ img, images[ t +1 ] ] ) ;
		}
	}
}

function get_page_height()
{
	var height = null ;

	var test1 = document .body .scrollHeight;
	var test2 = document .body .offsetHeight ;
	if ( test1 > test2 ) // all but Explorer Mac
	{
		height = document .body .scrollHeight ;
	}
	else // Explorer Mac, would also work in Explorer 6 Strict, Mozilla and Safari
	{
		height = document .body .offsetHeight ;
	}

	return height + 50 ;
}

function show_image( index )
{
	if ( index < 0 )
	{
		index = preloaded_images .length -1 ;
	}
	else if ( index >= preloaded_images .length )
	{
		index = 0 ;
	}

	current_index = index ;

	shade .style .visibility = 'visible' ;

	//titel
	p_titel .innerHTML = preloaded_images[ index ][ 1 ] ;

	if ( p_titel .innerHTML == '' )
	{
		p_titel .innerHTML = '<br />' ;
	}

	//image
	var img = preloaded_images[ index ][ 0 ] ;
	if ( div_image .firstChild != null )
	{
		div_image .removeChild( div_image .firstChild ) ;
	}
	div_image .appendChild( img ) ;
	
	zoomer .style .width = img .offsetWidth + 'px' ; 
	zoomer .style .left = ( ( get_document_width() - img .offsetWidth ) / 2 ) + 'px' ;
	zoomer .style .top = ( get_scroll_offset() + ( ( get_document_height() - zoomer .offsetHeight ) / 2 ) ) + 'px' ;

	zoomer .style .visibility = 'visible' ;
}

function get_document_width()
{
        if ( typeof( window .innerWidth ) == 'number' )
        {
                //Non-IE
                return window .innerWidth ;
        }
        else if ( document .documentElement && document .documentElement .clientWidth )
        {
                //IE 6+ in 'standards compliant mode'
                return document .documentElement .clientWidth ;
        }
        else if ( document .body && document .body .clientWidth )
        {
                //IE 4 compatible
                return document .body .clientWidth ;
        }

        return 200 ; //at least we see something in this exceptional case
}

function get_document_height()
{
        if ( typeof( window .innerHeight ) == 'number' )
        {
                //Non-IE
                return window .innerHeight;
        }
        else if ( document .documentElement && document .documentElement .clientHeight )
        {
                //IE 6+ in 'standards compliant mode'
                return document .documentElement .clientHeight ;
        }
        else if ( document .body && document .body .clientHeight )
        {
                //IE 4 compatible
                return document .body .clientHeight ;
        }

        return 200 ; //at least we see something in this exceptional case
}

function get_scroll_offset()
{
	var y;
	if (self.pageYOffset) // all except Explorer
	{
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		y = document.body.scrollTop;
	}

	return y ;
}

function next()
{
	show_image( current_index +1 ) ;
}

function previous()
{
	show_image( current_index -1 ) ;
}

return {
        show_image : show_image,
	next : next,
	previous : previous
} ;

} ) () ;
