
//jQuery onReady

$(document).ready(function(){
/*
$('.focusbox').hover(function(){
    $(this).css('background-color','#faa61a');
    sIFR.replace(book, {
          selector: '.focusbox .orange',
          css: '.sIFR-root { text-transform:uppercase; background-color:#faa61a; color:#000000;}'
    });
},function(){
    $(this).css('background-color','#000000');
});
*/

if($('#tx_comments_pi1_firstname').val() == ""){
	$('#tx_comments_pi1_firstname').val('Skal skrives');
}
if($('#tx_comments_pi1_email').val() == ""){
	$('#tx_comments_pi1_email').val('Skal skrives (vises ikke)');
}
$('.tx-comments-comment-form form').submit(function(){
	if($('#tx_comments_pi1_firstname').val() == "Skal skrives"){
		$('#tx_comments_pi1_firstname').val("");
	}
	if($('#tx_comments_pi1_email').val() == "Skal skrives (vises ikke)"){
		$('#tx_comments_pi1_email').val("");
	}
});




if($('.tx-comments-comments .nocomments').text() != "Ingen kommentarer"){
	$('.tx-comments-comments').addClass('active');
}

var colheight = $('#twocolumns #content').height()- $('#sidebar .sectionhead').height() - $('#sidebar  .social-links').height() + 20;
$('ul.sidenav').css('min-height',colheight);

$('.news_list_container .news_list_item:last').addClass("last");

//---- 
// All text inputs with a value get their value emptied on focus
//----	
	$(":text[class='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);
  			}
		});
	});
	

// Submits forms

$('.submit_on_change_url').change(function () {
	window.location = '/' + $(this).val();
})

//submit select forms on change

$('#maingroupselect select').change(function() {
 if($(this).val()=='-2') {
 return false;
 } else {
 this.form.submit();
 }
});

//submit select forms on change

$('#subgroupselect select').change(function() {
 if($(this).val()=='-2') {
 return false;
 } else {
 this.form.submit();
 }
});




//----
// sitemap active
//----
$('#footer .cols .col').each(function(){
	if($(this).find('li').hasClass("active")){
		$(this).find('strong').addClass("active");
		$(this).find('ul').addClass("active");
	}
});

//----
//tabset classes
//----

$('.tabset li').each(function(i){
	$(this).children('a').addClass("item"+i);
});


/*---- 
	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');
});




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