/* Fix Mac Firefox 2 opacity bug */
/* See http://groups.google.com/group/jquery-en/browse_thread/thread/3392907cd85427b9
The drawback now is that the text in FF2 for mac is lighter than in other browsers...
*/
$(document).ready(function() {
	$('body').css({opacity: .9999});
});

/* ### Open external links in new window ### */
$(document).ready(function() {
	$("a[href]").each(function () {
		if ($(this).attr('href').length > 4 && $(this).attr('href').substr(0,4) == 'http') $(this).attr('target','_blank');
	});
});

/*
Slideshow-script v1.0 using on jquery (1.3.2)
(c) Marcus Gustafsson 2009
*/

var activeSlideshowLayer = 'A';
var activeSlideshowImage = 0;
var nextActiveSlideshowImage = 1;

$(document).ready(function() {	
	if (typeof(slideshowImages) != 'undefined' && slideshowImages.length > 0) {
		$("#slideshowAImage").attr("src","/images/slideshow/"+slideshowImages[0][0]);
		$("#slideshowAText").text(slideshowImages[0][1]);
		if (slideshowImages.length > 1) { // only run slideshow if we have more than one image...
			$("#slideshowB").fadeOut(1); // hide second layer (for some reason opacity:0 doesn't work: layer doesn't fade in, it stays hidden!)
			$("#slideshowBImage").attr("src","/images/slideshow/"+slideshowImages[1][0]);
			$("#slideshowBText").text(slideshowImages[1][1]);
			setTimeout("slideshowRun()",4000);
		}
	} else { // finns inga bilder, låt inte slideshow ta upp utrymme...
		$("#slideshow").css("display","none");
	}
});

function slideshowRun() {
	if (activeSlideshowLayer == 'A') {
		newLayer = 'B';
		oldLayer = 'A';
		activeSlideshowLayer = 'B';
	} else {
		newLayer = 'A'
		oldLayer = 'B'
		activeSlideshowLayer = 'A';
	}
	activeSlideshowImage += 1;
	if (activeSlideshowImage == slideshowImages.length) activeSlideshowImage = 0;
	nextActiveSlideshowImage += 1;
	if (nextActiveSlideshowImage == slideshowImages.length) nextActiveSlideshowImage = 0;
	$("#slideshow"+newLayer).fadeIn(2000);
	$("#slideshow"+oldLayer).fadeOut(2000, function() {
			// load next image
	$("#slideshow"+oldLayer+"Image").attr("src","/images/slideshow/"+slideshowImages[nextActiveSlideshowImage][0]);
	$("#slideshow"+oldLayer+"Text").text(slideshowImages[nextActiveSlideshowImage][1]);
	setTimeout("slideshowRun()",4000);
	
	});
}
/* END SLIDESHOW-SCRIPT */

/* POPUP-SCRIPT */

$(document).ready(function(){
	$("#popupBackground").click(function() {
		hidePopup();
	});
});

function showPopup(content) {
	$("#popupBackground").css({
		"opacity": "0",
		"display":"block"}
	);
	$("#popupBackground").fadeTo(300, 0.75);
	$("#popupBody").html(content);
	centerPopup();
	$("#popupBody").fadeIn(400);
}

function showPopupAjax(url) {
	$("#popupBackground").css({
		"opacity": "0",
		"display":"block"}
	);
	$("#popupBackground").fadeTo(300, 0.75);
	$("#popupBody").load(url, '', function() {
		centerPopup();
		$("#popupBody").fadeIn(400);
	});
}

function popupShowError($errorString) {
	$("#popupTitle").innerHTML = 'Ett fel uppstod!';
	$("#popupContent").innerHTML = $errorString;
}

function hidePopup() {
	$("#popupBody").fadeOut(400);
	$("#popupBackground").fadeOut(400);
}

function centerPopup(){  
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = $("#popupBody").height();  
	var popupWidth = $("#popupBody").width();  
	//centering  
	$("#popupBody").css({  
	"position": "absolute",  
	"top": windowHeight/2-popupHeight/2 + window.pageYOffset,  
	"left": windowWidth/2-popupWidth/2  
	});  
	//only need force for IE6  
 
	$("#popupBackground").css({
		"height": windowHeight,
		"top" : window.pageYOffset
	});
}
/* END POPUP-SCRIPT */
