
//jQuery onReady

$(document).ready(function(){


/*---- 
	This function enables the menu with the id of ul_nav
	to show the submenu.
----*/

$('#ul_nav li').each(function(){
	$(this).hover(function(){
		$(this).addClass("over");
	}, function(){
		$(this).removeClass("over");
	});
});



//----
// Search
//----
/*
$('#sword').after('<img src="fileadmin/images/search_right.gif" alt="" id="searchright" />');
*/

/*----
All text inputs with a value get their value emptied on focus
----*/

	$("input:text").each(function(){
		var ov = $(this).val();

		$(this).focus(function(){
			var fv = $(this).val();
			if (fv == ov) {
				$(this).val('');
			}
		});

		$(this).blur(function(){
			var bv = $(this).val();
			if (bv.length < 1) {
				$(this).val(ov);
			}
		});
	});
	
	$("textarea").each(function(){
		var ov = $(this).val();
		$(this).focus(function(){
			var fv = $(this).val();
			if (fv == ov) {
				$(this).val('');
			}
		});

		$(this).blur(function(){
			var bv = $(this).val();
			if (bv.length < 1) {
				$(this).val(ov);
			}
		});
	});



//----
// Nyhedsopsætning
//----

$('.news_latest_item .readmore').each(function(){
	var brotha = $(this).siblings('p.bodytext');
	$(this).remove().appendTo(brotha);
});

$('.news_latest_item:last-child').addClass('lastnews');


//----
// Accesskeys
//----

$('#accesskeys a').focus(function(){
		$('#accesskeys').attr("style","left: 10px; z-index:999;");
});
$('#accesskeys a').blur(function(){
		$('#accesskeys').attr("style","left: -9999px; z-index:0;");
});


	
	
//----- 	
// Switch stylesheets starts
//-----

var c = readCookie('style');

if (c) {
	
	switchStylestyle(c);
	 
	if (c == "font_11px") {
        	$('.big').each(function(i) {
			$(this).attr({
				rel: "font_12px"
        		});
        	});
        	$('.small').each(function(i) {
			$(this).attr({
				rel: "font_11px"
        		});
        	});
        } else if (c == "font_12px") {
        	$('.big').each(function(i) {
			$(this).attr({
				rel: "font_13px"
        		});
        	});
        	$('.small').each(function(i) {
			$(this).attr({
				rel: "font_11px"
        		});
        	});
        } else if (c == "font_13px") {
        	$('.big').each(function(i) {
			$(this).attr({
				rel: "font_13px"
        		});
        	});
        	$('.small').each(function(i) {
			$(this).attr({
				rel: "font_12px"
        		});
        	});
        }
}
	
$('.big').click(function() {

	var relatt = this.getAttribute("rel");
        
       	switchStylestyle(relatt);
        
        if (relatt == "font_12px") {
		$(this).attr({
			rel: "font_13px"
        	});
        }
        if (relatt == "font_13px") {	
        	$('.small').attr({
			rel: "font_12px"
        	});
	}
	
        return false;
}); 	

$('.small').click(function() {

	var relatt = this.getAttribute("rel");
        
       	switchStylestyle(relatt);
        
        if (relatt == "font_12px") {
		$(this).attr({
			rel: "font_11px"
        	});
        }
        if (relatt == "font_11px") {	
        	$('.big').attr({
			rel: "font_12px"
        	});
	}
	
        return false;
}); 	

//-----
// Switch stylesheets ends
//-----

}); // End jQuery onReady

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);
}

// Ends all jquery



// 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
