$(function() {
    $("#menuList>li,#menuList>li.current").hover(
                    function() {
                        $(this).siblings().removeClass("sfhover");
                        $(this).addClass("sfhover");
                    },
                    function() {
                        $(this).removeClass("sfhover");
                    });

    $("#topmenu>ul>li").hover(
            function() {
                $(this).addClass("sfhover");
                $(this).siblings().removeClass("sfhover");
            },
            function() {
                $(this).removeClass("sfhover");
            });


    $(".h-price-adjuster").each(function() {
        $(this).css('height', getMaxHeight());
    });

    $("#sokeknapp").click(function() {
        location.href = "/Hovedmeny/Funksjoner/Sok.aspx?s=" + $("#sokeboks").attr("value");
        return false;
    });

    $("#prodsokeknapp").click(function() {
        location.href = "/Hovedmeny/Funksjoner/Sok.aspx?g=produkt&s=" + $("#prodsokeboks").attr("value");
        return false;
    });

    $("input").keypress(function(e) {
        var isFirstmatch = true;
        if (e.keyCode == 13) {
            $(this).parents().each(function() {
                if (isFirstmatch) {
                    $(this).find("input[type='submit'],input[type='image']").map(function() {
                        isFirstmatch = false;
                        $(this).trigger('click');
                        return false;
                    });
                }
            });
            return false;
        }
    });
});

function EDB_jumpMenu(targ, selObj, restore) { //v3.0
    eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
    if (restore) selObj.selectedIndex = 0;
}

function showSimpelDialog(url) {
    window.open(url, 'eTIMS', 'toolbar=0,location=0, directories=0, status=0, menubar=0,scrollbars=1,resizable=1,width=650,height=800');
}

function addToBasketClick(selector, qtyId, btnId, AddToBasketText, id, url) 
{
    if(!isPending)
    {
        isPending = true;
        $('#mainform').attr('action', url);
        selector.after('<input type=\"hidden\" id=\"productid\" name=\"productid\" value=\"' + id + '\"  />');
        selector.after('<input type=\"hidden\" id=\"qty\" name=\"qty\" value=\"' + $('#' + qtyId).val() + '\"  />');
     }

//    var isPending = false;
//    $(function() {
//        $('#btn1EC0057D-E9B5-413E-AE41-C885B7437E66ea63ed3e-8f2b-4eca-9105-af941f45a7c0').click(function() {
//            addToBasketClick('qty1EC0057D-E9B5-413E-AE41-C885B7437E66ea63ed3e-8f2b-4eca-9105-af941f45a7c0', 'btn1EC0057D-E9B5-413E-AE41-C885B7437E66ea63ed3e-8f2b-4eca-9105-af941f45a7c0', '', '{1EC0057D-E9B5-413E-AE41-C885B7437E66}', '/sitecore/content/Home/Hovedmeny/Nettbokhandel/Funksjoner/Kjopsprosess/ProduktLagtTilHandlekurv.aspx');
//        });
//    });
}


var maxHeight = 0;
function getMaxHeight() {
    if (maxHeight == 0) {
        $(".h-price-adjuster").each(function() {

            var divOffset = $(this).offset().top;
            var pOffset = $(this).find("p").offset().top;
            var pHeight = $(this).find("p").height();

            var aOffset = $(this).find("a").offset().top;
            var aHeight = $(this).find("a").height();

            var pTotHeight = (pOffset - divOffset) + pHeight + 20;
            var aTotHeight = (aOffset - divOffset) + aHeight + 20;

            //alert(divOffset + " " + pOffset + " " + pTotHeight + " " + aTotHeight);
            var height = (pTotHeight > aTotHeight) ? pTotHeight : aTotHeight;
            if (height > maxHeight) {
                maxHeight = height;
            }
        });
    }
    return maxHeight;
}


