var ie = false;
if (jQuery.browser.msie) {
      ie = true;
}

//---------------------------------------------------------------------------------------
//
//  Autopass info vindu
// 
//---------------------------------------------------------------------------------------

function fullDetailWindowOpen(){
}

function fullDetailWindowClosed(){
	flashBubblingFix(true);
}

var flashBubblingFixStatus;
function flashBubblingFix(fix){
    flashBubblingFixStatus = fix;
    if ($("input[name='miniMapSwitch']").val() != 1) {
	    if(fix){ 
		      
	        $("#shaddowContainer, #shaddowContainer").hide();
	        var pos = $("#PageContainer").position();
	        var leftPos = pos.left + 42 + 607;
	        var topPos = pos.top + 113;
	        $("#detailContainer").css({
	            left: leftPos, top: topPos
	        });
	        $("#detailContainer .narrow").css("left", (641-607));
	        $("#detailContainer .wideContainer .wide").css("left", (607-607)).css("width", (926-607));
	        $("#detailContainer .wideHeaderContainer .wideHeader").css("left", (607-607)).css("width", (926-607));
	        $("#detailContainer .close").css("left", (906-607)).removeShadow();
	        
	        var shaddowLeftPos = leftPos - 8;
	        var shaddowTopPos = topPos - 8;
	        $("#shaddowContainer").css({
	            left: shaddowLeftPos, top: shaddowTopPos
	        });
	        $("#shaddowContainer #narrowContainer").css("left", (659-607));
	        $("#shaddowContainer #wideContainer #wide").css("left", (608-607)).css("width", (51));
	        
	        $("#detailContainer .wideContainer").css("width", (926-607));
	        $("#detailContainer").css("width", (926-607));
	        
	        $("#shaddowContainer #wideContainer #wide").css("width", (946-607));
	        $("#shaddowContainer #wideContainer").css("width", (659-607));
	        
	        $("#detailContainer .wideHeaderContainer").css("width", (926-607));
	        
	        $("#shaddowContainer").css("width", (946-607));
	        $("#shaddowContainer, #shaddowContainer").show();
	    }else{
	        $("#shaddowContainer, #shaddowContainer").hide();
	        var pos = $("#PageContainer").position();
	        var leftPos = pos.left + 42;
	        var topPos = pos.top + 113;
	        $("#detailContainer").css({
	            left: leftPos, top: topPos
	        });
	        $("#detailContainer .narrow").css("left", (641));
	        $("#detailContainer .wideContainer .wide").css("left", (607)).css("width", (926));
	        $("#detailContainer .wideHeaderContainer .wideHeader").css("left", (607)).css("width", (926));
	        $("#detailContainer .close").css("left", (906)).redrawShadow();
	        
	        var shaddowLeftPos = leftPos - 8;
	        var shaddowTopPos = topPos - 8;
	        $("#shaddowContainer").css({
	            left: shaddowLeftPos, top: shaddowTopPos
	        });
	        $("#shaddowContainer #narrowContainer").css("left", (659));
	        $("#shaddowContainer #wideContainer #wide").css("left", (608)).css("width", (946));
	        
	        $("#detailContainer .wideContainer").css("width", (926));
	        $("#detailContainer").css("width", (926));
	        
	        $("#shaddowContainer #wideContainer #wide").css("width", (946));
	        $("#shaddowContainer #wideContainer").css("width", (659));
	        
	        $("#detailContainer .wideHeaderContainer").css("width", (926));
	        
	        $("#shaddowContainer").css("width", (946));
	        $("#shaddowContainer, #shaddowContainer").show();
	    }
    }
}

function parseXml(xml) {  
     if (ie) {  
          var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");  
          xmlDoc.loadXML(xml);  
          xml = xmlDoc;  
     }  
     return xml;  
} 

function getAnleggsInfo(id){
     $.ajax({
          url: "System/Kart/DetailXml",
          type: "POST",
          data: ({anlegg: id}),
          dataType: "text/html",
          success: function(data){

               data = parseXml(data);
               var anleggsInfo= new Array();
               anleggsInfo['id']=id;
               anleggsInfo['header']=$(data).find("anlegg").attr("navn");
               autopassShowDetailsExecute(anleggsInfo);

          }, 
          error: function(data){
               var anleggsInfo= new Array();
               anleggsInfo['id']=id;
               anleggsInfo['header']="Error!";

               autopassShowDetailsExecute(anleggsInfo);
          }
     });
}

