var browser;
if (navigator.appName == "Microsoft Internet Explorer") {
	browser = "IE";
} else {
	browser = "Mozilla";
} // if

// change alpha value of an object
function setAlpha(elem, alpha) {
	elem.style.opacity = alpha; // CSS3 method
	if (browser == "IE")elem.filters.alpha.opacity = (alpha * 100); // IE method
} // function setAlpha()

// animated alpha fade in/out
// from www.hesido.com
function alphaFade(elem, startAlpha, endAlpha, steps, milliseconds, powr) {
	// if there is any animation happening, stop it
	if(elem.alphaFadeInt) {
		window.clearInterval(elem.alphaFadeInt);
	} // if
	var actStep = 0; // actual step of animation, += 1 every execution
	// assign an interval function with interval id to the element
	elem.alphaFadeInt = window.setInterval( function() {
		// call the ease in/ease out function
		elem.currentAlpha = easeInOut(startAlpha, endAlpha, steps, actStep, 
			powr, 1);
		//alert(elem.currentAlpha);
		elem.style.opacity = elem.currentAlpha;
		if (browser == "IE") elem.filters.alpha.opacity = elem.currentAlpha * 100;
		actStep++; // increment step number
		// if the step number actStep is bigger than steps, terminate
		if (actStep > steps) window.clearInterval(elem.alphaFadeInt);
	}, milliseconds);
} // alphaFade()

// animation ease in/ease out function
// from www.hesido.com
// totalSteps = number of frames
// actualSteps = current frame
// powr = ease in/ease out factor
// (powr > 1) ease in, (powr < 1) ease out, (powr = 1) linear
// fraction = whether function returns integer or floating point
function easeInOut(minValue, maxValue, totalSteps, actualStep, powr, fraction) {
	var delta = maxValue - minValue;
	var stepp = minValue + (Math.pow(((1 / totalSteps) * actualStep), powr)
		* delta);
	if (fraction == 0) { 
		return Math.ceil(stepp);
	} else {
		return stepp;
	}
} // easeInOut()

// animated fade in for pictures
function fadeIn(elem) {
	if (!elem.currentAlpha) elem.currentAlpha = 0;
	alphaFade(elem, elem.currentAlpha, 1, 10, 25, 1);
} // alphaChange()

// animated fade in for thumbnails
function alphaChange(elem) {
	if (!elem.currentAlpha) elem.currentAlpha = 0.4;
	alphaFade(elem, elem.currentAlpha, 1, 1, 10, 1);
} // alphaChange()

// animated fade out for thumbnails
function alphaRestore(elem) {
	if (!elem.currentAlpha) elem.currentAlpha = 1;
	alphaFade(elem, elem.currentAlpha, 0.4, 15, 25, 0.5);
} // alphaRestore()

// drop-down menu function for IE6
function menuMouseOver(elem) {
	elem.className += " over";
} // menuMouseOver()

// drop-down menu function for IE6
function menuMouseOut(elem) {
	elem.className = ("");
} // menuMouseOut() 

// show image thumbnails
function showThumbs(startRow, picType) {
	var xmlHttp = false; // the XMLHttpRequest Object
	var theUrl; // query URL
	var content = document.getElementById("imagemenu"); //content div
	// Initialize The Xmlhttprequest Object
	// if it's not there already
	if (!xmlHttp) {
		// Mozilla/Safari
		if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		// IE
		} else if (window.ActiveXObject) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		// no AJAX support
		} else {
			return;
		} //
	} // if
	theUrl = "showthumbs.php";
	xmlHttp.open('POST', theUrl, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function() {
		if((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
	  	if(content) {
	  		content.innerHTML = xmlHttp.responseText;
	  	} // if
	  	//alert(content.innerHTML);
	  } // if
	} // xmlHttp.onreadystatechange()
	xmlHttp.send("startrow=" + startRow + "&pictype=" + picType);
	//alert("startrow=" + startRow + "&pictype=" + picType);
} // showThumbs

// change the picture displaying in the image gallery
function getPicture(name, picWidth, picHeight) {
	var xmlHttp = false; // the XMLHttpRequest Object
	var theUrl; // query URL
	var content = document.getElementById("picture"); //content div
	// Initialize The Xmlhttprequest Object
	// if it's not there already
	if (!xmlHttp) {
		// Mozilla/Safari
		if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		// IE
		} else if (window.ActiveXObject) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		// no AJAX support
		} else {
			return;
		} //
	} // if
	if(content) {
	  		content.innerHTML = "<p class=\"loading\">loading...</p>\n<div id=\"picture\" style=\"width:" + picWidth +"px;height:" + picHeight + "px;\" ></div>";
	} // if
	theUrl = "getpicture.php";
	xmlHttp.open('POST', theUrl, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function() {
		if((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
	  	if(content) {
	  		content.innerHTML = xmlHttp.responseText;
	  	} // if
	  	//alert(content.innerHTML);
	  } // if
	} // xmlHttp.onreadystatechange()
	xmlHttp.send("name=" + name);
} // getPicture()
