
/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	Load gallery
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

	var ajaxContent;
	var nFlaWidth = 990;
	var nFlaHeight = 585;
	var gImage_id = 0;
	var gGallery_id = 0;
	var gGallery_type = 0;
	var gPic_title = "";
	var gVoted = 0;

	function fnShowFlash(sXML, nStart, sVote) {

		var oTargetDiv = document.getElementById("flashGallery");

		oTargetDiv.innerHTML = '<p class="noFlash">This feature requires a new version of the Flash player. <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW" target="_blank"><strong>Click here to download the player from Adobe.</strong>.</a></p>';

		oTargetDiv.style.top = 0+"px";
		oTargetDiv.style.left = 0+"px";


		// build flash object
		var so = new SWFObject("/flash/gallery.swf", "gallery", nFlaWidth, nFlaHeight, "9");
		so.addParam("menu", "false");
		so.addParam("wmode", "transparent");
		so.addVariable("sXMLFile",sXML);
		so.addVariable("sShowVote",sVote); // no hides / yes shows

		so.addVariable("sStartDBID",nStart);
		so.write(oTargetDiv);


		showLayer('flashGalleryHolder');


		return false;

	}



	function ajaxInc(page) {

		var moo = new Request.HTML({
			'url': page,
			'onComplete': function(responseTree, responseElements, responseHTML, responseJavaScript) {
				$('flashGallery').set('html', responseHTML);
			}
		}).send();

	}



	function doVote(image_id, gallery_id, gallery_type, pic_title) {

		document.getElementById('flashGallery').innerHTML = "";

		gImage_id = image_id;
		gGallery_id = gallery_id;
		gGallery_type = gallery_type;
		gPic_title = pic_title;

		if (showingLoggedIn == false)
		{
			ajaxInc("/loginForm.php");
		}
		else
		{
			ajaxInc("/confirmForm.php");
		}

		showLayer('flashGalleryHolder');
	}


	function confirmVote(id) {
		ajaxInc("/thanksForm.php?gid=" + gGallery_id + "&gi_id=" + gImage_id + "&gt=" + gGallery_type);
		removeVotes();

		setTimeout("reloadFla()", 3000);
	}


	function regForm() {
		var moo = new Request.HTML({
			'url':'/regPost.php',
			'method':'post',
			'onComplete': function(responseTree, responseElements, responseHTML, responseJavaScript) {
				$('flashGallery').set('html', responseHTML);
			}
		}).send($('frmReg').toQueryString());

	}


	function activateForm() {

		var moo = new Request.HTML({
			'url':'/activatePost.php',
			'method':'post',
			'data' : {
				'key': $('activate').get('value')
			},
			'onComplete': function(responseTree, responseElements, responseHTML, responseJavaScript) {
				$('flashGallery').set('html', responseHTML);
			}
		}).send();
	}

	function reloadFla() {
		var galType = "";
		if (gGallery_type == 1)
		{
			galType = "asia";
		}
		else if (gGallery_type == 2)
		{
			galType = "europe";
		}

		var xmlFile = "/xml-generator-gallery.php?t=" + galType + "|gid=" + gGallery_id
		fnShowFlash(xmlFile, gImage_id);
	}


	function passForm() {
		var moo = new Request.HTML({
			'url':'/passRemind.php',
			'method':'post',
			'data' : {
				'email': $('email_address').get('value')
			},
			'onComplete': function(responseTree, responseElements, responseHTML, responseJavaScript) {
				$('flashGallery').set('html', responseHTML);
			}
		}).send();
	}


	function removeVotes() {
		var votebuts = document.getElementsByTagName("p");

		// Traverse all the images..
		for (var i=0; i<votebuts.length; i++)
		{
			if (votebuts[i].id.substr(0, 5) == "voteB")
			{
				document.getElementById(votebuts[i].id).innerHTML = "";
			}
		}

	}





/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	Overlay
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/


var layerShowing = null;
var resizingTimer;



function scrollLayer(type) {
	if( typeof( window.innerWidth ) == 'number' ) {
   		//Non-IE
		myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
		htmHeight = document.documentElement.scrollHeight;
		htmWidth = document.documentElement.scrollWidth;
		fadeBox = true;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
   		//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
    	myHeight = document.documentElement.clientHeight;
		htmHeight = document.documentElement.scrollHeight;
		htmWidth = document.documentElement.scrollWidth;
		fadeBox = false;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
    	myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
		htmHeight = document.body.offsetHeight;
		htmWidth = document.body.offsetWidth;
		fadeBox = false;
	}
	if (window.innerHeight) {
		topScroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		topScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		topScroll = document.body.scrollTop;
	}




	x = parseInt((winW/2) - (nFlaWidth/2));
	y = parseInt((myHeight/2) - (nFlaHeight/2)+topScroll);

	document.getElementById(type).style.top = y+"px";
	document.getElementById(type).style.left = x+"px";
	document.getElementById(type).style.display = "block";


	return false;


}

function selectState(type) {
	var selEls = document.getElementsByTagName('select');

	for(var i=0; i<selEls.length;i++) {
		selEls[i].style.visibility = type;
	}

}

