/*
 * Copyright (C) 1999-2009 Jive Software. All rights reserved.
 *
 * This software is the proprietary information of Jive Software. Use is subject to license terms.
 */

/*
* $ lightbox_me
* By: Buck Wilson
* Version : 2.2 changed by Nonea 2010-09-08
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


(function($) {

    $.fn.lightbox_me = function(options) {

        return this.each(function() {

            var
                opts = $.extend({}, $.fn.lightbox_me.defaults, options),
                $overlay = $('div.' + opts.classPrefix + '_overlay'),
                $self = $(this),
                $iframe = $('iframe#lb_iframe'),
                ie6 = ($.browser.msie && $.browser.version < 7);
            
            if ($overlay.length > 0) {
                $overlay[0].removeModal(); // if the overlay exists, then a modal probably exists. Ditch it!
            } else {
                $overlay =  $('<div class="' + opts.classPrefix + '_overlay" style="display:none;"/>'); // otherwise just create an all new overlay. 
            }

            $iframe = ($iframe.length > 0) ? $iframe : $iframe = $('<iframe id="lb_iframe" style="z-index: ' + (opts.zIndex + 1) + '; display: none; border: none; margin: 0; padding: 0; position: absolute; width: 100%; height: 100%; top: 0; left: 0;"/>');

            /*----------------------------------------------------
               DOM Building
            ---------------------------------------------------- */
            if (ie6) {
                var src = /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank';
                $iframe.attr('src', src);
                $('body').append($iframe);
            } // iframe shim for ie6, to hide select elements
            $('body').append($self).append($overlay);

            /*----------------------------------------------------
               CSS stuffs
            ---------------------------------------------------- */

            // set css of the modal'd window

            setSelfPosition();
            // Nonea: moved line into function above
            //$self.css({left: '50%', marginLeft: ($self.outerWidth() / 2) * -1,  zIndex: (opts.zIndex + 3) });

            // set css of the overlay

            setOverlayHeight(); // pulled this into a function because it is called on window resize.
            $overlay.css({ position: 'absolute', width: '100%', top: 0, left: 0, right: 0, bottom: 0, zIndex: (opts.zIndex + 2) })
                    .css(opts.overlayCSS);

            /*----------------------------------------------------
               Animate it in.
            ---------------------------------------------------- */

            if ($overlay.is(":hidden")) {
                $overlay.fadeIn(opts.overlaySpeed, function() {
                    $self[opts.appearEffect](opts.lightboxSpeed, function() { setOverlayHeight(); opts.onLoad()});
                });
            } else {
                $self[opts.appearEffect](opts.lightboxSpeed, function() { setOverlayHeight(); opts.onLoad()});
            }

            /*----------------------------------------------------
               Bind Events
            ---------------------------------------------------- */

            $(window).resize(setOverlayHeight)
                     .resize(setSelfPosition)
                     .scroll(setSelfPosition)
                     .keydown(observeEscapePress);
                     
            $self.find(opts.closeSelector).click(function() { removeModal(true); return false; });
            $overlay.click(function() { if(opts.closeClick){ removeModal(true); return false;} });

            
            $self.bind('close', function() { removeModal(true) });
            $self.bind('resize', setSelfPosition);
            $overlay[0].removeModal = removeModal;

            /*----------------------------------------------------------------------------------------------------------------------------------------
              ---------------------------------------------------------------------------------------------------------------------------------------- */

            /*----------------------------------------------------
               Private Functions
            ---------------------------------------------------- */


            function removeModal(removeO) {
                // fades & removes modal, then unbinds events
                $self[opts.disappearEffect](opts.lightboxDisappearSpeed, function() {
                    
                    if (removeO) {
                      removeOverlay();  
                    } 
                    
                    opts.destroyOnClose ? $self.remove() : $self.hide()
                    
                    
                    $self.find(opts.closeSelector).unbind('click');
                    $self.unbind('close');
                    $self.unbind('resize');
                    $(window).unbind('scroll', setSelfPosition);
                    $(window).unbind('resize', setSelfPosition);
                    
                    
                });
            }
            
            
            function removeOverlay() {
                // fades & removes overlay, then unbinds events
                $overlay.fadeOut(opts.overlayDisappearSpeed, function() {
                    $(window).unbind('resize', setOverlayHeight);

                    $overlay.remove();
                    $overlay.unbind('click');
                    
                    
                    opts.onClose();

                })
            }
            


            /* Function to bind to the window to observe the escape key press */
            function observeEscapePress(e) {
                if((e.keyCode == 27 || (e.DOM_VK_ESCAPE == 27 && e.which==0)) && opts.closeEsc) removeModal(true);
            }

            /* Set the height of the overlay
                    : if the document height is taller than the window, then set the overlay height to the document height.
                    : otherwise, just set overlay height: 100%
            */
            function setOverlayHeight() {
                if ($(window).height() < $(document).height()) {
                    $overlay.css({height: $(document).height() + 'px'});
                } else {
                    $overlay.css({height: '100%'});
                    if (ie6) {$('html,body').css('height','100%'); } // ie6 hack for height: 100%; TODO: handle this in IE7
                }
            }

            /* Set the position of the modal'd window ($self)
                    : if $self is taller than the window, then make it absolutely positioned
                    : otherwise fixed
            */
            function setSelfPosition() {
                var s = $self[0].style;

                if (($self.height() + 80  >= $(window).height()) && ($self.css('position') != 'absolute' || ie6)) {
                    var topOffset = $(document).scrollTop() + 40;
                    $self.css({position: 'absolute', top: topOffset + 'px', marginTop: 0})
                    if (ie6) {
                        s.removeExpression('top');
                    }
                } else if ($self.height()+ 80  < $(window).height()) {
                    if (ie6) {
                        s.position = 'absolute';
                        if (opts.centered) {
                            s.setExpression('top', '(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"')
                            s.marginTop = 0;
                        } else {
                            var top = (opts.modalCSS && opts.modalCSS.top) ? parseInt(opts.modalCSS.top) : 0;
                            s.setExpression('top', '((blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"')
                        }
                    } else {
                        if (opts.centered) {
                            $self.css({ position: 'fixed', top: '50%', marginTop: ($self.outerHeight() / 2) * -1})
                        } else {
                            $self.css({ position: 'fixed'}).css(opts.modalCSS);
                        }
                    }
                }
                // Nonea: moved this line into the function to account for dynamic width
                $self.css({left: '50%', marginLeft: ($self.outerWidth() / 2) * -1,  zIndex: (opts.zIndex + 3) });
            }
        });
    };


    $.fn.lightbox_me.defaults = {

        // animation when appears
        appearEffect: "fadeIn",
        overlaySpeed: 300,
        lightboxSpeed: "fast",
        
        // animation when dissapears
        disappearEffect: "fadeOut",
        overlayDisappearSpeed: 300,
        lightboxDisappearSpeed: "fast",

        // close
        closeSelector: ".close",
        closeClick: true,
        closeEsc: true,

        // behavior
        destroyOnClose: false,

        // callbacks
        onLoad: function() {},
        onClose: function() {},

        // style
        classPrefix: 'lb',
        zIndex: 999,
        centered: false,
        modalCSS: {top: '40px'},
        overlayCSS: {background: 'black', opacity: .6}
    }


})(jQuery);;
/*
 * jQuery corner plugin
 *
 * version 1.7 (1/26/2007)
 * Plus modifications by Bennett McElwee - http://www.thunderguy.com/semicolon/2007/07/19/optimised-jquery-corners-plugin/
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

/**
 * The corner() method provides a simple way of styling DOM elements.  
 *
 * corner() takes a single string argument:  $().corner("effect corners width")
 *
 *   effect:  The name of the effect to apply, such as round or bevel. 
 *            If you don't specify an effect, rounding is used.
 *
 *   corners: The corners can be one or more of top, bottom, tr, tl, br, or bl. 
 *            By default, all four corners are adorned. 
 *
 *   width:   The width specifies the width of the effect; in the case of rounded corners this 
 *            will be the radius of the width. 
 *            Specify this value using the px suffix such as 10px, and yes it must be pixels.
 *
 * For more details see: http://methvin.com/jquery/jq-corner.html
 * For a full demo see:  http://malsup.com/jquery/corner/
 *
 *
 * @example $('.adorn').corner();
 * @desc Create round, 10px corners 
 *
 * @example $('.adorn').corner("25px");
 * @desc Create round, 25px corners 
 *
 * @example $('.adorn').corner("notch bottom");
 * @desc Create notched, 10px corners on bottom only
 *
 * @example $('.adorn').corner("tr dog 25px");
 * @desc Create dogeared, 25px corner on the top-right corner only
 *
 * @example $('.adorn').corner("round 8px").parent().css('padding', '4px').corner("round 10px");
 * @desc Create a rounded border effect by styling both the element and its parent
 * 
 * @name corner
 * @type jQuery
 * @param String options Options which control the corner style
 * @cat Plugins/Corner
 * @return jQuery
 * @author Dave Methvin (dave.methvin@gmail.com)
 * @author Mike Alsup (malsup@gmail.com)
 */