function generateInfoShaddow(){
     if($("#shaddowContainer")) $("#shaddowContainer").remove();
     var html = "\
<div id='shaddowContainer'>\
<div id='narrowContainer'><div id='narrowleft'></div><div id='narrowright'></div></div>\
<div id='wideContainer'><div id='wide'></div></div>\
</div>\
     ";
     $("#detailContainer").after(html);
     $(".close").dropShadow({opacity : 0.5, blur: 4, left: 2, top: 2});
}

$(window).resize(autopassPlaceInfoWindow);

function autopassPlaceInfoWindow() {
    var pos = $("#PageContainer").position();
    if ($("input[name='miniMapSwitch']").val() == 1) {
        var leftPos = pos.left + 90;
        var topPos = pos.top + 215;
        $("#miniMapDetailContainer").css({
            left: leftPos, top: topPos
        });
    } else {
        var leftPos = pos.left + 42;
        var topPos = pos.top + 113;
        $("#detailContainer").css({
            left: leftPos, top: topPos
        });
        var shaddowLeftPos = leftPos - 8;
        var shaddowTopPos = topPos - 8;
        $("#shaddowContainer").css({
            left: shaddowLeftPos, top: shaddowTopPos
        });
    }
    flashBubblingFix(flashBubblingFixStatus);
}
function autopassShowDetails(id) {
     if($("#detailContainer").length>0) $("#detailContainer").remove();
     getAnleggsInfo(id);
}

function printPage(){
    window.print();
    return false;
}

function makePrintableAndPrint(){
    $(".wideContent .header").addClass("open");
    $(".wideContent .content").css("display", "block");
    printPage();
}

