// all JavaScripts for AG

// spam prevent
var myEmail = "info@academie-galan.de";
var adminEmail = "ag@silvan-thiele.de";

// check for Browser
var IE=0, MOZ=0, NS4=0, OP=0;
if(window.opera) OP=1;
if(document.all && !OP) IE=1;
if(document.getElementById && !IE) MOZ=1;
if(document.layers && !OP) NS4=1;

// removes the rectangle around links for IE+Win, only onClick-event, TAB function remains
function ExplorerFix() {
	for (a in document.links) document.links[a].onclick = document.links[a].blur; 
}
// if(IE) document.onmousedown = ExplorerFix; // only for IE


// mainnavi for IE
aHover = function() {
	var aEl = document.getElementById("mnav").getElementsByTagName("LI");
	for (var i=0; i<aEl.length; i++) {
		if(aEl[i].className.search(new RegExp("open\\b")) == -1) {
			aEl[i].className += " init";
			aEl[i].onmouseover=function() {this.className += " over";}
			aEl[i].onmouseout=function() {this.className = this.className.replace(new RegExp(" over\\b"), "");}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", aHover);


// changes photo images
var photoindex = 0;
var photopath = 'photo/';
var photolist = new Array('a_photo01','a_photo02','ax_photo01','a_photo03','ax_photo03','a_photo04','ax_photo02','a_photo05','ax_photo04','ax_photo05','a_photo07','a_photo06','ax_photo06','t_mitglied','a_photo08','a_photo09','a_photo10','az_photo01','az_photo02','az_photo03','az_photo04','az_photo05','az_photo06','az_photo07','az_photo08','az_photo09','az_photo10','az_photo11','c_001','c_002','c_003','c_004','c_005','c_006','c_007','c_008','c_009','c_010','c_011','c_012','c_013','c_014','c_015','c_016','c_017','c_018','c_019','c_020','c_021','c_022','c_023','c_024','c_025','c_026','c_027','c_028','c_029','c_030','c_031','c_032','c_033','c_034','c_035','c_036','c_037','c_038','c_039','c_040','c_041','c_042','c_043','c_044','c_045','c_046','c_047','c_048','c_049','c_050','c_051','c_052','c_053','c_054','c_055','c_056','c_057','c_058','c_059','c_060','c_061','c_062','c_063','c_064','c_065','c_066','c_067','c_068','c_069','c_070','c_071','c_072','c_073','c_074','c_075','c_076','c_077','c_078','c_079','c_080','c_081','c_082','c_083','c_084','c_085','c_086','c_087','c_088','c_089','c_090','c_091','c_092','c_093','c_094','c_095');

var imgObj = new Array(photolist.length);
for (var counter = 0; counter < photolist.length; counter++) {
		imgObj[counter] = new Image();
	}
var timercounter = 0;
var imgloaded = true;

function changeImg(direction) {
	timercounter = 0; // reset
	if (!imgloaded) return; // exit if previous image was not loaded
	imgloaded = false;
	document.getElementById('loadstatus').firstChild.nodeValue = 'Loading ' + parseInt(photoindex+1) + ' / ' + parseInt(photolist.length);
	document.getElementById('loadstatus').style.visibility = "visible"; // loading visible
	
	if (direction == 'f') photoindex = (photoindex < photolist.length-1) ? (photoindex+1) : 0;
	else if (direction == 'b') photoindex = (photoindex == 0) ? (photolist.length-1) : (photoindex-1);
	else return;
	
	document.getElementById('photo').src = photopath + '' + photolist[photoindex] + '.jpg'; // get the next image
	imgObj[photoindex].src = document.getElementById('photo').src;
	resetFooter(); // run the timer
}

function resetFooter() {
	if(imgObj[photoindex].complete) { // already loaded ?
		imgloaded = true;
		if(!IE) { // needed for all except IE
			window.resizeBy(0,1);
			setTimeout("window.resizeBy(0,-1)",100); // resize to reposition the footer
		}
		document.getElementById('loadstatus').style.visibility = "hidden"; // loading invisible
	}
	else {
		document.getElementById('loadstatus').firstChild.nodeValue += ' .';
		timercounter += 1;
		if (timercounter >= 160) {
			document.getElementById('loadstatus').firstChild.nodeValue = 'Bild kann nicht gefunden werden, einfach naechstes auswaehlen.';
			imgloaded = true;
			return;
		}
		else setTimeout("resetFooter()", 100); // check once more
	}
}

// input fields bgColor
var myInputColor = "#ffffff";
var myInputBorder = "#000000";

function inputSwap(obj,swapdir) {
	if (swapdir==true) {
		myInputColor = obj.style.backgroundColor;
		myInputBorder = obj.style.borderColor;
		obj.style.backgroundColor = "#fae2b8";
		obj.style.borderColor = "#000000";
	}
	else if (swapdir==false) {
		obj.style.backgroundColor = myInputColor;
		obj.style.borderColor = myInputBorder;
	}
	else return;
}