(function($){$.fn.expandAll=function(options){var defaults={state:'hidden',initTxt:'show',expTxt:'[Utvide alle]',cllpsTxt:'[Slå alle sammen]',oneSwitch:true,ref:'.expand',switchPosition:'before',scroll:false,showMethod:'slideDown',hideMethod:'slideUp',speed:600,cllpsEl:'.collapse',trigger:'.expand',localLinks:null,parent:false,child:false,cllpsLength:null};var o=$.extend({},defaults,options);return this.each(function(index){var $$=$(this),$referent,$sw,$cllps,$tr,container,toggleTxt,toggleClass;(o.switchPosition=='before')?($.fn.findSibling=$.fn.prev,$.fn.insrt=$.fn.before):($.fn.findSibling=$.fn.next,$.fn.insrt=$.fn.after);if(this.id.length){container='#'+ this.id;}else if(this.className.length){container=this.tagName.toLowerCase()+'.'+ this.className.split(' ').join('.');}else{container=this.tagName.toLowerCase();}
if(o.ref&&$$.find(o.ref).length){(o.switchPosition=='before')?$referent=$$.find("'"+ o.ref+":first'"):$referent=$$.find("'"+ o.ref+":last'");}else{return;}
if(o.cllpsLength&&$$.closest(container).find(o.cllpsEl).text().length<o.cllpsLength){$$.closest(container).find(o.cllpsEl).addClass('dont_touch');return;}
(o.initTxt=='show')?(toggleTxt=o.expTxt,toggleClass=''):(toggleTxt=o.cllpsTxt,toggleClass='open');if(o.state=='hidden'){$$.find(o.cllpsEl+':not(.shown, .dont_touch)').hide().findSibling().find('> a.open').removeClass('open');}
(o.oneSwitch)?($referent.insrt('<p class="switch"><a href="#" class="'+ toggleClass+'">'+ toggleTxt+'</a></p>')):($referent.insrt('<p class="switch"><a href="#" class="">'+ o.expTxt+'</a>&nbsp;|&nbsp;<a href="#" class="open">'+ o.cllpsTxt+'</a></p>'));$sw=$referent.findSibling('p').find('a');$cllps=$$.closest(container).find(o.cllpsEl).not('.dont_touch');if(o.trigger){$tr=$$.closest(container).find(o.trigger+' > a');}
if(o.child){$$.find(o.cllpsEl+'.shown').show().findSibling().find('> a').addClass('open').text(o.cllpsTxt);window.$vrbls={kt1:o.expTxt,kt2:o.cllpsTxt};}
var scrollElem;(typeof scrollableElement=='function')?(scrollElem=scrollableElement('html','body')):(scrollElem='html, body');$sw.click(function(){var $switch=$(this),$c=$switch.closest(container).find(o.cllpsEl+':first'),cOffset=$c.offset().top;if(o.parent){var kidTxt1=$vrbls.kt1,kidTxt2=$vrbls.kt2,kidTxt=($switch.text()==o.expTxt)?kidTxt2:kidTxt1;$switch.parent().nextAll().children('p.switch').find('a').text(kidTxt);}
if($switch.text()==o.expTxt){if(o.oneSwitch){$switch.text(o.cllpsTxt).attr('class','open');}
$tr.addClass('open');$cllps[o.showMethod](o.speed);}else{if(o.oneSwitch){$switch.text(o.expTxt).attr('class','');}
$tr.removeClass('open');$cllps[o.hideMethod](o.speed);if(o.scroll&&cOffset<$(window).scrollTop()){$(scrollElem).animate({scrollTop:cOffset},600);}}
return false;});if(o.localLinks){var localLink=$(container).find(o.localLinks);if(localLink.length){$(localLink).click(function(){var $target=$(this.hash);$target=$target.length&&$target||$('[name='+ this.hash.slice(1)+']');if($target.length){var tOffset=$target.offset().top;$(scrollElem).animate({scrollTop:tOffset},600);return false;}});}}
function scrollableElement(els){for(var i=0,argLength=arguments.length;i<argLength;i++){var el=arguments[i],$scrollElement=$(el);if($scrollElement.scrollTop()>0){return el;}else{$scrollElement.scrollTop(1);var isScrollable=$scrollElement.scrollTop()>0;$scrollElement.scrollTop(0);if(isScrollable){return el;}}};return[];};});};$.fn.toggler=function(options){var defaults={cllpsEl:'div.collapse',method:'slideToggle',speed:'slow',container:'',initShow:'.shown'};var o=$.extend({},defaults,options);var $this=$(this);$this.wrapInner('<a style="display:table-cell" href="#" title="Brett ut, les mer, lukk igjen" />');if(o.initShow){$(o.initShow).addClass('shown');}
$this.next(o.cllpsEl+':not(.shown)').hide();return this.each(function(){var container;(o.container)?container=o.container:container='html';if($this.next('div.shown').length){$this.closest(container).find('.shown').show().prev().find('a').addClass('open');}
$(this).click(function(){$(this).find('a').toggleClass('open').end().next(o.cllpsEl)[o.method](o.speed);return false;});});};$.fn.toggleHeight=function(speed,easing,callback){return this.animate({height:'toggle'},speed,easing,callback);};$.fn.fadeToggle=function(speed,easing,callback){return this.animate({opacity:'toggle'},speed,easing,callback);};$.fn.slideFadeToggle=function(speed,easing,callback){return this.animate({opacity:'toggle',height:'toggle'},speed,easing,callback);};})(jQuery);
