var nerv = null;
var wordings = new Array();
var curWord = 1000;
var running = false;
var load = true;
var not_whitespace = new RegExp(/[^\s]/);//This can be given inside the funciton - I made it a global variable to make the scipt a little bit faster.
var parent_count;
var curHamburger = 0;
var myWindow = null;
var lastDeckel = -1;

function parteiprogramm(typ) {

	if (typ == "MWMUFFK") if (confirm("Sind Sie auch ein Maulwurf ?")) {
		downLoad('download.php?title=Pimmelspiel&download=download/pimmelspiel.jpg');
		return false;
		}
	if (typ == "MWFMK") if (confirm("Sind Sie auch ein Maulwurf ?")) {
		downLoad('download.php?title=König%20Ludwig&download=download/konig-ludwig.jpg');
		return false;
		}
	if (typ == "MWFFK") if (confirm("Sind Sie auch ein Maulwurf ?")) {
		downLoad('download.php?title=Parteiprogramm&download=download/parteiprogramm.pdf');
		return false;
		}
		

}

function dachverband() {
	
	openMaulwurf('http://jakob-friedl.de/?feed=rss2', 'rss feed', screen.availWidth,screen.availHeight);	
	return false;
}

function maximizeWindow() {

	self.moveTo(0,0);
	self.resizeTo(screen.availWidth,screen.availHeight);

}

function geheimkot(download,title,message) {
if ($('#jakob p:first').text().indexOf("Audroel") >= 0) {
			if ($('#maulwurf p:first').text().indexOf("Rumpelstielzchen") >= 0 ) {
				if ($('#friedl p:first').text().indexOf("Maulwurf") >= 0 ) {	
					if (confirm("Sind Sie auch ein Maulwurf ?")) downLoad('download.php?title='+title+'&download=download/'+download+'&message='+message);
				}
			}
		}
	
return false;
}

function downLoad(url) {

    openMaulwurf(url, 'Download', 400, 300);
	
	return false;
	
}
function openPopup(theURL,winName) { //v2.0	var loc = document.title + "";
 if (loc.indexOf("Europabrunnendeckel") >= 0) openMaulwurf(theURL, winName, 1200, 600); else openMaulwurf(theURL, winName, 620, 500);
 
 return false;
 
}

function openMaulwurf(theURL, winName, width, height) {

	width = Math.min(screen.availWidth, width) -10;
	height = Math.min(screen.availHeight, height) - 10;

	width = Math.max(570, width) -10;
	height = Math.max(400, height) - 10;
	
	if (navigator.appName == "Microsoft Internet Explorer") {
		myWindow = window.open("about:blank", null, "height=1,width=1,status=no,resizable=yes,scrollbars=yes,menubar=no");
		winName = winName.replace(" ","_");
		}

    var left = Math.max(parseInt((screen.availWidth/2) - (width/2)),0);
    var top = Math.max(parseInt((screen.availHeight/2) - (height/2)),0);
    var windowFeatures = "width=" + width + ",height=" + height + ",status=no,resizable=yes,scrollbars=yes, menubar=no,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    	
	if (myWindow == null || myWindow.closed) {
		myWindow = window.open(theURL,winName, windowFeatures);
		}
	else {
	
	if (navigator.userAgent.indexOf('Chrome/') > 0) {
			myWindow.close();
			myWindow = null;
			myWindow = window.open(theURL,winName, windowFeatures);
		}
		else {
			myWindow.location.href = theURL;
			myWindow.moveTo(left,top);
			myWindow.resizeTo(width,height);
			myWindow.focus();
			}
			
		}

	return false;

}

function eraseField(id) {
	$('#'+id).text("");
}

$(window).unload( function () { try { myWindow.close(); myWindow = null; } catch (e) {/*No window.*/} } );

$(document).ready(function() {

	$('.popUp').click( function() {
		if (document.title.indexOf("Europabrunnendeckel") >= 0) openMaulwurf($(this).attr('href'), $(this).attr('title'), 1200, 600 );
		else openMaulwurf($(this).attr('href'), $(this).attr('title'), 500, 500 );
		return false;
	});
	$('.burgerPopup').click( function() {
		var w = 1200;
		var h = 600;
		 
		try {
			var theImage = new Image();
			theImage.src = $($(this).children('img')[0]).attr("src");
			w = theImage.width + 60;
			h = theImage.height;
		} catch (e) { }
		if (w < 620) w = 620;
		if (h < 500) h = 500;
		openMaulwurf($(this).attr('href'), $(this).attr('title'), w, h );
		return false;
	});
	makeCookie('maulwurfCookie');

	$('#nav').children('li').children('ul').children('li').click( function() {

	$(this).parent().parent().children('p').text($(this).text());
	
		if ($('#jakob p:first').text().indexOf("Audroel") >= 0) {
			if ($('#maulwurf p:first').text().indexOf("Rumpelstielzchen") >= 0 ) {
				if ($('#friedl p:first').text().indexOf("Maulwurf") >= 0 ) {	
					if (confirm("Sind Sie auch ein Maulwurf ?")) downLoad('download.php?title=Lebenslauf&download=download/lebenslauf.pdf');
				}
			}
		}
	
	var a = new Date();
	a = new Date(a.getTime() +1000*60*60*24*365);
	/*
	document.cookie = id+'='+name+'; expires='+a.toGMTString()+';'; 
	*/
	//if (document.getElementById(id).firstChild.value == ('Dulldrael')) alert ("Zapp!");
	var value = ';jakob=';
	if ($('#jakob p:first').text() != null) 
	value += $('#jakob p:first').text()+';';
	else value+= 'Jakob;';
	value+= 'maulwurf=';
	if ($('#maulwurf p:first').text() != null) 
	value += $('#maulwurf p').text()+';';
	else value+= 'Maulwurf;';
	value += 'statt=';
	if ($('#statt p:first').text() != null) 
	value += $('#statt p:first').text()+';';
	else value+= '-;';
	value+='friedl=';
	if ($('#friedl p:first').text() != null) 
	value += $('#friedl p:first').text()+';';
	else value+= 'Friedl;';
	//alert(value);
	setCookie('maulwurfCookie', value, a, null, null, null);

	return false;
	
	}
	);


});
// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.geocities.com/~yehuda/

// Boolean variable specified if alert should be displayed if cookie exceeds 4KB
var caution = false

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if (!caution || (name + "=" + escape(value)).length <= 4000) {
document.cookie = curCookie
}
else
if (confirm("Cookie is too big! Exceeds 4KB and will be cut! Njaam"))
document.cookie = curCookie
}
function makeCookie(name) {
try {
	var cook = getCookie(name);
	if (cook != null) {
	var werte = cook.split(';');

	var i = 0;
	while (i < werte.length) {

	var str = werte[i].split('=');
		if (str[0].search('jakob') != -1) $('#jakob p:first').text(str[1]);
		if (str[0].search('maulwurf')!= -1) $('#maulwurf p:first').text(str[1]);
		if (str[0].search('statt')!= -1) $('#statt p:first').text(str[1]);
		if (str[0].search('friedl')!= -1) $('#friedl p:first').text(str[1]);
	//alert(str[0]+' '+i+' '+str[1]);
		i++;
	}
	}
	} catch (e) {}
}
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (document.cookie.length < 1) {
return null
}
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie)
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT"
}
}
