
//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 fil' />";
var word_icon = "<img src='/fileadmin/images/word_icon.gif' alt='Word fil' />";
var excel_icon = "<img src='/fileadmin/images/excel_icon.gif' alt='Excel fil' />";

$(".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();

$('.news-catmenu .level1:first-child').hide();

$("#tx_comments_pi1_email").keyup(function(){
		
			var email = $("#tx_comments_pi1_email").val();
		
			if(email != 0)
			{
				if(isValidEmailAddress(email))
				{
					$("#validEmail").css({
						"background": "url('/fileadmin/images/validYes.png')"
					});
					$("#validEmail").attr("title","Valid");
				} else {
					$("#validEmail").css({
						"background": "url('/fileadmin/images/validNo.png')"
					});
					$("#validEmail").attr("title","Ikke valid");
				}
			} else {
				$("#validEmail").css({
					"background": "none"
				});			
			}
		
		});
		
//link around box
$(".small-campaign .inner").each(function(){
	var Link = $(this).find("a").attr("href");
	$(this).wrap("<a class='small-campaign-link'></a>");
	$(this).parent().attr("href", Link); 
});

}); // End jQuery onReady

//function valid email

function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
}

// 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