function showLayer(type) {

	selectState('hidden');


	document.getElementById('flashBG').style.width = nFlaWidth +"px"

	if( typeof( window.innerWidth ) == 'number' )
	{
   		//Non-IE
		myWidth = window.innerWidth;
    		myHeight = window.innerHeight;
		htmHeight = document.documentElement.scrollHeight;
		htmWidth = document.documentElement.scrollWidth;
		fadeBox = true;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
   		//IE 6+ in 'standards compliant mode'
    		myWidth = document.documentElement.clientWidth;
    		myHeight = document.documentElement.clientHeight;
		htmHeight = document.documentElement.scrollHeight;
		htmWidth = document.documentElement.scrollWidth;
		fadeBox = false;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		htmHeight = document.body.offsetHeight;
		htmWidth = document.body.offsetWidth;
		fadeBox = false;
	}

	if (window.innerHeight)
	{
		topScroll = window.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		topScroll = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		topScroll = document.body.scrollTop;
	}




	winW = myWidth;
	if(htmHeight > myHeight)
	{
		winH = htmHeight;
	}
	else
	{
		winH = myHeight;
	}


	if(myWidth>nFlaWidth)
	{
		winW2 = htmWidth;
		//use htmWidth here, because non-ie browsers count the scroll bar in the win width
	}
	else
	{
		winW2 = nFlaWidth;
	}

	document.getElementById('flashBG').style.height = winH+"px";
	document.getElementById('flashBG').style.width = winW2+"px";



	x = parseInt((winW/2) - (nFlaWidth/2));
	y = parseInt((myHeight/2) - (nFlaHeight/2)+topScroll) + 25;	 // the +25 is to padd the top..


	if (x == 8 || x == 9)
	{
		x = 0;
	}


	if (x < 0)
	{
		x = 0;
	}

	if (y < 0)
	{
		y = 0;
	}

	//alert(x);

	document.getElementById(type).style.top = y+"px";
	document.getElementById(type).style.left = x+"px";


	document.getElementById('flashBG').style.display = "block";
	document.getElementById(type).style.display = "block";
//	document.getElementById("flashGallery").style.zIndex = nFlaWidth;

	//fade in
	if(layerShowing == null) {
	setOpacity(90, 'flashBG');
	/*
		if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
			//saveSelectStates();
		}
		setOpacity(10, 'flashBG');
		if(fadeBox == true) {
			setOpacity(20, type);
			setTimeout("setOpacity(40, 'flashBG'); setOpacity(40, '" + type + "');", 40);
			setTimeout("setOpacity(60, 'flashBG'); setOpacity(50, '" + type + "');", 80);
			setTimeout("setOpacity(80, 'flashBG'); setOpacity(70, '" + type + "');", 120);
			setTimeout("setOpacity(70, 'flashBG'); setOpacity(90, '" + type + "');", 160);
			setTimeout("setOpacity(90, 'flashBG'); setOpacity(100, '" + type + "');", 200);
		} else {
			setTimeout("setOpacity(40, 'flashBG')", 40);
			setTimeout("setOpacity(50, 'flashBG')", 80);
			setTimeout("setOpacity(60, 'flashBG')", 120);
			setTimeout("setOpacity(70, 'flashBG')", 160);
			setTimeout("setOpacity(90, 'flashBG')", 200);
		}
	*/
	}

	layerShowing = type;
	return false;
}



function hideLayer(type) {


	//fade out, then close
	/*
	setOpacity(50, 'flashBG');
	if(fadeBox == true) {
		setTimeout("setOpacity(40, 'flashBG'); setOpacity(90, '" + type + "');", 40);
		setTimeout("setOpacity(30, 'flashBG'); setOpacity(60, '" + type + "');", 80);
		setTimeout("setOpacity(20, 'flashBG'); setOpacity(40, '" + type + "');", 120);
		setTimeout("setOpacity(10, 'flashBG'); setOpacity(20, '" + type + "');", 160);
	} else {
		setTimeout("setOpacity(40, 'flashBG')", 40);
		setTimeout("setOpacity(30, 'flashBG')", 80);
		setTimeout("setOpacity(20, 'flashBG')", 120);
		setTimeout("setOpacity(10, 'flashBG')", 160);
	}
	setTimeout("closeLayer('"+type+"')", 200);
	*/
	closeLayer(type);

	selectState('visible');

	return false;

}

function closeLayer(type) {
	if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
		//applySelectStates();
	}
	document.getElementById('flashGalleryHolder').style.display = "none";
	document.getElementById('flashBG').style.display = "none";
	layerShowing = null;
}



function setOpacity(opacity, id) {
	if (detectMacXFF() == true)
	{

	}
	else
	{
		var object = document.getElementById(id).style;
		object.MozOpacity = (opacity / 100);
		object.opacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}
}


function detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}



function fnGetVisibleHeight() {

	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;
	}

}




window.onscroll = function () {
	if(layerShowing != null) {

	var myHeight = fnGetVisibleHeight();
	//alert(myHeight);



		if (myHeight > 600)
		{
			//alert(htmHeight);
			scrollLayer(layerShowing);

		}
		else
		{
			// pad the top slightly.. (5 px?)
			//document.getElementById(layerShowing).style.top = "15px";
		}
	}
}

window.onresize = function () {
	if(layerShowing != null) {
  		clearTimeout(resizingTimer);
  		setTimeout(window.onresizeend, 50);
	}
}


window.onresizeend = function() {
	if(layerShowing != null) {
  		showLayer(layerShowing);
  	}
}