//
//	Försvåra för robotar att hitta en e-postadress
//
function em( a, b, c, d, e ) {
	if( typeof( e ) != "undefined" && e != "" ) {
		if( typeof( d ) != "undefined" && d != "" ) {
			document.write( "<" + "a href=\"mail" + "to:" + a + "@" + b + "." + c + "?" + e + "\">" + d + "</a>" );
		} else {
			document.write( "<" + "a href=\"mail" + "to:" + a + "@" + b + "." + c + "?" + e + "\">" + a + "@" + b + "." + c + "</a>" );
		}
	} else {
		if( typeof( d ) != "undefined" && d != "" ) {
			document.write( "<" + "a href=\"mail" + "to:" + a + "@" + b + "." + c + "\">" + d + "</a>" );
		} else {
			document.write( "<" + "a href=\"mail" + "to:" + a + "@" + b + "." + c + "\">" + a + "@" + b + "." + c + "</a>" );
		}
	}
}

if( 0 ) {
var hdrBase = "chrome/";
var hdr = Array(
		"header01_920x240.jpg",
		"header02_920x240.jpg",
		"header03_920x240.jpg",
		"header04_920x240.jpg",
		"header05_920x240.jpg",
		//"header06_920x240.jpg",
		"header07_920x240.jpg",
		//"header08_920x240.jpg",
		"header09_920x240.jpg",
		//"header10_920x240.jpg",
		"header11_920x240.jpg",
		"header12_920x240.jpg",
		//"header13_920x240.jpg",
		"header14_920x240.jpg",
		"header15_920x240.jpg",
		"header16_920x240.jpg",
		"header17_920x240.jpg",
		"header18_920x240.jpg",
		"header19_920x240.jpg",
		"header20_920x240.jpg",
		"header21_920x240.jpg",
		"header22_920x240.jpg",
		//"header23_920x240.jpg",
		//"header24_920x240.jpg"
		"header25_920x240.jpg",
		"header26_920x240.jpg",
		"header27_920x240.jpg",
		"header28_920x240.jpg",
		"header29_920x240.jpg",
		"header30_920x240.jpg",
		"header31_920x240.jpg",
		"header32_920x240.jpg",
		"header33_920x240.jpg",
		"header34_920x240.jpg",
		"header35_920x240.jpg",
		"header36_920x240.jpg",
		"header37_920x240.jpg",
		"header38_920x240.jpg"
	);
}
var	hbg = 0;

$(document).ready(function(){

	if( $.browser.msie ) {
		var	h1 = $("h1#test"),
			tW = 920,	//h1.width(),
			tH = h1.height(),
			b1 = $("<div id='ie6bg1' />"),
			b2 = $("<div id='ie6bg2' />");
		b1.insertBefore( h1 );
		b2.insertBefore( h1 );
		b1.css({
			width		: Math.floor(tW * 0.45)+"px",
			height		: tH+"px"
		});
		b2.css({
			left		: Math.floor(tW * 0.45)+"px",
			width		: Math.floor(tW * 0.2)+"px",
			height		: tH+"px"
		});
	}

	//
	//	Lägg till en "gå till topp"-tabb och animera den vid behov
	//
	$("<div id=\"gototop\"></div>").attr("title","Go to top of page").bind("click", function() {
		$(window).scrollTop(0);
	}).prependTo("#bgshr");
	$(window).bind("scroll", function() {
		var st = $(window).scrollTop();
		if( st == 0 ) {
			$("div#gototop:visible").animate({"marginLeft":"-=40px"},500,function() { $(this).hide() });
		} else {
			$("div#gototop:hidden").show().animate({"marginLeft":"+=40px"},500);
		}
	});

	$("ul#navigation a").bind("focus", function() { $(this).blur(); });

	//
	//	Kolla vilken bakgrund vi visade sist
	//
	hbg = getCookie("hdrbg");
//	hbg = hbg && parseInt( hbg ) < hdr.length ? parseInt( hbg ) : 0;
	hbg = hbg && parseInt( hbg ) < hdr.length ? parseInt( hbg ) : Math.floor(Math.random()*hdr.length);	// slumpa vilken banner som visas först

	//
	//	Lägg till bakgrunden till huvudet, starta igång
	//	det automatiska bytet av bakgrundsbild
	//
	$("<div class=\"hdrbg\" id=\"hdrbg"+hbg+"\"></div>").hide().css({"backgroundImage":"url("+hdrBase+hdr[hbg]+")"}).prependTo("div#header");
	for( var i = 0; i < hdr.length; i++ ) {
		if( i != hbg ) {
			$("<div class=\"hdrbg\" id=\"hdrbg"+i+"\"></div>").hide().css({"backgroundImage":"url("+hdrBase+hdr[i]+")"}).prependTo("div#header");
		}
	}

	$("div#contents div#header").css({"backgroundImage":"none"});
	$("div#hdrbg"+hbg).show();
	setTimeout( function() {
		var tcb = arguments.callee;
		var nbg = hbg + 1 == hdr.length ? 0 : hbg + 1;
		setCookie("hdrbg", nbg, false, "/", "", "");
		$("div#hdrbg"+nbg).insertAfter("div#hdrbg"+hbg).fadeIn(5000, function() {
			$("div#hdrbg"+hbg).hide();
			hbg = nbg;
			setTimeout( tcb, 10000 );
		});
	}, 10000 );

});

function setCookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
		if the expires variable is set, make the correct
		expires time, the current script below will set
		it for x number of days, to make it for hours,
		delete * 24, for minutes, delete * 60 * 24
	*/
	if( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if( cookie_name == check_name ) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if( !b_cookie_found ) {
		return null;
	}
}
	
