/**
 * @author simonius
 */

var params = new Object();
$(document).ready(function(){

	/**
	 * document.location.params will store all document parameters 
	 * found in location after '?'. E.g. 'index.html?foo=bar&lorem=ipsum' 
	 * becomes an object { 'foo':'bar', 'lorem':'ipsum'}
	 */
	jQuery.extend(document.location, {'params':{}});
	var _params = document.location.search;
	if( _params ){
		// get stuff after '?'
		_params = _params.match(/\?(.*)/);
		if( undefined != _params[1] ){
			// split parameter sets
			_params = _params[1].split('&');
			for( i=0; i<_params.length; i++ ){
				// split key from value
				var tmp = _params[i].split('=');
				document.location.params[ tmp[0] ] = tmp[1];
			}
		}
	}
	
	/**
	 * Homepage mainmenu flyouts
	 */
	 
	$("li.produkte").hover(
		function(){ $("div", this).show(10); }, 
		function(){ $("div", this).hide(10); } 
	);
	if (document.all) {
		$("li.produkte").hoverClass ("navhover");
	}
	
	$("li.rezepte").hover(
		function(){ $("div", this).show(10); }, 
		function(){ $("div", this).hide(10); } 
	);
	if (document.all) {
		$("li.rezepte").hoverClass ("navhover");
	}
	
	$("li.geniessen").hover(
		function(){ $("div", this).show(10); }, 
		function(){ $("div", this).hide(10); } 
	);
	if (document.all) {
		$("li.geniessen").hoverClass ("navhover");
	}
	
	$("li.beratung").hover(
		function(){ $("div", this).show(10); }, 
		function(){ $("div", this).hide(10); } 
	);
	if (document.all) {
		$("li.beratung").hoverClass ("navhover");
	}


});


/**
 * navigation mouseover
 */
$.fn.hoverClass = function(c) {
	return this.each(function(){
        $(this).hover( 
                function() { $(this).addClass(c);	},
                function() { $(this).removeClass(c); }
        );
	});
};


/**
 * font sizing scripts
 */ 

function fontsizeup() {
	active = getActiveStyleSheet();
	switch (active) {
		case 'A+' : 
			setActiveStyleSheet('A++');
			break;
		case 'A++' : 
			setActiveStyleSheet('A++');
			break;
		default :
			setActiveStyleSheet('A+');
			break;
	}
	return false;
}

function fontsizedown() {
	active = getActiveStyleSheet();
	switch (active) {
		case 'A++' : 
			setActiveStyleSheet('A+');
			break;
		case 'A+' : 
			setActiveStyleSheet('A');
			break;
		default :
			setActiveStyleSheet('A');
			break;
	}
	return false;
}

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	createCookie("style", title, 365);
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	return ('A');
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


/**
 * Initializing stylesheets, image rotator and ticker 
 */
$(document).ready(function(e){
	var cookie = readCookie("style");
	var title = (cookie != null) ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
});
