/*
 * JSizes - JQuery plugin v0.32
 *
 * Licensed under the revised BSD License.
 * Copyright 2008, Bram Stein
 * All rights reserved.
 */
(function(B){var A=function(C){return parseInt(C,10)||0};B.each(["min","max"],function(D,C){B.fn[C+"Size"]=function(G){var F,E;if(G){if(G.width){this.css(C+"-width",G.width)}if(G.height){this.css(C+"-height",G.height)}return this}else{F=this.css(C+"-width");E=this.css(C+"-height");return{width:(C==="max"&&(F===undefined||F==="none"||A(F)===-1)&&Number.MAX_VALUE)||A(F),height:(C==="max"&&(E===undefined||E==="none"||A(E)===-1)&&Number.MAX_VALUE)||A(E)}}}});B.fn.isVisible=function(){return this.css("visibility")!=="hidden"&&this.css("display")!=="none"};B.each(["border","margin","padding"],function(D,C){B.fn[C]=function(E){if(E){if(E.top){this.css(C+"-top"+(C==="border"?"-width":""),E.top)}if(E.bottom){this.css(C+"-bottom"+(C==="border"?"-width":""),E.bottom)}if(E.left){this.css(C+"-left"+(C==="border"?"-width":""),E.left)}if(E.right){this.css(C+"-right"+(C==="border"?"-width":""),E.right)}return this}else{return{top:A(this.css(C+"-top"+(C==="border"?"-width":""))),bottom:A(this.css(C+"-bottom"+(C==="border"?"-width":""))),left:A(this.css(C+"-left"+(C==="border"?"-width":""))),right:A(this.css(C+"-right"+(C==="border"?"-width":"")))}}}})})(jQuery);

/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {

$.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }
    
  return this.each(function () {
    // get jQuery version of 'this'
    var $input = $(this),
    
    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title
      
      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

})(jQuery);

jQuery(document).ready(function(){
	if($('.sidebar').length > 0){
		$('.sidebar').accordion({ 
			icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus'},
			header: 'h3',
			active: 0,
			autoHeight: false
		});
	}

	/* 
		Funksjon som gjoer at hover paa elementene lista under barn og ungdom skifter bildet
	*/
	$('.img_no_desc li a').hover(function() {
		$(this).parent().siblings().removeClass('active');
		$(this).parent().siblings().children('img').css({'z-index' : '100'});
		$(this).parent().addClass('active');
		$(this).prev().css({'z-index' : '101'});
	});
	
	/*
		Dropdown meny, hovednav
	*/
	$('#nav').superfish({
		delay: 600
	}); 
	
	/*
		Tabs, forside
	*/
	if($('#tabs').length > 0) {
		$('#tabs').tabs({ fx: { opacity: 'toggle', duration: 100 } });
		$('#tabs ul li').css('height', '55px');
		
		$('div.overlay').css({'position':'absolute', 'bottom':'0'});
	
		
		$('#tabs_content div img').each(function(){
			var parent_id = $(this).parent().attr('id');
			$(this).attr('id', parent_id + '-img');
			$('div.img_overlay div.front_images').append(this);
			$(this).hide();
		});
		
		var active_panel = "tabs-1";
		$('#' + active_panel + '-img').show();
		$('#tabs').bind('tabsshow', function(event, ui) {
			$('#' + active_panel + '-img').hide();
			var prev_panel = active_panel;
			active_panel = ui.panel.id;
		  	var active_img = $('#' + active_panel + '-img');
			$('div.img_overlay div.front_images').append(active_img);
			if($('#' + active_panel + '-img').size()){
				$('#' + active_panel + '-img').show();
			} else {
				$('#' + prev_panel + '-img').show();
				active_panel = prev_panel;
			}
			
		});
		
		$('#tabs_content').equalHeights();
	}
	
	/*
		Gir alle kolonnene i footer lik hoeyde
	*/
	$('#footer div.row').equalHeights();
	
	
	
	/* Sett bredde paa bilde-div i artikler */
	
	$('div.article').children('div.image', 'div.image_right').each(function(i){
		var img_width = $(this).children('img').width();
		$(this).css('width', img_width)
	});
	
	$('div.article').children('div.image_right').each(function(i){
		var img_width = $(this).children('img').width();
		$(this).css('width', img_width)
	});

	/* Fjern tekst i soekefelt ved klikk */
	$('input.search_field').hint();
	
		// style switcher
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
	
  	setTabMargin();
  	
  	$('#top_nav ul li.fontsize a.default').click(function(){
  		setActiveStyleSheet('default');
  		setTabMargin();
  	});
  	
	$('#top_nav ul li.fontsize a.big').click(function(){
  		setActiveStyleSheet('size-big');
  		setTabMargin();
  	});
  	
  	$('#top_nav ul li.fontsize a.bigger').click(function(){
  		setActiveStyleSheet('size-bigger');
  		setTabMargin();
 	});
 	
 	/*  Gi kolonnene paa forsiden samme hoeyde */
	$('#content_container').equalHeights();
  
  /* Bildegalleri */
  if($('#PicThumbs').length > 0) {
	
	
	$('#PicThumbs li').each(function(){
		var img = $(this).find('a > img');
		var maxH = img.attr('height');
		var curW = img.width();
		
		$(this).css({
			'height': maxH,
			'width': curW 
		}); 
	});
	jQuery('#PicThumbs').jcarousel({
		scroll: 1
	});
  }
  
  
  
  /* Bildegalleri slutt */
  
  if($('table.CalendarTitleStyle').length > 0){
  	var ordforerCalendarTitle = $('table.CalendarTitleStyle');

  	ordforerCalendarTitle.find('tbody > tr > td').each(function(i){
  		if(i==0)
  			$(this).addClass('calnavleft');
  		else if(i==1)
  			$(this).addClass('caltitle');
  		else if(i==2)
  			$(this).addClass('calnavright');
  	});
  }
  
  // Move article images up on hover
	$("div#filmstrip ul li a").mouseover(function(){
			
	      	$(this).find('span.container').stop().animate({ 
			     bottom: "0"
			}, 200 );
	    }).mouseout(function(){
	      	$(this).find('span.container').stop().animate({ 
			     bottom: "-44px"
			 }, 200 );
	});

  
});

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

function setTabMargin(){
	var tabheight = 0;
	$('#tabs ul li a').each(function(){
		if($(this).height() > tabheight) 
			tabheight = $(this).height();
	});
	if (parent == window) {
		$('div#tabs_content').css('margin-top', tabheight-55);
	}
}
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;
    }
}