jQuery.fn.corner = function(o) {
    function hex2(s) {
        var s = parseInt(s).toString(16);
        return ( s.length < 2 ) ? '0'+s : s;
    };
    function gpc(node) {
        for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode  ) {
            var v = jQuery.css(node,'backgroundColor');
            if ( v.indexOf('rgb') >= 0 ) { 
                rgb = v.match(/\d+/g); 
                return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
            }
            if ( v && v != 'transparent' )
                return v;
        }
        return '#ffffff';
    };
    function getW(i) {
        switch(fx) {
        case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
        case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
        case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
        case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
        case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
        case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
        case 'curl':   return Math.round(width*(Math.atan(i)));
        case 'tear':   return Math.round(width*(Math.cos(i)));
        case 'wicked': return Math.round(width*(Math.tan(i)));
        case 'long':   return Math.round(width*(Math.sqrt(i)));
        case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
        case 'dog':    return (i&1) ? (i+1) : width;
        case 'dog2':   return (i&2) ? (i+1) : width;
        case 'dog3':   return (i&3) ? (i+1) : width;
        case 'fray':   return (i%2)*width;
        case 'notch':  return width; 
        case 'bevel':  return i+1;
        }
    };
    o = (o||"").toLowerCase();
    var keep = /keep/.test(o);                       // keep borders?
    var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);  // corner color
    var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
    var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
    var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
    var fx = ((o.match(re)||['round'])[0]);
    var edges = { T:0, B:1 };
    var opts = {
        TL:  /top|tl/.test(o),       TR:  /top|tr/.test(o),
        BL:  /bottom|bl/.test(o),    BR:  /bottom|br/.test(o)
    };
    if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
        opts = { TL:1, TR:1, BL:1, BR:1 };
    var strip = document.createElement('div');
    strip.style.overflow = 'hidden';
    strip.style.height = '1px';
    strip.style.backgroundColor = sc || 'transparent';
    strip.style.borderStyle = 'solid';
    return this.each(function(index){
        var pad = {
            T: parseInt(jQuery.css(this,'paddingTop'))||0,     R: parseInt(jQuery.css(this,'paddingRight'))||0,
            B: parseInt(jQuery.css(this,'paddingBottom'))||0,  L: parseInt(jQuery.css(this,'paddingLeft'))||0
        };

        if (jQuery.browser.msie) this.style.zoom = 1; // force 'hasLayout' in IE
        if (!keep) this.style.border = 'none';
        strip.style.borderColor = cc || gpc(this.parentNode);
        var cssHeight = jQuery.curCSS(this, 'height');

        for (var j in edges) {
            var bot = edges[j];
            strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
            var d = document.createElement('div');
            var ds = d.style;

            bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

            if (bot && cssHeight != 'auto') {
                if (jQuery.css(this,'position') == 'static')
                    this.style.position = 'relative';
                ds.position = 'absolute';
                ds.bottom = ds.left = ds.padding = ds.margin = '0';
                if (jQuery.browser.msie)
                    ds.setExpression('width', 'this.parentNode.offsetWidth');
                else
                    ds.width = '100%';
            }
            else {
                ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 
                                    (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';                
            }

            // Accumulate strips into a combined border; when border width changes, add the combined border and start accumulating again
            var combinedBorderWidth = '';
            var combinedHeight = 0;
            for (var i=0; i < width; i++) {
                var w = Math.max(0,getW(i));
                var newBorderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
                if (newBorderWidth != combinedBorderWidth) {
                    // New strip is different to previous, so add the combined strip (if any) and start accumulating again
                    if (0 < combinedHeight) {
                        var e = strip.cloneNode(false);
                        e.style.borderWidth = combinedBorderWidth;
                        e.style.height = combinedHeight+'px';
                        bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
                        combinedHeight = 0;
                    }
                    combinedBorderWidth = newBorderWidth;
                }
                ++combinedHeight;
            }
            // Add the last strip
            if (0 < combinedHeight) {
                var e = strip.cloneNode(false);
                e.style.borderWidth = combinedBorderWidth;
                e.style.height = combinedHeight+'px';
                bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
            }
        }
    });
};
;
// bigTarget.js - A jQuery Plugin
// Version 1.0.1
// Written by Leevi Graham - Technical Director - Newism Web Design & Development
// http://newism.com.au
// Notes: Tooltip code from fitted.js - http://www.trovster.com/lab/plugins/fitted/

