﻿function initialise() {
    openmenu();
    $("a[rel^=lightbox]").lightBox({
        imageLoading: '/Files/Templates/Designs/MostersButik/img/lightbox-ico-loading.gif',
        imageBtnClose: '/Files/Templates/Designs/MostersButik/img/lightbox-btn-close.gif',
        imageBtnPrev: '/Files/Templates/Designs/MostersButik/img/lightbox-btn-prev.gif',
        imageBtnNext: '/Files/Templates/Designs/MostersButik/img/lightbox-btn-next.gif'
    });
    $("select.changeUrl").change(function() {
        var url = "";
        $("select.changeUrl").each(function() {
            if ($(this).val() != 0) {
                url += $(this).val() + ".";
            }
        });
        changeUrlPar("variantid", url.substr(0, url.length - 1));
    });

    $(".changelink").click(function() {
        var required = 0;
        $(".error").remove();
        $("select.changeUrl").each(function() {
            if ($(this).val() == 0) {
                required = true;
                $(this).after("<span class='error'>Vælg venligst " + $(this).attr('class').split(' ').slice(-1) + "</span>");
            }
        });
        if (required) { return false; }
    });

    //change default value
    var url = "";
    $("select.changeUrl").each(function() {
        if ($(this).val() != 0) {
            url += $(this).val() + ".";
        }
    });
    changeUrlPar("variantid", url.substr(0, url.length - 1));
}
/**
* function change urls parametrs
*/
function changeUrlPar(par, val) {
    var link = $("a.changelink");
    if ($(link).attr("href")) {
        var href = $(link).attr("href");
        href = href.substr(href.indexOf("?") + 1);
        href = href.split("&");
        var arrayOfPar = Array();
        //make new assoc array of par of url
        for (i = 0; i < href.length; i++) {
            var arrayEl = href[i].split("=");
            arrayOfPar[arrayEl[0]] = arrayEl[1];
        }
        //replace or make par and value of this functions parametrs
        arrayOfPar[par] = val;
        //make new url from array
        var newHref = "";
        for (var i in arrayOfPar) {
            newHref += i + "=" + arrayOfPar[i] + "&";
        }
        newHref = newHref.substr(0, newHref.length - 1);
        //combine new url with old href of link
        $(link).attr("href", $(link).attr("href").substr(0, $(link).attr("href").indexOf("?") + 1) + newHref);
    }
}
function expandProductGroup(strGroupID) {
/*
    $("#lefetmenu ul.M0").css("display", "none");
    $("#lefetmenu li").css("background-image", "none");
    $("#lefetmenu li").css("border", "none");
    
    $("#" + strGroupID).css("display", "block");
    $("#" + strGroupID).parent().css("background-image", "url('/Files/Templates/Designs/MostersButik/img/productmenu-active.png')");
    $("#" + strGroupID).parent().css("border-top", "1px solid #58a30c");
    $("#" + strGroupID).parent().css("border-bottom", "1px solid #58a30c");
    */
    $("#lefetmenu ul.M0").css("display", "none");
    $("#lefetmenu li").removeClass('expanded');

    $("#" + strGroupID).css("display", "block");
    $("#" + strGroupID).parent().addClass('expanded');
}
function openmenu() {
    var blnHasSubPages = false;
    if ($(".activeitemleft").parent().parent()[0].id.length != 0) {
        blnHasSubPages = true;
    }
    
    if (blnHasSubPages == true) {
        $(".activeitemleft").parent().parent().css("display", "block");
        $(".activeitemleft").parent().parent().parent().addClass('expanded');
        /*
        $(".activeitemleft").parent().parent().parent().css("background-image", "url('/Files/Templates/Designs/MostersButik/img/productmenu-active.png')");
        $(".activeitemleft").parent().parent().parent().css("border-top", "1px solid #58a30c");
        $(".activeitemleft").parent().parent().parent().css("border-bottom", "1px solid #58a30c");
        */
    }
}
function makeactive(strIDrange) {
    aryIDrange = strIDrange.split("|");
    var strID = "";
    if (aryIDrange[0] != "GROUP67") {
        strID = aryIDrange[0];
    } else {
        if (aryIDrange.length > 1) {
            strID = aryIDrange[1];
        }
    }
    if (strID != "") {
        $("#item" + strID).addClass('activeitemleft');
    }
}