function autopassShowDetailsExecute(anleggsInfo) {
    if ($("input[name='miniMapSwitch']").val() == 1 && $("html").attr("xml:lang")== 'en') {
        $("#articles").hide();
        if ($("#miniMapDetailContainer").length == 0) {
            var container = "\
            <div id='miniMapDetailContainer'>\
            <div id='miniMapHeader'></div>\
            <div id='info'></div>\
            <div class='close'></div>\
            </div>\
            ";
            $("body").append(container);
            $("#miniMapDetailContainer").dropShadow({
                opacity: 0.5, blur: 4, left: 2, top: 2
            });
            $("#miniMapDetailContainer .close").bind("click", function () {
                $("#miniMapDetailContainer, .dropShadow").remove();
                $("#articles").show();
            }).dropShadow({
                opacity: 0.5, blur: 4, left: 2, top: 2
            });
        }
        $("#miniMapDetailContainer #info").load("System/Kart/DetailHtmlEn?anlegg=" + anleggsInfo[ 'id'], "", function () {
            $("#miniMapDetailContainer #miniMapHeader").html(anleggsInfo[ 'header']);
        });
        
    } else {
        if ($("#detailContainer").length == 0) {
            var container = "\
            <div id='detailContainer'>\
            <div class='narrow'>\
            <div class='narrowContent'></div>\
            </div>\
            <div class='wideContainer'>\
            <div class='wide'>\
            <div class='handle'></div>\
            <div class='wideContent'></div>\
            </div>\
            </div>\
            <div class='wideHeaderContainer'>\
            <div class='wideHeader'><span class='icon-closed' id='expandCollapsIcon'></span><span class='header'></span></div>\
            </div>\
            <div class='close'></div>\
            </div>\
            ";
            $("body").append(container);
        }
        $("#detailContainer .header").html(anleggsInfo[ 'header']);
        //Skalerer ned overskrift om den er for lang fra maks fontstørrelse 16 til minimum 8.
        for(var i=16;i>8;i--){
            if($("#detailContainer .header").width()>269)$("#detailContainer .header").css("font-size", i+"px");
        }
        for(var i=18;i<25;i++){
            if(parseFloat($("#detailContainer .header").height())+parseFloat($("#detailContainer .header").css("padding-top"))<38)$("#detailContainer .header").css("padding-top", i+"px");
        }
        
        

        generateInfoShaddow();
        autopassPlaceInfoWindow();
        $(document).pngFix();

        $("#detailContainer #collapsExpand, #detailContainer .wide .handle, #detailContainer .wideHeader").bind("click", function () {
            if ($("#detailContainer .wide").hasClass("open")) {
                $("#detailContainer .wide .wideContent").fadeOut("fast", function () {
                    $("#detailContainer .wide").dequeue().removeClass("open").animate({
                        left: 607
                    },
                    "slow", function () {
                        $("#detailContainer #collapsExpand").html(anleggsInfo[ 'open']);
                        $("#detailContainer .wideHeader .icon-open").removeClass("icon-open").addClass("icon-closed");
                    });
                    $("#detailContainer .wideHeaderContainer .wideHeader").dequeue().animate({
                        left: 607
                    },
                    "slow", function () {
                        fullDetailWindowClosed();
                    });
                    $("#shaddowContainer #wide").dequeue().animate({
                        left: 608
                    },
                    "slow", function () {
                        fullDetailWindowClosed();
                    });
                });
            } else {
                flashBubblingFix(false);
                $("#detailContainer .wide").dequeue().addClass("open").animate({
                    left: 0
                },
                "slow", function () {
                    $("#detailContainer .wide .wideContent").fadeIn("fast");
                    $("#detailContainer #collapsExpand").html(anleggsInfo[ 'close']);
                    $("#detailContainer .wideHeader .icon-closed").removeClass("icon-closed").addClass("icon-open");
                    fullDetailWindowOpen();
                });
                $("#detailContainer .wideHeaderContainer .wideHeader").dequeue().animate({
                    left: 0
                },
                "slow", function () {
                });
                $("#shaddowContainer #wide").dequeue().animate({
                    left: 0
                },
                "slow", function () {
                });
            }
        });
        $("#detailContainer .wideContent").load("System/Kart/DetailHtml?anlegg=" + anleggsInfo[ 'id'], "", activateWideContent);
        $("#detailContainer .narrowContent").load("System/Kart/DetailSmallHtml?anlegg=" + anleggsInfo[ 'id'], "", function () {
            $("#print").bind("click", printPage);
            $(".narrowContent .mychoice").each(function () {
                var myChoice = $(this).text();
                
                $(this).bind("click", function () {
	                	if (!$("#detailContainer .wide").hasClass("open")){
	                		$("#detailContainer .wideHeader").trigger("click");
	                		setTimeout("activateMyChoice('"+myChoice+"')", 1000);
                		}else{
	                		$(".wideContent .header h3:contains('" + myChoice + "')").parent(".header").trigger("click");
                		}
                });
            });
            
            for(var i=11; i>8; i--){
	          logger("bredde: " + $(".narrowContent .epost a").width());
	       		if($(".narrowContent .epost a").width()>200)$(".narrowContent .epost a").css("font-size", i+"px");
        }
        });
        if (ie) {
            $(".wideContent").scroll(function () {
                if ($(".wideContent .open").next(".content").find("#bomstasjonkart").length > 0) {
                    $(".wideContent .open").next(".content").find("#bomstasjonkart").css("display", "");
                    googleMaps();
                }
            });
        }
        $("#detailContainer .close").bind("click", function () {
            autopassCloseDetails();
        });
        
        if ($("input[name='miniMapSwitch']").val() == 1 && $("html").attr("xml:lang")== 'no') {
	        $("#detailContainer .wide .handle").trigger("click");
        }
        
        flashBubblingFix(true);
    }
}
function activateMyChoice(myChoice){
	$(".wideContent .header h3:contains('" + myChoice + "')").parent(".header").trigger("click");
}

var googleMapCheck = false;
function activateWideContent(){
    logger(googleMapCheck);
     $(".wideContent .header").bind("click", function(){
          if($(this).hasClass("open")){
               $(this).removeClass("open").next(".content").slideUp("fast").siblings(".content").slideUp("fast");
               $(this).siblings(".header").removeClass("open");
          }else{
               $(this).addClass("open").next(".content").slideDown("fast").siblings(".content").slideUp("fast", function(){
                    if(!googleMapCheck) setTimeout("checkForGoogleMaps()", 300);
               });
               $(this).siblings(".header").removeClass("open");
          }
     });
}