// create closure
(function($) {
	// plugin definition
	$.fn.bigTarget = function(options) {
		// build main options before element iteration
		var opts = $.extend({}, $.fn.bigTarget.defaults, options);
		// iterate and reformat each matched element
		return this.each(function() {
			// set the anchor attributes
			var $a = $(this);
			var href = $a.attr('href');
			var title = $a.attr('title');
			// build element specific options
			var o = $.meta ? $.extend({}, opts, $a.data()) : opts;
			// update element styles
			$a.parents(o.clickZone)
				.hover(function() {
					$h = $(this);
					if(typeof o.title != 'undefined' && o.title === true && title != '') {
						$h.attr('title',title);
					}
					if (typeof(o.hoverClass)=='function') {
						o.hoverClass.call($h, 1);
						return;
					}
					$h.addClass(o.hoverClass);
				}, function() {
					$h = $(this);
					if(typeof o.title != 'undefined' && o.title === true && title != '') {
						$h.removeAttr('title');
					}
					if (typeof(o.hoverClass)=='function') {
						o.hoverClass.call($h, 0);
						return;
					}
					$h.removeClass(o.hoverClass);
				})
				// click
				.click(function(event) {
					if(getSelectedText() == "" && !event.isPropagationStopped())
					{
						if($a.is('[rel*=external]')){
							window.open(href);
							return false;
						}
						else {
							//$a.click(); $a.trigger('click');
							window.location = href;
						}
					}
					return true;
				});
		});
	};
	// private function for debugging
	function debug($obj) {
		if (window.console && window.console.log)
		window.console.log('bigTarget selection count: ' + $obj.size());
	};
	// get selected text
	function getSelectedText(){
		if(window.getSelection){
			return window.getSelection().toString();
		}
		else if(document.getSelection){
			return document.getSelection();
		}
		else if(document.selection){
			return document.selection.createRange().text;
		}
		return null;
	};
	// plugin defaults
	$.fn.bigTarget.defaults = {
		hoverClass	: 'hover',
		clickZone	: 'li:eq(0)',
		title		: true
	};
// end of closure
})(jQuery);;
jQuery(document).ready(function () {
  
  //active class for selected menu item
  jQuery('.menu-service li').click(function(){
    jQuery('.menu-service li').removeClass('active');
    jQuery(this).addClass('active');
  });
  
  jQuery('a').attr('hidefocus', 'hidefocus');
  
  // link puff frontpage
  
  jQuery('.view-id-puff_flex_collection .is-clickable a').bigTarget({
        //hoverClass: 'puff-hover',
        hoverClass: function (h) {
            if (h) {
                this.addClass('puff-hover');
                
            } else {
                this.removeClass('puff-hover');
            }
        },
        clickZone: 'div:eq(1)'
    });
    jQuery('.view-id-front_refobj_list a').bigTarget({
    //hoverClass: 'puff-hover',
    hoverClass: function (h) {
        if (h) {
            this.addClass('puff-hover');
            
        } else {
            this.removeClass('puff-hover');
        }
    },
    clickZone: 'div:eq(1)'
    });
    jQuery('.view-id-reference_objects .inner-object a').bigTarget({
      //hoverClass: 'puff-hover',
      hoverClass: function (h) {
          if (h) {
              this.addClass('puff-hover');
              
          } else {
              this.removeClass('puff-hover');
          }
      },
      clickZone: 'div:eq(0)'
      });
    
  
    
    // link puff product stage 2
    jQuery('.puff-282x252 .inner-puff .link a').bigTarget({
        //hoverClass: 'puff-hover',
        hoverClass: function (h) {
            if (h) {
                this.addClass('puff-hover');
                
            } else {
                this.removeClass('puff-hover');
            }
        },
        clickZone: 'div:eq(3)'
    });
    
    // link puff product stage 1
    jQuery('.puff-428x248 .inner-wrapper .sjohav-button a').bigTarget({
        //hoverClass: 'puff-hover',
        hoverClass: function (h) {
            if (h) {
                this.addClass('puff-hover');
                
            } else {
                this.removeClass('puff-hover');
            }
        },
        clickZone: 'div:eq(3)'
    });
    
    //hides all services except the first one
    jQuery('#service-area .node').addClass('element-hidden');
    jQuery('#service-area .views-row-first .node').removeClass('element-hidden');

    
    //-------------- simulates target=_blank behavior ----------------
    /*
    jQuery('.node-product .one-product-wrapper .product-details a').bind('click', function() {
      window.open(this.href); 
      return false;
    });
    
    jQuery('.views-field-field-homepage a').bind('click', function() {
      window.open(this.href); 
      return false;
    });
    
    jQuery('.homepage a').bind('click', function() {
        window.open(this.href); 
        return false;
    });
    */
  
  /*
  //Default text that hides when user has focus.
  //to apply effekt example: jQueryform['x']['#attributes']['class'] = array('defaultText'); jQueryform['x']['#attributes']['title'] = t('Ipsum');
  jQuery(".defaultText").focus(function(srcc)
    {
        if (jQuery(this).val() == jQuery(this)[0].title)
        {
          jQuery(this).removeClass("defaultTextActive");
          jQuery(this).val("");
        }
    });
    
    
  jQuery(".defaultText").blur(function()
    {
        if (jQuery(this).val() == "")
        {
          jQuery(this).addClass("defaultTextActive");
          jQuery(this).val(jQuery(this)[0].title);
        }
    });
    
  jQuery(".defaultText").blur();
  */  
  
});

