
//jQuery onReady

$(document).ready(function(){

//----
// Mailform dropdowns
//----
$('.kommunesellbl').hide();
$('.kommunesel').hide();
$('.regionsellbl').hide();
$('.regionsel').hide();

//var checkval;
$('.tx-thmailformplus-pi1 .krvalg input:radio').click(function(){
  var checkval = $('.tx-thmailformplus-pi1 .krvalg input:radio:checked').val();
  if(checkval == "kommune"){
  	$('.kommunesellbl').show();
	$('.kommunesel').show();
	$('.regionsellbl').hide();
	$('.regionsel').hide();  

  }
  if(checkval == "region"){
  	$('.regionsellbl').show();
	$('.regionsel').show();
	$('.kommunesellbl').hide();
	$('.kommunesel').hide();
  }
});

//----
// Dropdown menues
//----

$('.dropdownmenu .csc-menu').each(function(i){
	var ul = $(this);
	var links = ul.find('a');

	ul.hide();
	ul.after('<form action="/" id="dropdownform'+i+'"><select><option value="/">Vælg fra listen:</option></select></form>');
	var form = $('#dropdownform'+i);
	links.each(function(){
		form.children('select').append('<option value="'+$(this).attr('href')+'">'+$(this).text()+'</option>');
	});
	form.children('select').change(function(){
		$(this).children("option:selected").each(function(){
//			console.log($(this).attr('value'));
			if($(this).attr('value') != '/'){
				form.attr('action',$(this).attr('value')).submit();
			}
		});
	});	
});

/*---- 
	This function enables the menu with the id of ul_nav
	to show the submenu. Works in all browsers
----*/
 	
$('#ul_nav li').hover(function(){
	$(this).addClass('over');
}, function(){
	$(this).removeClass('over');
});



//----
// 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