function checkForGoogleMaps(){
     logger("Google Maps Active: "+googleMapCheck);
     if(!googleMapCheck && ($(".wideContent .open").next(".content").find("#bomstasjonkart").length>0)){
          logger("Activating Google Maps...");
          $(".wideContent .open").next(".content").find("#bomstasjonkart").css("display", "");
          googleMaps();
          googleMapCheck=true;
     }
}

function autopassCloseDetails(){
    googleMapCheck = false;
     $("#shaddowContainer").remove();
     $("#detailContainer .close").removeShadow();
     $("#detailContainer").fadeOut("fast", function(){$(this).remove()});
}

//---------------------------------------------------------------------------------------
//
//  PNG Fix
// 
//---------------------------------------------------------------------------------------

/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.1, 11.09.2007
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 */
/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.2, 09.03.2009
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    09.03.2009 Version 1.2
 *    - Update for jQuery 1.3.x, removed @ from selectors
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'crop\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});
		
		//fix input with png-source
		jQuery(this).find("input[src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});
	
	}
	
	return jQuery;

};

})(jQuery);


$(document).ready(function(){ 
     $(document).pngFix();
}); 

//---------------------------------------------------------------------------------------
//
//  Drop shaddow
// 
//---------------------------------------------------------------------------------------

/*
	VERSION: Drop Shadow jQuery Plugin 1.6  12-13-2007

	REQUIRES: jquery.js (1.2.6 or later)

	SYNTAX: $(selector).dropShadow(options);  // Creates new drop shadows
					$(selector).redrawShadow();       // Redraws shadows on elements
					$(selector).removeShadow();       // Removes shadows from elements
					$(selector).shadowId();           // Returns an existing shadow's ID

	OPTIONS:

		left    : integer (default = 4)
		top     : integer (default = 4)
		blur    : integer (default = 2)
		opacity : decimal (default = 0.5)
		color   : string (default = "black")
		swap    : boolean (default = false)

	The left and top parameters specify the distance and direction, in	pixels, to
	offset the shadow. Zero values position the shadow directly behind the element.
	Positive values shift the shadow to the right and down, while negative values 
	shift the shadow to the left and up.
	
	The blur parameter specifies the spread, or dispersion, of the shadow. Zero 
	produces a sharp shadow, one or two produces a normal shadow, and	three or four
	produces a softer shadow. Higher values increase the processing load.
	
	The opacity parameter	should be a decimal value, usually less than one. You can
	use a value	higher than one in special situations, e.g. with extreme blurring. 
	
	Color is specified in the usual manner, with a color name or hex value. The
	color parameter	does not apply with transparent images.
	
	The swap parameter reverses the stacking order of the original and the shadow.
	This can be used for special effects, like an embossed or engraved look.

	EXPLANATION:
	
	This jQuery plug-in adds soft drop shadows behind page elements. It is only
	intended for adding a few drop shadows to mostly stationary objects, like a
	page heading, a photo, or content containers.

	The shadows it creates are not bound to the original elements, so they won't
	move or change size automatically if the original elements change. A window
	resize event listener is assigned, which should re-align the shadows in many
	cases, but if the elements otherwise move or resize you will have to handle
	those events manually. Shadows can be redrawn with the redrawShadow() method
	or removed with the removeShadow() method. The redrawShadow() method uses the
	same options used to create the original shadow. If you want to change the
	options, you should remove the shadow first and then create a new shadow.
	
	The dropShadow method returns a jQuery collection of the new shadow(s). If
	further manipulation is required, you can store it in a variable like this:

		var myShadow = $("#myElement").dropShadow();

	You can also read the ID of the shadow from the original element at a later
	time. To get a shadow's ID, either read the shadowId attribute of the
	original element or call the shadowId() method. For example:

		var myShadowId = $("#myElement").attr("shadowId");  or
		var myShadowId = $("#myElement").shadowId();

	If the original element does not already have an ID assigned, a random ID will
	be generated for the shadow. However, if the original does have an ID, the 
	shadow's ID will be the original ID and "_dropShadow". For example, if the
	element's ID is "myElement", the shadow's ID would be "myElement_dropShadow".

	If you have a long piece of text and the user resizes the	window so that the
	text wraps or unwraps, the shape of the text changes and the words are no
	longer in the same positions. In that case, you can either preset the height
	and width, so that it becomes a fixed box, or you can shadow each word
	separately, like this:

		<h1><span>Your</span> <span>Page</span> <span>Title</span></h1>

		$("h1 span").dropShadow();

	The dropShadow method attempts to determine whether the selected elements have
	transparent backgrounds. If you want to shadow the content inside an element,
	like text or a transparent image, it must not have a background-color or
	background-image style. If the element has a solid background it will create a
	rectangular	shadow around the outside box.

	The shadow elements are positioned absolutely one layer below the original 
	element, which is positioned relatively (unless it's already absolute).

	*** All shadows have the "dropShadow" class, for selecting with CSS or jQuery.

	ISSUES:
	
		1)	Limited styling of shadowed elements by ID. Because IDs must be unique,
				and the shadows have their own ID, styles applied by ID won't transfer
				to the shadows. Instead, style elements by class or use inline styles.
		2)	Sometimes shadows don't align properly. Elements may need to be wrapped
				in container elements, margins or floats changed, etc. or you may just 
				have to tweak the left and top offsets to get them to align. For example,
				with draggable objects, you have to wrap them inside two divs. Make the 
				outer div draggable and set the inner div's position to relative. Then 
				you can create a shadow on the element inside the inner div.
		3)	If the user changes font sizes it will throw the shadows off. Browsers 
				do not expose an event for font size changes. The only known way to 
				detect a user font size change is to embed an invisible text element and
				then continuously poll for changes in size.
		4)	Safari support is shaky, and may require even more tweaks/wrappers, etc.
		
		The bottom line is that this is a gimick effect, not PFM, and if you push it
		too hard or expect it to work in every possible situation on every browser,
		you will be disappointed. Use it sparingly, and don't use it for anything 
		critical. Otherwise, have fun with it!
				
	AUTHOR: Larry Stevens (McLars@eyebulb.com) This work is in the public domain,
					and it is not supported in any way. Use it at your own risk.
*/


