
//jQuery onReady

$(document).ready(function(){

/*Fjerner tomme links fra forsiden*/
$('.box-text a').each(function(){
    if($(this).attr('href') == ''){
        var tekst = $(this).text();
        $(this).parent().append(tekst);
        $(this).remove();
    }
});

/*-----news rotater ---*/

//antal nyheder
var totalcount = 0;
$('.side-box .news_latest_item').each(function(){
	totalcount++;
});
//alert(totalcount);

$('.side-box .news_latest_item').hide();
$('.side-box .news_latest_item:eq(0)').show();

//næste knap
var nexti = 1;
var previ = totalcount-1;

//forrige knap
//$('.side-box .news_latest_container').append('<a id="prevbtn">Forrige</a>');
$('.side-box #prevbtn').click(function(){
	//alert(previ);
	//alert(nexti);
	
	//sætter i til totalcount hvis man står på første item
	if(previ == -1){
		previ = totalcount-1;
	}
	
	//$('.side-box .news_latest_item').hide();
	//$('.side-box .news_latest_item:eq('+previ+')').fadeIn();
	$('.side-box .news_latest_item').hide();
	$('.side-box .news_latest_item:eq('+previ+')').show('slide',{ direction: 'left' },500);
	
	previ--;
	nexti = previ +2;
	
	return false;
});

//$('.side-box .news_latest_container').append('<a id="nextbtn">Næste</a>');
$('.side-box #nextbtn').click(function(){
	//sætter i til 0 hvis man står på sidste item
	if(nexti == totalcount){
		nexti = 0;
	}

  var options = {};
	//$('.side-box .news_latest_item').hide();
	//$('.side-box .news_latest_item:eq('+nexti+')').fadeIn();
	$('.side-box .news_latest_item').hide();
	$('.side-box .news_latest_item:eq('+nexti+')').show('slide',{ direction: 'right' },500);
	
	nexti++;
	previ = nexti-2;
	return false;
});

window.setInterval(function(){
	//sætter i til 0 hvis man står på sidste item
	if(nexti == totalcount){
		nexti = 0;
	}

	$('.side-box .news_latest_item').hide();
	$('.side-box .news_latest_item:eq('+nexti+')').show('slide',{ direction: 'right' },500);
	
	nexti++;
	previ = nexti-2;
	return false;
},8000); 


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