
//jQuery onReady

jQuery.noConflict();

jQuery(document).ready(function($){

$('.deabatehead:first').css("background","none");


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

//-------------
// Input values for ve_guestbook and tipafriend
//-------------
if($('.tx-guestbook-field_left :input').attr("value") == null)
$('.tx-guestbook-field_left :input').attr("value","Dit navn");

if($('.tx-guestbook-field_right :input').attr("value") == null)
$('.tx-guestbook-field_right :input').attr("value","Din e-mail adresse");

if($('.tx-guestbook-field textarea').attr("value") == null)
$('.tx-guestbook-field textarea').attr("value","Din kommentar");

if($('#tipforms #tipsender').attr("value") == null)
$('#tipforms #tipsender').attr("value", "Dit navn");

if($('#tipforms #tipsenderemail').attr("value") == null)
$('#tipforms #tipsenderemail').attr("value", "Din e-mail adresse");

if($('#tipforms #tipreceiver').attr("value") == null)
$('#tipforms #tipreceiver').attr("value", "Dit vens navn");

if($('#tipforms #tipreceiveremail').attr("value") == null)
$('#tipforms #tipreceiveremail').attr("value", "Din vens e-mail adresse");

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


//mouse over funktion nyheder

$(".news_latest_item").each(function(){
      var Link = $(this).find("a").attr("href");
      $(this).wrap("<a class='box_link'></a>");
      $(this).parent().attr("href", Link);
});

$(".news_list_item").each(function(){
      var Link = $(this).find("a").attr("href");
      $(this).wrap("<a class='box_link'></a>");
      $(this).parent().attr("href", Link);
});

$(".mostview_news").each(function(){
      var Link = $(this).find("a").attr("href");
      $(this).wrap("<a class='box_link'></a>");
      $(this).parent().attr("href", Link);
});

$(".file_item").each(function(){
      var Link = $(this).find("a").attr("href");
      $(this).wrap("<a class='box_link'></a>");
      $(this).parent().attr("href", Link);
});

$(".comment").each(function(){
      var Link = $(this).find("a").attr("href");
      $(this).wrap("<a class='box_link'></a>");
      $(this).parent().attr("href", Link);
});

$(".link_box").each(function(){
      var Link = $(this).children().find("a").attr("href");
      $(this).wrap("<a class='box_link'></a>");
      $(this).parent().attr("href", Link);
});

/*
$(".twrss_table").each(function(){
      var Link = $(this).children().find("a").attr("href");
      $(this).wrap("<a class='box_link'></a>");
      $(this).parent().attr("href", Link);
      $(this).parent().attr("target", "_blank");
});
*/

$(".arrangement").each(function(){
      var Link = $(this).children().find("a").attr("href");
      $(this).wrap("<a class='box_link'></a>");
      $(this).parent().attr("href", Link);
});

//anchor - fetching the right url    
$('.anchor_box a').each(function(){
	var siteUrl = window.location;
	var linkUrl = $(this).attr("href");
	if ( linkUrl.indexOf("#") > -1 ){
        elId = linkUrl.substr(linkUrl.indexOf("#"));
        }
	$(this).attr("href", siteUrl + elId);
});


// Slide Kategorivælger

var emnecookie = (readCookie("emneslide") == 0 || readCookie("emneslide") == null) ? 0 : 1;

if(emnecookie == 1){
	$("#sorter_efter_emne_plugin").show();

	$("#sorter_efter_emne_overskrift").toggle(function(){
		$("#sorter_efter_emne_plugin").slideUp('medium');
		createCookie("emneslide",0,365);
	}, function(){
		$("#sorter_efter_emne_plugin").slideDown('medium');
		createCookie("emneslide",1,365);
	});
} else {
	$("#sorter_efter_emne_overskrift").toggle(function(){
		$("#sorter_efter_emne_plugin").slideDown('medium');
		createCookie("emneslide",1,365);
	}, function(){
	        $("#sorter_efter_emne_plugin").slideUp('medium');
		createCookie("emneslide",0,365);  
	});
}

$("#sorter_efter_emne_luk_ikon_bund img").click(function(){
	$("#sorter_efter_emne_plugin").slideUp('medium');
	createCookie("emneslide",0,365);
});




$(".news_list_item img[src*='plus']").toggle(
	function(){
		$(this).parents(".news_list_item").children(".subheader").slideDown('medium');
		var minuspic = "fileadmin/images/minus.gif";
		$(this).attr("src",minuspic);
		
	},function(){
		$(this).parents(".news_list_item").children(".subheader").slideUp();
 		var pluspic = "fileadmin/images/plus.gif";
		$(this).attr("src",pluspic);
	}
);

//hide empty doc and links boxes

$(".related_docs").parent().parent().hide();
$(".related_docs>dl:has(dd)").each(function(){
    	$(this).parent().parent().parent().show();
});

$(".links_news").parent().parent().hide();
$(".links_news>p").each(function(){
    	$(this).parent().parent().parent().show();
});

// skjuler og viser captcha til nyhedbrevtilmelding

$('.tx-sremailsubscribe-pi1-captcha-response').hide();

if ($('p.tx-sremailsubscribe-pi1-error_captcha').text().length > 0)
{
$('.tx-sremailsubscribe-pi1-captcha-response').show();
$('input#tx-sremailsubscribe-pi1-captcha-response').focus();		
}

$('input#tx-sremailsubscribe-pi1-name').focus(function()
{
$('.tx-sremailsubscribe-pi1-captcha-response').fadeIn(1000);			
});

$('input#tx-sremailsubscribe-pi1-email').focus(function()
{
$('.tx-sremailsubscribe-pi1-captcha-response').fadeIn(1000);			
});




}); // End jQuery onReady




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