(function($){

	var dropShadowZindex = 10000;  //z-index counter

	$.fn.dropShadow = function(options)
	{
		// Default options
		var opt = $.extend({
			left: 4,
			top: 4,
			blur: 2,
			opacity: .5,
			color: "black",
			swap: false
			}, options);
		var jShadows = $([]);  //empty jQuery collection
		
		// Loop through original elements
		this.not(".dropShadow").each(function()
		{
			var jthis = $(this);
			var shadows = [];
			var blur = (opt.blur <= 0) ? 0 : opt.blur;
			var opacity = (blur == 0) ? opt.opacity : opt.opacity / (blur * 8);
			var zOriginal = (opt.swap) ? dropShadowZindex : dropShadowZindex + 1;
			var zShadow = (opt.swap) ? dropShadowZindex + 1 : dropShadowZindex;
			
			// Create ID for shadow
			var shadowId;
			if (this.id) {
				shadowId = this.id + "_dropShadow";
			}
			else {
				shadowId = "ds" + (1 + Math.floor(9999 * Math.random()));
			}

			// Modify original element
			$.data(this, "shadowId", shadowId); //store id in expando
			$.data(this, "shadowOptions", options); //store options in expando
			jthis
				.attr("shadowId", shadowId)
				.css("zIndex", zOriginal);
			if (jthis.css("position") != "absolute") {
				jthis.css({
					position: "relative",
					zoom: 1 //for IE layout
				});
			}

			// Create first shadow layer
			bgColor = jthis.css("backgroundColor");
			if (bgColor == "rgba(0, 0, 0, 0)") bgColor = "transparent";  //Safari
			if (bgColor != "transparent" || jthis.css("backgroundImage") != "none" 
					|| this.nodeName == "SELECT" 
					|| this.nodeName == "INPUT"
					|| this.nodeName == "TEXTAREA") {		
				shadows[0] = $("<div></div>")
					.css("background", opt.color);								
			}
			else {
				shadows[0] = jthis
					.clone()
					.removeAttr("id")
					.removeAttr("name")
					.removeAttr("shadowId")
					.css("color", opt.color);
			}
			shadows[0]
				.addClass("dropShadow")
				.css({
					height: jthis.outerHeight(),
					left: blur,
					opacity: opacity,
					position: "absolute",
					top: blur,
					width: jthis.outerWidth(),
					zIndex: zShadow
				});
				
			// Create other shadow layers
			var layers = (8 * blur) + 1;
			for (i = 1; i < layers; i++) {
				shadows[i] = shadows[0].clone();
			}

			// Position layers
			var i = 1;			
			var j = blur;
			while (j > 0) {
				shadows[i].css({left: j * 2, top: 0});           //top
				shadows[i + 1].css({left: j * 4, top: j * 2});   //right
				shadows[i + 2].css({left: j * 2, top: j * 4});   //bottom
				shadows[i + 3].css({left: 0, top: j * 2});       //left
				shadows[i + 4].css({left: j * 3, top: j});       //top-right
				shadows[i + 5].css({left: j * 3, top: j * 3});   //bottom-right
				shadows[i + 6].css({left: j, top: j * 3});       //bottom-left
				shadows[i + 7].css({left: j, top: j});           //top-left
				i += 8;
				j--;
			}

			// Create container
			var divShadow = $("<div></div>")
				.attr("id", shadowId) 
				.addClass("dropShadow")
				.css({
					left: jthis.position().left + opt.left - blur,
					marginTop: jthis.css("marginTop"),
					marginRight: jthis.css("marginRight"),
					marginBottom: jthis.css("marginBottom"),
					marginLeft: jthis.css("marginLeft"),
					position: "absolute",
					top: jthis.position().top + opt.top - blur,
					zIndex: zShadow
				});

			// Add layers to container	
			for (i = 0; i < layers; i++) {
				divShadow.append(shadows[i]);
			}
			
			// Add container to DOM
			jthis.after(divShadow);

			// Add shadow to return set
			jShadows = jShadows.add(divShadow);

			// Re-align shadow on window resize
			$(window).resize(function()
			{
				try {
					divShadow.css({
						left: jthis.position().left + opt.left - blur,
						top: jthis.position().top + opt.top - blur
					});
				}
				catch(e){}
			});
			
			// Increment z-index counter
			dropShadowZindex += 2;

		});  //end each
		
		return this.pushStack(jShadows);
	};


	$.fn.redrawShadow = function()
	{
		// Remove existing shadows
		this.removeShadow();
		
		// Draw new shadows
		return this.each(function()
		{
			var shadowOptions = $.data(this, "shadowOptions");
			$(this).dropShadow(shadowOptions);
		});
	};


	$.fn.removeShadow = function()
	{
		return this.each(function()
		{
			var shadowId = $(this).shadowId();
			$("div#" + shadowId).remove();
		});
	};


	$.fn.shadowId = function()
	{
		return $.data(this[0], "shadowId");
	};


	$(function()  
	{
		// Suppress printing of shadows
		var noPrint = "<style type='text/css' media='print'>";
		noPrint += ".dropShadow{visibility:hidden;}</style>";
		$("head").append(noPrint);
	});

})(jQuery);

