(function(jQuery){jQuery.each(['backgroundColor','borderBottomColor','borderLeftColor','borderRightColor','borderTopColor','color','outlineColor'],function(i,attr){jQuery.fx.step[attr]=function(fx){if(fx.state==0){fx.start=getColor(fx.elem,attr);fx.end=getRGB(fx.end)}fx.elem.style[attr]="rgb("+[Math.max(Math.min(parseInt((fx.pos*(fx.end[0]-fx.start[0]))+fx.start[0]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[1]-fx.start[1]))+fx.start[1]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[2]-fx.start[2]))+fx.start[2]),255),0)].join(",")+")"}});function getRGB(color){var result;if(color&&color.constructor==Array&&color.length==3)return color;if(result=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))return[parseInt(result[1]),parseInt(result[2]),parseInt(result[3])];if(result=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))return[parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55];if(result=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))return[parseInt(result[1],16),parseInt(result[2],16),parseInt(result[3],16)];if(result=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))return[parseInt(result[1]+result[1],16),parseInt(result[2]+result[2],16),parseInt(result[3]+result[3],16)];return colors[jQuery.trim(color).toLowerCase()]}function getColor(elem,attr){var color;do{color=jQuery.curCSS(elem,attr);if(color!=''&&color!='transparent'||jQuery.nodeName(elem,"body"))break;attr="backgroundColor"}while(elem=elem.parentNode);return getRGB(color)};var colors={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery);
//$.fn.equalHeights=function(px){$(this).each(function(){var currentTallest=0;$(this).children().each(function(i){if($(this).height()>currentTallest){currentTallest=$(this).height()}});if($.browser.msie&&$.browser.version==6.0){$(this).children().css({'height':currentTallest})}$(this).children().css({'min-height':currentTallest})});return this};

$(function() {
    //	$('#f_cols').equalHeights();
		$("#javaScriptOnly").show();
		$("#search").show();

    /*
    RadDock
    */
    // Legg på skjul-knapp på hver boks
    /*$('#RadDockContent .rdCommands').append('<a href="#" class="rdClose btn" title="Lukk boksen"><span>X</span></a>')*/

    /* 
    Meny for å styre "lytt til tekst"-funksjon
	
	// Skjul menyen
    $('#listen_controls').hide();
	
	// Legg på skjul knapp på lyttekontrollene
    $('#listen_controls').append('<li class="close_controls"><a href="#">X</a></li>');
	
	$('li.close_controls').click(function(){
    $('#listen_controls').slideUp();
    return false;
    });
	
	// Ved klikk på lytteknappen, åpne menyen
    $('a.listen_text').click(function(){
    $('#listen_controls').slideToggle();
    return false;
    });
    */
    if ($('#newsSlider').length > 0) {
        alert('asd');
        $('#newsSlider').loopedSlider({
            containerClick: false,
            restart: 3000,
            autoStart: 10000
        });
    }
    $('#breadcrumbs li a:last').animate({ color: '#BE0000' }, 1000).animate({ color: '#333' }, 1000).animate({ color: '#BE0000' }, 1000).animate({ color: '#333' }, 1000);
    // Call stylesheet init so that all stylesheet changing functions 
    // will work.
    $.stylesheetInit();

    // When one of the styleswitch links is clicked then switch the stylesheet to
    // the one matching the value of that links rel attribute.
    $('.styleswitch').bind(
			'click',
			function(e) {
			    $.stylesheetSwitch(this.getAttribute('rel'));
			    return false;
			}
		);
    $('li.pag_newsHeading1 a').html($('#frontNewsHeading1').html());
    $('li.pag_newsHeading2 a').html($('#frontNewsHeading2').html());
    $('li.pag_newsHeading3 a').html($('#frontNewsHeading3').html());
    /*
    function getNewsHeading1() {
    var tekst1 = $('#frontNewsHeading1').html();
    return tekst1;
    }

    function getNewsHeading2() {
    var tekst2 = $('#frontNewsHeading2').html();
    return tekst2;
    }

    function getNewsHeading3() {
    var tekst3 = $('#frontNewsHeading3').html();
    return tekst3;
    }*/

    $('input.SearchButton').click(function() {

        window.location = 'Sok/?q=' + $('input.quickSearchField').val();
        return false;
    });
});

/**
* Stylesheet toggle variation on styleswitch stylesheet switcher.
* Built on jQuery.
* Under an CC Attribution, Share Alike License.
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/

(function($)
	{
		// Local vars for toggle
		var availableStylesheets = [];
		var activeStylesheetIndex = 0;
		
		// To loop through available stylesheets
		$.stylesheetToggle = function()
		{
			activeStylesheetIndex ++;
			activeStylesheetIndex %= availableStylesheets.length;
			$.stylesheetSwitch(availableStylesheets[activeStylesheetIndex]);
		};
		
		// To switch to a specific named stylesheet
		$.stylesheetSwitch = function(styleName)
		{
			$('link[@rel*=style][title]').each(
				function(i) 
				{
					this.disabled = true;
					if (this.getAttribute('title') == styleName) {
						this.disabled = false;
						activeStylesheetIndex = i;
					}
				}
			);
			createCookie('style', styleName, 365);
		};
		
		// To initialise the stylesheet with it's 
		$.stylesheetInit = function()
		{
			$('link[@rel*=style][title]').each(
				function(i) 
				{
					availableStylesheets.push(this.getAttribute('title'));
				}
			);
			var c = readCookie('style');
			if (c) {
				$.stylesheetSwitch(c);
			}
		};
	}
)(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
   function printPage() 
   {
        var da = (document.all) ? 1 : 0;
        var pr = (window.print) ? 1 : 0;

        if (!pr)
            return;

        var printArea = document.getElementById("MainBodyArea");

        if (printArea == null && da)
            printArea = document.all.MainBodyArea;

        if (printArea) {
            var sStart = "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"/templates/public/styles/print.css\"></head><body onload=\"javascript:window.print();\">";
            sStop = "</body></html>";

            var w = window.open('', 'printWin', 'width=650,height=440,scrollbars=yes');
            wdoc = w.document;
            wdoc.open();
            wdoc.write(sStart + printArea.innerHTML);
            wdoc.writeln(sStop);
            wdoc.close();
        }
    }
    


function SelectImageLink(e, textboxid) {
    var url = e; var linkAttributes = new Object(); var dialogArguments = linkAttributes; var features = { width: 600, height: 412 }; var callbackArguments = new Object();
    callbackArguments.inputFieldId = textboxid; /* opens the filemanagerbrowser dialog */
    EPi.CreateDialog(url, OnFileDialogClosed, callbackArguments, dialogArguments, features);
}
function OnFileDialogClosed(returnValue, callbackArguments) {
    if (returnValue != undefined && returnValue != 0) {
        var inputBox = document.getElementById(callbackArguments.inputFieldId);
        inputBox.value = returnValue;
    }
}
