var vIE		= navigator.userAgent.indexOf('MSIE') != -1;
var vIE6	= navigator.userAgent.indexOf('MSIE 6') != -1;


/**
 *  Javascript f�r "Link in Lupe"
 * 
 *  Es wird das onclick Ereignis des �bergeordneten Elements aufgerufen
 *
 *  Getestet mit:
 *  - FF 2.0.16
 *  - Safari 3.0.4
 *  - IE 7.0 (ietester)
 *  - IE 6.0 (ietester)
 *  - IE 8 Beta 1 (ietester)
 */
function openPreviousLink(elem) {
	elem.parentNode.getElementsByTagName('a')[0].click();
}


/**
 *  Javascript f�r "Link in Lupe"
 *  Bei Bildern in der News liegen die A-Tags der Bilder auf der
 *  gleichen DOM-Ebene wie das A-Tag mit der Lupe
 *  Daher wird der n�chste vorhergehende A-Tag gesucht und dort
 *  das onclick-Ereignis ausgel�st.
 *  
 */
function openPreviousNewsLink(elem) {
	// letzten vorhergehenden Link finden
	elem = elem.previousSibling;
	while (null != elem) {
		if (elem.nodeName.toLowerCase() == 'a') {
			// return openPic(elem,'thePicture',''+vWidth+','+vSplit[3]+',status=0,menubar=0');
			elem.onclick();
		}
		elem = elem.previousSibling;
	}
}


// Funktion, um das Suchfeld bei Eingabe zu l�schen und zu setzen
function setSearchWord(sWord, sMode) {
	fInput = document.getElementById('suchwort');
	switch(sMode) {
		case 0:
			if (fInput.value == sWord) fInput.value = '';
		break;
		case 1:
			if (fInput.value == '') fInput.value = sWord;
		break;
	}
}


/**
 * setCookie:
 * name: Name des Cookies
 * value: Wert
 * expires: 0 = mit der Sitzung; ansonsten in Tagen
 */
/*function setCookie(name,value,expires) {
	var expire = new Date();
	expire.setTime(expire.getTime() + (expires * 24*60*60));
	document.cookie = name+"="+value+"; expires="+expire.toGMTString();
}

*/
/**
 * getCookie:
 * Gibt den Wert eines bestimmten Cookies zur�ck
 *
 */
//function getCookie(name) {
// check for cookie to set font-size
/*	
	var cookie = unescape(document.cookie);
	var entrys = cookie.split(';');
	var entry;
	for (var i = 0; i < entrys.length; i++) {
		entry = entrys[i].split('=');
		if (trim(entry[0]) == name) {
			return trim(entry[1]);
		}
	}
	return ''; // not found
}

function trim(value) {
	while (value != '' && value.substr(0,1) == ' ') {
		value = value.substr(1);
	}
	while (value != '' && value.substr(value.length-1)  == ' ') {
		value = value.substr(0, value.length-1);
	}
	return value;
}
*/

/**
 *  Cookie management
 */
function getCookie(cookieName) {
	strValue = false;
	if (strCookie = document.cookie) {
		if (arrCookie = strCookie.match(new RegExp(cookieName + '=([^;]*)', 'g'))) {
			strValue = RegExp.$1;
		}
	}
	return strValue;
}


function setCookie(cookieName, cookieValue, intDays) {
	if (!cookieEnabled()) return false;
	
	var expires	= new Date();
	var date	= expires.getTime() + (intDays * 24 * 60 * 60 * 1000);
	expires.setTime(date);
	document.cookie = cookieName + '=' + cookieValue + ';expires='+expires.toGMTString()+';path=/';
	return true;
}


function delCookie(cookieName) {
	if (document.cookie) {
		document.cookie = cookieName + '=' + getCookie(cookieName) + ';expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/'; 
		return true;
	}
	return false;
}


function cookieEnabled() {
	if (typeof navigator.cookieEnabled!=undefined) return navigator.cookieEnabled;
	
	setCookie('test_cookie', 'foo', 1);
	if (!document.cookie) return false;
	
	delCookie('test_cookie');
	return true;        
}


/**
 *  curFontSizer
 */
var fontSize	= 3, 
	cookieName	= 'fontSizer';

function switchFontSize(val) {
	var bd = jQuery(document.getElementsByTagName('body')[0]),
		curFontSize = parseInt(fontSize);
	switch (val) {
		case 'inc':
			if (fontSize+1 < 7) {
				bd.removeClass('fs'+curFontSize);
				curFontSize++;
				bd.addClass('fs'+curFontSize);
			}
		break;
		case 'dec':
			if (curFontSize-1 > 0) {
				bd.removeClass('fs'+curFontSize);
				curFontSize--;
				bd.addClass('fs'+curFontSize);
			}
		break;
		default:
			bd.removeClass('fs'+curFontSize);
			curFontSize = val;
			bd.addClass('fs'+curFontSize);
	}
	setCookie(cookieName, curFontSize, 365);
	fontSize = curFontSize;	
}


jQuery(window).bind('load', function() { 
	var newFontSize = getCookie(cookieName) || 3;
	if (newFontSize!='' && newFontSize > 0) switchFontSize(newFontSize);
});