//---------------------------------------------------------------------------------------
//
//  Logger
// 
//---------------------------------------------------------------------------------------

function logger(message) {
    if (window[ 'loadFirebugConsole']) {
        window.loadFirebugConsole();
        console.log(message);
    }
}

jQuery.fn.logger = function(message) {
    logger(message);
    return this;
};

//---------------------------------------------------------------------------------------
//
//  Utility
// 
//---------------------------------------------------------------------------------------

function existsonpage(element) {
		 return $(element).length > 0;
}


//---------------------------------------------------------------------------------------
//
//  Switch image src for mouseover-effect
// 
//---------------------------------------------------------------------------------------

function showImage(id, imageURL){
  if(document.images){
    document.getElementById(id).src=imageURL;
  }
}

//---------------------------------------------------------------------------------------
//
//  External links should open in a new window
// 
//---------------------------------------------------------------------------------------

function eh_openInNewWindow(e) {
	e.preventDefault();
	window.open(this.href, '', '');
}

//---------------------------------------------------------------------------------------
//
// Collapse and expand articles
//
//---------------------------------------------------------------------------------------

function toggleArticle(id) {

	 var headingDiv = $('#heading' + id);
	 var articletextDiv = $('#text' + id);
	 var headingH2 = $('#link' + id);
	 var slideSpeed = 700;
	
	 if (articletextDiv.css("display") == 'none') {
		 headingDiv.parent().removeClass("collapsed"); /* Justerer class-attributtet på .article */
		 headingDiv.parent().addClass("expanded"); /* Justerer class-attributtet på .article */
		 headingH2.removeClass("collapsed");
		 headingH2.addClass("expanded");
		 articletextDiv.slideDown(slideSpeed);
	 } else {
		 headingDiv.parent().removeClass("expanded"); /* Justerer class-attributtet på .article */
		 headingDiv.parent().addClass("collapsed"); /* Justerer class-attributtet på .article */
		 articletextDiv.slideUp(slideSpeed, function() {
		 	headingH2.removeClass("expanded");
		 	headingH2.addClass("collapsed");
	 		});
	 }
} 