/*
 * Image slider
 */
jQuery(function () {
    
    // set the first active page
    var currentpage = 0;
    // get the container with fixed size
    var container = jQuery('.view-id-refobj_img_list');
    // get all images
    var images = container.find('img');
	// get the holder with dynamic size
    var holder = jQuery('.view-id-refobj_img_list .views-field-field-refobj-images');
	
    holder.css({
        height: container.height()+'px',
        width: (container.width()*images.length)+'px',
        position: 'relative'
    });
    
    // store number of images
    var numImages = images.length;
    
    // init image text
    jQuery('.counter-text').text('Bild '+(currentpage+1)+' av '+numImages);
    
    // listen for clicks
    var leftarrow = jQuery('.arrow-left a');
    function go_prev ()
    {
        // special case at first item - go to last
        if (currentpage-1 < 0) {
            currentpage = numImages;
        }
        
        // increase counter
        currentpage--;
        // get total width
        var w = container.width();
        // goto current
        holder.animate({left:-currentpage*w});
        // set active text
        jQuery('.counter-text').text('Bild '+(currentpage+1)+' av '+numImages);
        
        // abort the default href fetch
        return false;
    }
    leftarrow.click(go_prev);
    
    var rightarrow = jQuery('.arrow-right a');
    function go_next ()
    {
        // special case at last item - go to first
        if (currentpage+1 == numImages) {
            currentpage = -1;
        }
        
        // increase counter
        currentpage++;
        // get total width
        var w = container.width();
        // goto current
        holder.animate({left:-currentpage*w});
        // set active text
        jQuery('.counter-text').text('Bild '+(currentpage+1)+' av '+numImages);
        
        // abort the default href fetch
        return false;
    }
    rightarrow.click(go_next);
    
});

function service_into_area(nid) {
  var select_node = ' #service-area #node-'+nid;
  jQuery('#service-area .node').addClass('element-hidden');
  jQuery(select_node).removeClass('element-hidden');
};;

