/* 
    Page-specific JavaScript
    Dependent on jquery.js
    Copyright (c) 2010, Matthias Genzmehr. All rights reserved.
*/

var numOfImages = 47;
var imagePath = "pics/reisen/";
var imageCount = 0;
var myImages = new Array (numOfImages);

for (i = 0; i < 2; i++) {
    myImages[i] = new Image();
	myImages[i].src = "pics/reisen/" + (i+1).toString() + ".jpg";
}

function changePics () {
    document.getElementById('israelBilder').src = myImages[imageCount].src;
    (imageCount >= (numOfImages - 1)) ? imageCount = 0 : imageCount++;
    setTimeout("changePics()", 3000); // change Picture every 3 seconds
}

function showPicture(number) {
	if (isNaN(number)) return;
	var file = "kinder.xml?nr=" + number.toString();
	var windowName = "KinderMalenIsrael";
	myWindow = window.open (file, windowName, "width=640,height=800,toolbar=0,titlebar=0,scrollbars=0,resizable=1");
	myWindow.focus();
}

function showScheduleEntry (entryID) {
    if (isNaN(entryID)) return;
    var file = "termin.php?id=" + entryID.toString ();
    var windowName = "Termin";
	myWindow = window.open (file, windowName, "width=640,height=440,toolbar=0,titlebar=0,scrollbars=0,resizable=1");
	myWindow.focus();
}

function showSchedule(month, year) {
    if (month < 0 || month > 12) {
        return;
    }

    document.zeitraum.monat.value = month;
	document.zeitraum.jahr.value = year;
	
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
	
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("termine").innerHTML = xmlhttp.responseText;
        }
    }
	
    xmlhttp.open("GET", "getschedule.php?month=" + month.toString() + "&year=" + year.toString(), true);
    xmlhttp.send();
}

function decryptCharcode (n, start, end, offset) {
    n = n + offset;
	
	if (offset > 0 && n > end) {
	    n = start + (n-end-2);
	}
	else if (offset < 0 && n < start) {
	    n = end - (start-n-2);
	}
		
    return String.fromCharCode(n);
}

function decryptString (string, offset) {
    var dec = "";
	var len = string.length;
	
	for(var i = 0; i < len; i++) {
	    var n = string.charCodeAt(i);
		if (n >= 0x2B && n <= 0x3A) {
		    dec += decryptCharcode(n, 0x2B, 0x3A, offset);
		}
		else if (n >= 0x40 && n <= 0x5A) {
		    dec += decryptCharcode(n, 0x40, 0x5A, offset);
		}
		else if (n >= 0x61 && n <= 0x7A) {
		    dec += decryptCharcode(n, 0x61, 0x7A, offset);
		}
		else {
		    dec += string.charAt(i);
		}
	}

	return dec;
}

function uncryptMailTo(s) {
    location.href = decryptString(s,-4);
}

$(document).ready(function () {
    $(".menu").mouseover(function () {
	    $(this.getElementsByTagName("ul")[0]).css("visibility","visible");
	});
	
	$(".menu").mouseout(function () {
	    $(this.getElementsByTagName("ul")[0]).css("visibility","hidden");
	});
	
    var links = $("a.popup");
    links.click(function(event){
        event.preventDefault();
        window.open($(this).attr('href'),'FacebookSharer',"width=520,height=400,resizable=1");
    });
    
	changePics ();
});

