var ie = (!window.opera && document.all);
var dom = (!document.all && document.getElementById);
var gallery_index = 0;
var description_index = 0;

function ajaxManager()
{
	var args = ajaxManager.arguments;
	switch (args[0])
	{
		case "load_page":
			var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			pageWidth = document.body.clientWidth;
//			pageWidth = (dom) ? innerWidth : document.body.clientWidth;
			preload = document.getElementById("preloadLYR");
			gallery = document.getElementById("galleryLYR");
			if (x)
				{
				x.onreadystatechange = function()
					{
					if (x.readyState == 0)
						{
							preload.innerHTML = "initializing";
						}
					else if (x.readyState == 1)
						{
							preload.innerHTML = "processing request";
						}
					else if (x.readyState == 2)
						{
							preload.innerHTML = "request acknowledged";
						}
					else if (x.readyState == 3)
						{
							preload.innerHTML = "loading data..";
							setOpacity(0, 'galleryLYR');
						}
					else if (x.readyState == 4 && x.status == 200)
						{
							el = document.getElementById(args[2]);
							el.innerHTML = x.responseText;
							preload.innerHTML = "<img src='images/loading.gif' align='left'>";
							getImageSize = document.getElementsByTagName("img")[0].getAttribute("width");
//							document.getElementById('captionLYR').style.left = (pageWidth -	getImageSize) / 2+"px";
							document.getElementById('accessLYR').style.visibility = "hidden";
							setTimeout("fadeIn('galleryLYR', 0, '99.99')", 1200);
//							setTimeout("fadeIn('captionLYR', 0, '99.99')", 1300);
						}
					}
				x.open("GET", args[1], true);
				x.send(null);
				}
			break;

		case "cycle_gallery":
			ajaxManager('load_page', "ShowPic.php?section="+args[2]+"&id="+args[3], 'galleryLYR');
			break;
		case "hide_access":
			document.getElementById('accessLYR').style.visibility = "hidden";
			break;
		case "load_fx":
			document.getElementById('accessLYR').style.visibility = "hidden";
			break;
		case "start_up":
			ajaxManager('hide_access');
			if(args[3] != null)
				ajaxManager('load_page', "ShowPic.php?section="+args[2]+"&id="+args[3], 'galleryLYR');
			break;
	}
}

function fadeIn(id, startfade, endfade)
{
	timer = 0;
	if (startfade < endfade)
	{
		for (i = startfade; i <= endfade; i++)
		{
			setTimeout("setOpacity(" + i + ",'" + id + "')", (timer * 20));
			timer++;
		}
	}
}

function setOpacity(opacity, id)
{
	var el = document.getElementById(id).style;
	el.opacity = (opacity / 100);
	el.MozOpacity = (opacity / 100);
	el.KhtmlOpacity = (opacity / 100);
	el.filter = "alpha(opacity=" + opacity + ")";
}