function collapseAllArticles() {

	var articles = $('#articles');
	
	if(articles){
		$(".articletext").hide();
		$(".articletext").parent().removeClass("expanded");
		$(".articletext").parent().addClass("collapsed");
		$(".articlelink").removeClass("expanded");
		$(".articlelink").addClass("collapsed");
	}
	
}





//---------------------------------------------------------------------------------------
//
// Display flash map. Depends on function in flashutils.js
//
//---------------------------------------------------------------------------------------

function displayFlash() {

	var flashdiv = $('#FlashDiv');
	
	//assume doDisplayFlash is defined
	if(existsonpage(flashdiv)){
		if(doDisplayFlash == 'true'){
		   /*display FlashDiv with the flash included by SWFObject above*/
			var flashdiv = document.getElementById("FlashDiv");
			if(flashdiv){
				flashdiv.style.display = "block";
			}	
					
			//assumes that variable "so" exists.
			so.write("FlashDiv");
			//the html page needs to have this function avail (flashutils.js)
			flashToFront(); 
		}
	}
	
}

//---------------------------------------------------------------------------------------
//
// Cookie plugin for jQuery
//
//---------------------------------------------------------------------------------------

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

//---------------------------------------------------------------------------------------
//
// Google analytics for web statistics. Depends on function in ga.js from google.
//
//---------------------------------------------------------------------------------------


function googleAnalytics(){
	try {
		var pageTracker = _gat._getTracker("UA-2627771-5");
		pageTracker._trackPageview();
	} catch(err) {}
	
}
    
  

//---------------------------------------------------------------------------------------
//
//  eh_initPage() is the starting point for executing Javascript on the page
// 
//---------------------------------------------------------------------------------------


function eh_initPage() {

	// Sjekk om siden har sin egen, lokale Javascript-fil med funksjonen localInit(). Funksjonen utføres hvis den finnes.
	//if (typeof(localInit) == "function") {
	//	localInit();
	//}

	
	// Alle artikler skjules per default for brukere med javascript
	collapseAllArticles();
	//ekspandere markert artikkel (lenket til direkte eller er eneste artikkel på siden)
	if (existsonpage(".skalEkspanderes")) {
 		toggleArticle($(".skalEkspanderes")[0].id);
 	}
	
	// Display flash-div
	displayFlash();

	// All links with this class should open in an external window
	$(".external").click(eh_openInNewWindow); 
	
	
	// Google analytics
	googleAnalytics();
	
	
}
//---------------------------------------------------------------------------------------
//
//  jQuery plugin, wait
// 
//---------------------------------------------------------------------------------------

(function($) {    
	$.fn.wait = function(time, callback) {
		var target = this;
		
		target.queue(function() {
			window.setTimeout( 
				function() {    
                                        target.queue(callback);
                                        target.dequeue();    
			       },time);
	      });
		return this;
	}
})(jQuery);

//---------------------------------------------------------------------------------------
//
//  eh_initPage() skal kalles når DOM er ferdig lastet
// 
//---------------------------------------------------------------------------------------

$(document).ready(eh_initPage);
