
//jQuery onReady

var jq = jQuery.noConflict();

jq(document).ready(function($){


//-----Sandcolorbox - toggle ----
$('.sandcolor_box .expandable_content').each(function(){
	if($(this).children().length != 0) {
	
		// Hide and append img, only if not empty
		$(this).hide().before("<img class='box_toggler' src='fileadmin/images/arrow_down_more.gif' title='Se mere indhold' alt='Se mere indhold' />");
		
		// Toggle
		$(this).siblings('.box_toggler').toggle(function(){
			$(this).siblings('.expandable_content').show("medium");
			$(this).attr("src","fileadmin/images/arrow_up_more.gif");
			$(this).attr("title","Fold ind");
		}, function(){
			$(this).siblings('.expandable_content').hide("medium");
			$(this).attr("src","fileadmin/images/arrow_down_more.gif");
			$(this).attr("title","Se mere indhold");
		});
	}
});

//----- Dokumenter - Tilføj ikoner

var pdf_icon = "<img src='/fileadmin/images/pdf_icon.gif' alt='PDF' />";
var word_icon = "<img src='/fileadmin/images/word_icon.gif' alt='PDF' />";
var excel_icon = "<img src='/fileadmin/images/excel_icon.gif' alt='PDF' />";

$(".doc_item a").each(function(){
	if ($(this).is("[href$=.pdf]")) {
		$(this).parents(".doc_item").prepend(pdf_icon);
	} else if ($(this).is("[href$=.doc]")) {
		$(this).parents(".doc_item").prepend(word_icon);
	} else if ($(this).is("[href$=.xls]")) {
		$(this).parents(".doc_item").prepend(excel_icon);
	}
});


//---- Search
//skjul for dem som ikke js og flyt værdien op i topboxen
$('.tx-indexedsearch form fieldset').hide();
var sword = $('#tx-indexedsearch-searchbox-sword').val();
$('#search .input_text').val(sword);
$('#searchFormular .input_text').attr("autocomplete","off");


//-----newsletter select all categories----
$('.newsletter_all :checkbox').click(function() {
    if ($(this).is(':checked'))
	$('.newsletter_checkbox :checkbox').attr("checked", "checked");
    else
    $('.newsletter_checkbox :checkbox').attr("checked", "");
});

//----
// 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;");
});
	
//----strip lists style---
$('.tx-lfsos-pi1 ul li:nth-child(odd)').each(function(){
       $(this).addClass('odd');
});

//----strip dokumenter style---
$('.docs .doc_item:nth-child(odd)').each(function(){
       $(this).addClass('odd');
});



//----emneord toggle----//
var maxantal = 2;

$('.tx-lfcategoriesfe-pi5 .topic .inner').each(function(){
	var lis = $(this).find("li").size();
	if(lis > maxantal) {
		$(this).append('<img class="catclapper" src="fileadmin/images/arrow_up_more.gif" alt="Vis kun to" />');
	}
});

/*$('.tx-lfcategoriesfe-pi5 .topic .inner ul').each(function(){
	var listitem = $(this).children("li");
	for(var x = maxantal; x < listitem.length; x++) {
		listitem[x].style.display = "none";
	}
});*/

$('.catclapper').toggle(function() {
	var listitem = $(this).siblings("ul").children("li");
	for(var x = maxantal; x < listitem.length; x++) {
		listitem[x].style.display = "none";
	}
	$(this).attr("src","fileadmin/images/arrow_down_more.gif");
	
},function() {
	/*$(this).siblings("ul").children("li").show("medium");*/
	$(this).siblings("ul").children("li").css("display","list-item");
	$(this).attr("src","fileadmin/images/arrow_up_more.gif");
}
);

//****select pulje boks****

$("#stotte_selector").change(function () {
 	 var Link = $(this).children("option:selected").attr("value");
 	 var OldLink = $(this).parent().attr("action");
 	 var NewLink = OldLink + Link;
 	 $(this).parent().attr("action",NewLink); 
});

//*****remove no comments*****
$('.tx-comments-comments .docs .text:contains("Ingen kommentarer")').parent().hide();

}); // 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
