$(document).ready(function() {
	$.ajaxSetup ({
	    // Disable caching of AJAX responses */
	    cache: false
	});
	
	fuie6();
	
	// apply css to main text
	if ($("#home").length) {
		// $("#home .box_darker,#home .maintext").equalHeights();
		$("#home .box_light").equalHeights();
		var el = $("div.maintext ul")
		$("a", el).addClass("more").wrapInner("<span />");
		el.addClass("morelinks");
		
		$("div.box_light").each(function() {
			var el = $("p a", $(this))
			el.addClass("more more_single").wrapInner("<span />").parent().css("margin-left", "0");
			var to = el.attr("href");
			
			$("a", $(this)).attr("href", to);
		})
	}
	
	if ($("#weathercontent").length) {
		$('#weathercontent').load(siteUrl + "/wp-content/themes/espira/yr.php", function() {
			$(this).show();
			fuie6();
		});
	}
	
	$("#sidebar,#main").equalHeights();	
	
	// open external links in new window
	$("a[rel=external]").bind("click", function() {
		window.open(this.href);
		return false;
	});
	
	// spam protect e-mail addresses
	$('a.email').each(function(){
		e = this.rel.replace('/','@');
		this.href = 'mailto:' + e;
		$(this).text(e);
	});
	
	$("#weathercity_settings").change(function() {
		var toOpen = $("#weatherform").attr("action");
		var toSend = this.value;		
		
		$.get(toOpen, { fylkeOgSted: toSend },
			function(data){
				location.reload();
			}
		);
	});
	
	if (typeof imgArray == 'object' && imgArray.length > 1) {
		$('#mainImages').crossSlide({
			sleep: 5,
			fade: 1
		}, 
			imgArray
		);
	}
	
	$("a.weatherchange").live("click", function() {
		$("#weathercontent").fadeOut("slow", function() {
			$("#weather form,#weather .weathercancel").show();
		});
		return false;
	});
	
	$("p.weathercancel a").live("click", function() {
		$("#weather form").fadeOut("slow", function() {
			$("#weathercontent").show();
		});
		return false;
	});
}); // document ready

function fuie6() {
	if ($.browser.msie && $.browser.version <= 6) $('#weather img').ifixpng(); 
}

function cycleMainFeatured() {
	var mainImgVisible = $("#mainTxt img:last:visible");
	var numImages = $("#mainTxt img").length;
	// var lastImage = "mainImg" + $("#mainTxt img").length;
	var firstImage = "mainImg" + numImages;
	var lastImage = "mainImg1";
	
	// alert(mainImgVisible.attr("src"))
	
	if (mainImgVisible.attr("class") == lastImage) {
		loadNext = $(".mainImg1");
	} else {
		loadNext = mainImgVisible.prev();
	}
	
	$(mainImgVisible).fadeOut("slow", function() {
		// loadNext.fadeIn("fast");
	});	
}


