﻿//open/close productNav
$(document).ready(function() {
$("#siteNavProducts").css("display", "none");
$("#siteNav li.products").append("<a href='' class='siteNavMore'>Visa produktlista</a>");
    $("a.siteNavMore").click(function() {
    $("#siteNavProducts").toggle(); return false
    });
    //$("body").click(function() {
    //$("#siteNavProducts").fadeOut('fast');
    //});
    $("#siteNav ul li.products").hover(function() {
          //$("#siteNavProducts").css();
      },
      function() {
      $("#siteNavProducts").fadeOut('fast');
  });
});

$(function() {
    $(".print").click(function() {
        $('.printArea').jqprint(); 

    });
});

$(function() {
	$('#cycle').cycle({
		fx: 'fade',
		speed: 2000,
		timeout:  8000 
	});   
});

$(function() {
    $("h3.productsHeading.btn").click(function() {
    $(this).next("ul").slideToggle("fast");
    $(this).toggleClass("active");
    });
});

$(function() {
    $('a.lightbox').lightBox(); // Select all links with lightbox class
});

//$(function() {
  //  $(".productDisplay ul img").css("cursor", "pointer");
 //   $(".productDisplay ul li").click(function() {
  //  window.location = $(this).find("a").attr("href"); return false;  
 //   });
//});

var swap_text_boxes = [];

function init_swap_text_boxes() {
    //Store the default value for each box
    $('input[type=text][value].swaptextbox').each(function() {
        swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
    });
    //Add focus and blur events to set or clear the value
    $('input[type=text][value].swaptextbox').bind('focus', function() {
        if ($(this).val() == swap_text_boxes[$(this).attr('id')]) {
            $(this).val('');
        }
    });
    $('input[type=text][value].swaptextbox').bind('blur', function() {
        if ($(this).val() == '') {
            $(this).val(swap_text_boxes[$(this).attr('id')]);
        }
    });
}
$(document).ready(function() { init_swap_text_boxes(); });


//equal heights, author anderas lagerkvist (andreaslagerkvist.com)
jQuery.fn.equalHeight = function () {
    var height        = 0;
    var maxHeight    = 0;

    // Store the tallest element's height
    this.each(function () {
        height        = jQuery(this).outerHeight();
        maxHeight    = (height > maxHeight) ? height : maxHeight;
    });

    // Set element's min-height to tallest element's height
    return this.each(function () {
        var t            = jQuery(this);
        var minHeight    = maxHeight - (t.outerHeight() - t.height());
        var property    = jQuery.browser.msie && jQuery.browser.version < 7 ? 'height' : 'min-height';

        t.css(property, minHeight + 'px');
    });
};

$(document).ready(function() {
    $('#products #content > div').equalHeight();
    $('#content.twoColMainLeft > div, #content.twoColMainRight > div, #content.threeCol > div').equalHeight();
});


/**
* @author Karl Swedberg
*/

$(document).ready(function() {
    $('div#footer a[href*=#]').each(function() {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
    && location.hostname == this.hostname
    && this.hash.replace(/#/, '')) {
            var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) + ']');
            var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
            if ($target) {
                var targetOffset = $target.offset().top;
                $(this).click(function() {
                    $('html, body').animate({ scrollTop: targetOffset }, 400);
                    return false;
                });
            }
        }
    });
});

//theme changer - this will be removed from the final js file
$(document).ready(function() {

    $(".two1").click(function() {
        $("div#content").removeClass().addClass("twoColMainLeft");
        $("div#content a").css("font-weight", "normal");
        $("a.two1").css("font-weight", "bold");
    });
    $(".two2").click(function() {
        $("div#content").removeClass().addClass("twoColMainRight");
        $("div#content a").css("font-weight", "normal");
        $("a.two2").css("font-weight", "bold");
    });
    $(".three").click(function() {
        $("div#content").removeClass().addClass("threeCol");
        $("div#content a").css("font-weight", "normal");
        $("a.three").css("font-weight", "bold");
    });

});