
//jQuery onReady

$(document).ready(function(){


//news lister første item ingen border
$('.news_latest_presserum_right .news_latest_single_item:first-child()').css("border","0");

// Luk bokse

$('.all-box').each(function(){
	var oc = $(this).children('div:first-child').attr("class");
	
	$(this).children().children().children('.close').click(function(){
    			//$(this).parents(".all-box").children().not(".open-box").hide();
    			//$(this).attr("style","background:red;");
    			if(oc == "lukket"){
				$(this).parent().parent().removeClass("lukket");
				oc = $(this).parents('.all-box').children('div:first-child').attr("class");			
    			}
    			else{
    				//alert("åbn");
    				$(this).parent().parent().addClass("lukket");
    				oc = $(this).parents('.all-box').children('div:first-child').attr("class");
    			}
    			return false;
    		});		
	var link = $(this).find("h2 a[href='']").each(function(){
		$(this).removeAttr("href");
	});
	/*
	
	if(oc == "lukket"){
		//$(this).children().children('.box-content').hide();
		//$(this).children().children().children('.close').addClass("open");
		//alert("test");
		$(this).children().children().children('.close').toggle(function(){
			//alert("click1");
			//$(this).removeClass("open");	
    			//$(this).parents().children('.box-content').show();
    			$(this).parent().parent().removeClass("lukket");
    			return false;
   		},function(){
   			//alert("click2");
   			//$(this).addClass("open");
   			//$(this).parents().children('.box-content').hide();
   			$(this).parent().parent().addClass("lukket");
    			return false;
		});
	}else{ //hvis boksen ikke er lukket fra start
		$(this).children().children().children('.close').toggle(function(){
			//$(this).addClass("open");
    			//$(this).parents().children('.box-content').hide();
    			$(this).parent().parent().addClass("lukket");
    			return false;
   		},function(){
   			//$(this).parents().children('.box-content').show();
    			//$(this).removeClass("open");
    			$(this).parent().parent().removeClass("lukket");
    			return false;
		});
	}
	//alert(oc);
	*/
});

$('.all-box-new').each(function(){
	//var oc = $(this).find("div:first").attr("class");
	
	$(this).find('.close').click(function(){
    			//$(this).parents(".all-box").children().not(".open-box").hide();
    			//$(this).attr("style","background:red;");
    			var oc = $(this).parents('.all-box-new').find('div:first').attr("class");
    			//alert(oc);
    			if(oc == "lukket"){
    				//$(this).parent().parent().addClass("lukket");
					$(this).parent().parent().removeClass("lukket");
					$(this).parent().parent().addClass("open");
					oc = $(this).parents('.all-box-new').children('div:first-child').attr("class");			
    			}else{
    				//alert("åbn");
    				$(this).parent().parent().removeClass("open");
    				$(this).parent().parent().addClass("lukket");
    				
    			}
    			return false;
    		});		
		var link = $(this).find("h2 a[href='']").each(function(){
		$(this).removeAttr("href");
	});
	/*
	
	if(oc == "lukket"){
		//$(this).children().children('.box-content').hide();
		//$(this).children().children().children('.close').addClass("open");
		//alert("test");
		$(this).children().children().children('.close').toggle(function(){
			//alert("click1");
			//$(this).removeClass("open");	
    			//$(this).parents().children('.box-content').show();
    			$(this).parent().parent().removeClass("lukket");
    			return false;
   		},function(){
   			//alert("click2");
   			//$(this).addClass("open");
   			//$(this).parents().children('.box-content').hide();
   			$(this).parent().parent().addClass("lukket");
    			return false;
		});
	}else{ //hvis boksen ikke er lukket fra start
		$(this).children().children().children('.close').toggle(function(){
			//$(this).addClass("open");
    			//$(this).parents().children('.box-content').hide();
    			$(this).parent().parent().addClass("lukket");
    			return false;
   		},function(){
   			//$(this).parents().children('.box-content').show();
    			//$(this).removeClass("open");
    			$(this).parent().parent().removeClass("lukket");
    			return false;
		});
	}
	//alert(oc);
	*/
});




$(".results_numbers span:contains('Forrige')").addClass("prev_link_left");
$(".results_numbers a:contains('Forrige')").addClass("prev_link_left");

//link divs img_w_txt, img_w_txt_under
$(".img_w_txt").linkelement({className: "rklink"});
$(".img_w_txt_under").linkelement({className: "rklink"});


//flytter www adressen på byens liv single visning
$('.homepage_placeholder').replaceWith($('#homepage'));
$('#homepage').wrapInner('<a target="_blank"></a>');
$('#homepage a').attr('href','http://' + $('#homepage').text());


//søgning i byens liv, skjuler og viser søgeresultater / tekst
if($('.right .tx-cal-controller ul li').attr('id') == "byens_liv_nores"){
	$('.right .tx-cal-controller').hide();
}
if($('.right .tx-cal-controller ul li').attr('class') == "searchitem" || $('.right .tx-cal-controller ul li').attr('class') == "dayitem" ){
	$('.right .tx-cal-controller').show();
	$('.twocol .right .csc-textpic').hide();
}

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

//search frontpage - show hide search instructions
$('.search_box .options img').click(function(){
	$('.whitebox_redheader').show();
});

$('.search_box .inner .searchForm .option_help').click(function(){
	$('.whitebox_redheader').show();
});

$('.search_box .inner .tx-lfsearch-pi1 .option_help').click(function(){
	$('.whitebox_redheader').show();
});

$('.whitebox_redheader .options img').click(function(){
	$(this).parent().parent().hide();
});

//don't submit form
$('#search_form').submit(function(){
	return false;
});

//remove boxes after search results
$('#queryResult > div').each(function(){
	$('.tx-lfcustomsearch-pi1').nextAll().hide();
});
//----- 	
// 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



// TAB Javascript fra psd2html
function initTabs()
{
	var sets = document.getElementsByTagName("div");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

					//reset all tabs on start
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";

					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							//reset all tabs before change
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}

if (window.addEventListener) window.addEventListener("load", initTabs, false);
else if (window.attachEvent) window.attachEvent("onload", initTabs);


