
var diaporama;
var next;
var delay = 5000;

function getScrollY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}

function collectionPopup(id,lang,inside)
{	
	beforePopup(inside);
	new Ajax.Updater('gallery_content', '/collection/show/'+id+'?lang='+lang, 	
		{	asynchronous:true, evalScripts:true,
			onComplete:function(request){ afterPopup(inside) },
			onLoading:function(request){}
		}); 
	return false;
}

function collectionPopupTxt(id,lang,inside)
{	
	beforePopup(inside);
	new Ajax.Updater('gallery_content', '/collection/showtext/'+id+'?lang='+lang, 	
		{	asynchronous:true, evalScripts:true,
			onComplete:function(request){ afterPopup(inside) },
			onLoading:function(request){  }
		}); 
	return false;
}

function parcourPopup (id,wid,lang)
{
	parcourPopup(id,wid,lang,false,false);	
}

function parcourPopupInside (id,wid,lang,diaporama)
{
	parcourPopup(id,wid,lang,diaporama,true);	
}

function parcourPopup (id,wid,lang,diaporama,inside)
{
	beforePopup(inside);
	new Ajax.Updater('gallery_content', '/parcour/go/'+id+'?wid='+wid+'&lang='+lang+'&diaporama='+diaporama, 	
		{	asynchronous:true, evalScripts:true,
			onComplete:function(request){ afterPopup() },
			onLoading:function(request){  }
		});
	return false; 
}

function parcourPopupTxt(id,wid,lang,diaporama,inside)
{	
	beforePopup(inside);
	new Ajax.Updater('gallery_content', '/parcour/showtext/'+id+'?wid='+wid+'&lang='+lang+'&diaporama='+diaporama,	
		{	asynchronous:true, evalScripts:true,
			onComplete:function(request){ afterPopup(inside) },
			onLoading:function(request){  }
		}); 
	return false;
}

function beforePopup (inside)
{
	var scrollOffset = 0;
	var startOffset = 65;

	document.body.style.cursor = 'wait';
	
	if(!inside)
	{
		/*Try.these(		
			function () {scrollOffset = window.pageYOffset;}
			function () {scrollOffset = document.body.scrollTop;}
			function () {scrollOffset = document.documentElement.scrollTop();}
		)*/
		scrollOffset = getScrollY();

		Element.setStyle('gallery',{top:(startOffset+scrollOffset) +'px'});	
		
		$('gallery_content').innerHTML='<table width=100% height=100%><tr valign=middle align=center><td>LOADING ..</td></tr></table>';			
	}
	else
	{
		// $('gallery_main').innerHTML='<table width=100% height=100%><tr valign=middle align=center><td>LOADING ..</td></tr></table>';
	}
}

function afterPopup (inside)
{
	document.body.style.cursor = 'default';
	if (!inside)
		new Effect.Appear('gallery');
}

// menu popups:


function keepPopup(name)
{
	
	Try.these(
		function () {eval("window.clearTimeout(to_"+name+")"); }
	)
}

function delPopup(name)
{
	Try.these(
		function () { eval("window.clearTimeout(to_"+name+")"); }
	)
	Try.these(
		function () { eval("to_"+name +" = window.setTimeout('Element.hide(\""+name+"\")',40);"); }
	)
	
}


// gallery images:

function switchGalleryImage(img_src)
{
	$('gallery_img_main').innerHTML = 
		'<img id="main_image" src="/img/collection/' + img_src + '" alt="" border="0">';
}


// diaporama
 
function stopDiaporama()
{
	if (diaporama) {
		window.clearTimeout(diaporama);
		$('dia').innerHTML = '<a href="#" onClick="startDiaporama()"><img src="/img/diaporama.gif" border="0" alt="dia" /> diaporama</a>';
	}
}

function startDiaporama()
{
	if (next) {
		diaporama = window.setTimeout('eval(next)',delay); 
		$('dia').innerHTML = '<a href="#" onClick="stopDiaporama()"><img src="/img/diaporama_stop.gif" border="0" alt="dia" /> stop</a>';
	}
}



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

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


function onloadfunc() {
	// Browser Check
	var detect = navigator.userAgent.toLowerCase();
	var OS,browser,version,total,thestring;

	if (checkIt('msie')) browser = "Internet Explorer"
	if (!version) version = detect.charAt(place + thestring.length);

	function checkIt(string)
	{
		place = detect.indexOf(string) + 1;
		thestring = string;
		return place;
	}

	if(browser=="Internet Explorer" && version < 6)
		alert("Internet Explorer below version 6 is not supported by this Website. \nPlease update your browser!\nWe recommend Mozilla Firefox.\n");
	else if(browser=="Internet Explorer"  && version == 6)
	{	
		Element.setStyle('bg_img',{width:(getWidth()) +'px'});
		Element.setStyle('bg_img',{height:(getHeight()) +'px'});
	}
}
