
/*---- 
	Use this function to assign other functions to body.onload 
----*/
function addLoadEvent(func) {
    	var oldonload = window.onload;
    	if (typeof window.onload != 'function') {
    	    	window.onload = func;
  	} else {
    	    	window.onload = function() {
      	    	oldonload();
      	    	func();
    		}
    	}
}



/*---- 
	This function enables the menu with the id of ul_nav
	to show the submenu. Works only on 2 levels.
----*/
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("ul_nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
  				}
	  			node.onmouseout=function() {
  					this.className=this.className.replace(" over", "");
   				}
   			}
  		}
 	}
}

addLoadEvent(startList);


$(document).ready(function () {

//----
// Accesskeys
//----

$('#accesskeys a').each(function(i){
	$(this).focus(function(){
		$('#accesskeys').attr("style","left: 10px; z-index: 999;");
	});
	$(this).blur(function(){
		$('#accesskeys').attr("style","left: -9999px;");
	});
});


// Submit on change

$('.submitonchange').change(function() {
	if($(this).val()=='-1') {
		return false;
	} else {
		this.form.submit();
	}
});


// Switch stylesheets

var c = readCookie('style');

if (c) {
	
	switchStylestyle(c);
	 
	if (c == "font_big") {
        	$('.styleswitch').each(function(i) {
		$(this).attr({
			rel: "font_normal"
        	});
        });
        } else if(c == "font_normal"){
		$('.styleswitch').each(function(i) {
		$(this).attr({
			rel: "font_big"
        	});
        });
	} else {
		$('.styleswitch').each(function(i) {
		$(this).attr({
			rel: "font_normal"
        	});
        });
	}
}
	
$('.styleswitch').click(function() {

	var relatt = this.getAttribute("rel");
        switchStylestyle(relatt);
        if (relatt == "font_big") {
        	$(this).attr({ 
			rel: "font_normal"
        	});
        } else if(relatt == "font_normal"){
		$(this).attr({ 
			rel: "font_big"
        	});
	} else {
		$(this).attr({ 
			rel: "font_normal"
        	});
	}
	
        return false;
});	
	
	
}); // onready ends


/*function switchStylestyle(styleName){
//alert(styleName);
        $("body").each(function(i){
                $(this).attr({
                	class: "alternate stylesheet"
                });
        });
        
        $("link[href*="+styleName+"]").each(function(i){
                $(this).attr({
                	rel: "stylesheet"
                });
        });
        
        createCookie('style', styleName, 365);
}*/

function switchStylestyle(styleName)
{
        $('link[@rel*=style][@title]').each(function(i)
        {
                this.disabled = true;
                if (this.getAttribute('title') == styleName) this.disabled = false;
        });
        createCookie('style', styleName, 365);
}

// cookie functions http://www.quirksmode.org/js/cookies.html

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 var 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;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}

// cookie functions end
