﻿$(function () {
    $(".accordionContent").hide();

    $(".helperText").text("");
    $(".accordionHeader").find(".helperText").text("Läs mer");

    $(".accordionHeader").click(function () {
        $(this).siblings(".accordionContent").slideToggle();
        $("html").find(".accordionContent").not($(this).siblings(".accordionContent")).slideUp();
        $("html").find(".accordionHeader").not($(this)).removeClass("current");
        $(this).addClass("current");
        return false;
    });

    $('#imageSlider')
    .cycle({
        fx: 'fade',
        speed: 1000,
        timeout: 5000,
        pager: '#imageSliderNav'
    });

    $("#content").find("img").wrap(function () {
        if ($(this).width() == 500 && $(this).height() == 320 && !($(this).parent().hasClass("imageSliderImage"))) {
            $(this).wrap('<div id="slider" />').wrap('<div class="imageSliderImage" />');
        }
    });

    //------------------------------------------------------background selector script -----------------------------------------
    var selectedBackground = "";

    //Run image selector on page load 
    ScaleWindow();

    $(window).resize(function () {
        ScaleWindow();
    });

    function ScaleWindow() {
        if ($(window).width() > 1920) { currentBackground = "/images/background_2560.jpg"; }
        else if ($(window).width() <= 1920 && $(window).width() > 1280) { currentBackground = "/images/background_1920.jpg"; }
        else if ($(window).width() <= 1280 && $(window).width() > 1024) { currentBackground = "/images/background_1280.jpg"; }
        else if ($(window).width() <= 1024 && $(window).width() > 800) { currentBackground = "/images/background_1024.jpg"; }
        else { selectedBackground = ""; }

        if (currentBackground != selectedBackground) {
            selectedBackground = currentBackground;
            $("body").css({ 'background-image': "url(" + selectedBackground + ")" });
        }
    }
});











