function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}


function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;

   return h ? h : 0;
}




var myImage = new Image();
var isLoaded = 0;
var imagePath;


function chkLoad() {
	//alert("check");
	
	//alert("NW: " + myImage.naturalWidth + "\n\nW: " + myImage.width);
	
	if(myImage.complete) {	
		if (myImage.width == "undefined" || myImage.width == "0") {
			//alert("failed");			
			return false;
		}
		else
		{
			//alert("loaded");
			
			
									// set all details
						if (document.getElementById) {
							var windowHeight = getWindowHeight();

							var scroll = getScrollHeight();

							if (windowHeight > 0) {
								var contentElement = document.getElementById('content');

								var contentHeight = contentElement.offsetHeight;

								//alert(document.getElementById('largeImage').height);

								var contentHeight = myImage.height;

								//alert("Window Height: " + (windowHeight / 2) +
								//"\n\nContent Height: " + (contentHeight / 2) +
								//"\n\nScroll: " + scroll);

								if (windowHeight - contentHeight > 0) {
									//contentElement.style.position = 'relative';
									contentElement.style.position = 'absolute';
									contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2) + scroll) + 'px';
								}
								else {
									contentElement.style.position = 'static';
								}
							}
						}
			
			
			document.images['largeImage'].src=myImage.src;
			clearInterval(isLoaded); 
		}

	}
}



function setContent(image) {
	//document.images['largeImage'].src="i/loading.gif";
	imagePath = "i/art/large/" + image;

	myImage = new Image();
	myImage.src = imagePath;

	chkLoad();

	if(!myImage.complete) {
			document.images['largeImage'].src="i/loading.gif";
			isLoaded = setInterval('chkLoad()',1000);
	}
	else if(myImage.width == "undefined" || myImage.width == "0")
	{
		document.images['largeImage'].src="i/loading.gif";
		isLoaded = setInterval('chkLoad()',1000);
	}






	//var obj = document.getElementById("largeImage");
	//imagePath = "i/art/large/" + image;
	
	//obj.src = imagePath;

	if (document.getElementById) {
		var windowHeight = getWindowHeight();

		var scroll = getScrollHeight();

		if (windowHeight > 0) {
			var contentElement = document.getElementById('content');
			
			//var contentHeight = contentElement.offsetHeight;
			
			var contentHeight = document.getElementById('largeImage').height;
			
			var contentHeight = myImage.height;
						
			//alert(document.getElementById('largeImage').height);
			
			//var contentHeight = document.getElementById('largeImage').style.height;
			
			//alert("Window Height: " + (windowHeight / 2) +
			//"\n\nContent Height: " + (contentHeight / 2) +
			//"\n\nScroll: " + scroll);
			
			if (windowHeight - contentHeight > 0) {
				//contentElement.style.position = 'relative';
				contentElement.style.position = 'absolute';
				contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2) + scroll) + 'px';
			}
			else {
				contentElement.style.position = 'static';
			}
		}
	}

}

function switcher() {
	var obj = document.getElementById("dimmer");
	
	this.page = getPageDimensions();

	obj.style.width = this.page.scrollWidth + 'px';
	obj.style.height = this.page.scrollHeight + 'px';


		// reset opacity
	obj.style.visibility = 'visible';
	obj.style.opacity = 0.0;
	obj.style.zoom = 1;
	obj.style.filter =  "alpha(opacity=00)";

	fadeIn("dimmer",1000);


	obj = document.getElementById('content').style;
	obj.opacity = 0.0;
	obj.zoom = 1;
	obj.filter =  "alpha(opacity=00)";

	obj.visibility == 'visible' ? obj.visibility = 'hidden' : obj.visibility = 'visible';
}

function fadeIn(target, milli)
{
	var speed = Math.round(milli / 100);
	var timer = 0;

	for(x=1;x<=70;x++)
	{
		setTimeout("setOpacity(" + x + ",'" + target + "')",(timer * speed));
		timer++;
	}
}

function fadeInPic(target, milli)
{
	var speed = Math.round(milli / 100);
	var timer = 0;

	for(x=1;x<=100;x++)
	{
		setTimeout("setOpacity(" + x + ",'" + target + "')",(timer * speed));
		timer++;
	}
}

function setOpacity(opac, target)
{
	var obj = document.getElementById(target).style;

	obj.opacity = (opac / 100);
	obj.filter = "alpha(opacity=" + opac + ")";

	if(opac==40 && target=="dimmer")
	{
			fadeInPic("content",1500);
	}
}

function fadeOpacity(opac, target)
{
	var obj = document.getElementById(target).style;

	obj.opacity = (opac / 100);
	obj.filter = "alpha(opacity=" + opac + ")";
	
	if(opac==0 && target=="dimmer" || target=="content")
	{
		obj.visibility = 'hidden';
		obj.opacity = 0.0;
		obj.zoom = 1;
		obj.filter =  "alpha(opacity=00)";
	}
}

function getPageDimensions()
{
	var dE = document.documentElement || document.body;

	return {
		scrollWidth: Math.max(dE.scrollWidth, dE.clientWidth),
		scrollHeight: Math.max(dE.scrollHeight, dE.clientHeight),
		innerWidth: window.innerWidth || (dE.offsetWidth - 2 * (dE.clientLeft || 0)),
		innerHeight: window.innerHeight || (dE.offsetHeight - 2 * (dE.clientTop || 0)),
		availWidth: dE.clientWidth,
		availHeight: dE.clientHeight,
		offsetX: window.pageXOffset || dE.scrollLeft,
		offsetY: window.pageYOffset || dE.scrollTop
	};
}

function fadeOutAll(milli)
{
	clearInterval(isLoaded);
	
	var speed = Math.round(milli / 100);
	var timer = 0;

	for(x=69;x>=0;x--)
	{
		setTimeout("fadeOpacity(" + x + ",'dimmer')",(timer * speed));
		setTimeout("fadeOpacity(" + x + ",'content')",(timer * speed));
		timer++;
	}
}
