var isIE = false;
var _LoginBox;

//////////////////////////

function $(e)
{
	var element = document.getElementById(e);
	return element;
}

function getStyle(el,styleProp)
{
	var x = $(el);
	
	if (x.currentStyle)	
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	
	return y;
}

function CutPx(Value){
	var tmp = Value;
	tmp = tmp.substring(0,tmp.length-2);
	tmp = parseInt(tmp);
	return tmp;
}


function toggle_scroll(value)
{
	switch (value) 
	{
		case "on": document.body.style.overflow = "auto"; break;
		case "off": document.body.style.overflow = "hidden"; break;
		case null:
			if (isIE) 
			{ 
				document.body.style.overflow = "auto"; //IE sucks
				break; 
			} else 
			{
				if (CutPx(getStyle("content", "height")) > document.height)
				{
					document.body.style.overflow = "auto";	
				} else {
					document.body.style.overflow = "hidden";	
				}
			}
		break;
	}	
}

function detectBrowser()
{
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	var version = parseFloat(b_version);

	if (browser == "Microsoft Internet Explorer") isIE = true;
}

function galleryHash()
{
		var gHash = window.location.hash;
		var gID;
		
		if (gHash) 
		{
			gID = gHash.substr(1, gHash.length-1); //cut #
			gID--;
			
			full_view(gID);
		}	
}

function init()
{
	detectBrowser();
	
	if (!isIE) {
		toggle_scroll(null);
	} else {
		toggle_scroll("on");	
	}
	
	galleryHash();
	_LoginBox = $("aLoginBox");
}

function formSubmit(e)
{
	var charCode
	
	if (e && e.which) { //if which property of event object is supported (NN4)
		e = e;
		charCode = e.which; //character code is contained in NN4's which property
	}
	else {
		e = event;
		charCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if(charCode == 13) { //return key
		return true;
	} else {
		return false;
	}
}

function toggleLoginBox(value)
{	
	if ($("aPW")) {
		$("aPW").value = "";
	}

	switch (value) {	
		case 0: 
			_LoginBox.style.display = "none";
		break;
		
		case 1: 
			_LoginBox.style.display = "block";
			if ($("aPW")) {
				$("aPW").focus();
			}
		break;
		
		case 2: 
			(getStyle("aLoginBox", "display") == "none") ? toggleLoginBox(1) : toggleLoginBox(0); 
		break;
	}
}

function adminLoginResponse(text)
{	
	switch (text) { 
		case "1":
			document.location = "admin.php";
		break;
		
		case "2":
			document.location = "index.php";
		break;
		
		case "3":
			alert("Authentifizierung fehlgeschlagen.");
		break;
	}
}


function adminLogin(value)
{
	var aLoginQ = new Ajax("admin/login.php", adminLoginResponse);
	
	switch (value) {
		case 0:
			aLoginQ.query("logout=true");
		break;
		case 1:
			aLoginQ.query("pw=" + $("aPW").value);
		break;
	}
}
