$(document).ready(function () {


    //Sætter åbningstider og telefon
    var tlf = $("#tlf").text();
    var opentimes = $("#opentimes").text();

    $(".tlf").text(tlf);
    $(".opentimes").text(opentimes);

    //Venstremenu
    $(".RootCategory_Productmenu:last").css("background-image", "none");

    $("#ShopLayOut_Search_TD").parent().css("display", "none");
    $(".SubMenu_Productmenu_Table").parent().css("display", "none");

    $("#Table17").css({ 'width': '160px', 'margin-right': '10px', 'margin-top': '10px' });

    var search = $("#Search_Form2");
    $("#CustomSearch").append(search);

    //Paysteps
    $(".BackGroundColor1_OrderStep3").find("br:eq(0)").css("display", "none");
    $(".BackGroundColor1_OrderStep3").find("br:eq(1)").css("display", "none");

    $(".CustomerInfo_OrderStep3").find("br:eq(0)").css("display", "none");
    $(".CustomerInfo_OrderStep3").find("br:eq(1)").css("display", "none");

    $("#acceptTermsBit").parent("td").css("padding", "10px 0px");


    //Vareliste
    $("#CatDesc table").removeAttr("style");

    if ($("#CatDesc .CmsPageStyle").html() != null) {
        var desc = $("#CatDesc .CmsPageStyle").html().split("#");
        $("#CatDesc .CmsPageStyle").html('');

        $("#CatDesc .CmsPageStyle").append("<div id='CustomShortDesc'></div>");
        $("#CatDesc .CmsPageStyle").append("<div id='CustomLongDesc'></div>");

        $("#CustomShortDesc").html(desc[0]);

        if (desc.length > 1) {
            $("#CustomLongDesc").html(desc[1]);
            $("#VarelisteSubtext").html(desc[1]);
            $("#CustomShortDesc").append("<img src='/images/adserving2/images/laes_mere.gif' id='CustomShortDesc_Link' />");
        }

        $("#CustomShortDesc_Link").click(function () {
            $("#CustomLongDesc").slideDown(300);
            $("#CustomShortDesc_Link").remove();
            $("#VarelisteSubtext").slideUp(300);
        });
    }


    //Varekort
    $("#BUYSECTION td:lt(2)").css("display", "none");

    //Produktkonfigurator
    //$(".Prices_Custom_TBL tr").addClass("exclude");

    var tr = $("#ProductList_TD tr:not(.Prices_Custom_TBL tr), .Related_Custom_TBL tr, .Frontpage_Custom_TBL tr");

    $(tr).each(
    function (intIndex) {
        var headlineCells = $(this).find(".txt");
        var h = 0;
        $(headlineCells).each(
        function (intIndex) {
            if ($(this).height() > h)
                h = $(this).height();
            //alert(h);
        });
        $(this).find("td:not(.Prices_Custom_TBL td, .CmsPageStyle td)").each(
            function (intIndex) {
                if (intIndex == 1 || intIndex == 2)
                    $(this).addClass("testClass");
                $(this).find(".txt").css("height", h);

            });

    });

    $("<td class='splitter'><div style='width:15px;display:block;'></div></td>").insertBefore(".testClass");

    //Priser
    var priceBefore = $(".priceBefore");
    $(priceBefore).each(
    function (intIndex) {
        if ($(this).text() != "") {
            $("<span>(</span>").insertBefore(this);
            $("<span>) </span>").insertAfter(this);
        }
    });

    var oldRelatedText = $("#oldRelatedText").text();
    var newRelatedText = $("#newRelatedText").text();
    if (oldRelatedText != '') {
        if (newRelatedText != '') {
            $("#oldRelatedText").text(newRelatedText);
        }
    };

    //Internt produktnumrevisning
    if ($.cookie('enable_toplinks') == 'true') {
        var linkProductnumber = document.createElement("a");
        $(linkProductnumber).attr({ "id": "linkProductnumber", "href": "#" });
        $(".customTopmenu:first").append(linkProductnumber);

        var linkStock = document.createElement("a");
        $(linkStock).attr({ "id": "linkStock", "href": "#" });
        $(".customTopmenu:first").append(linkStock);

        if ($.cookie('show_productnumber') == 'true') {
            $(".produktnumre").css("display", "block");
            $(linkProductnumber).attr("rel", "hide");
            $(linkProductnumber).text("Skjul produktnumre");
        }
        else {
            $(".produktnumre").css("display", "none");
            $(linkProductnumber).attr("rel", "show");
            $(linkProductnumber).text("Vis produktnumre");
        }

        if ($.cookie('show_stock') == 'true') {
            $(".lager").css("display", "block");
            $(linkStock).attr("rel", "hide");
            $(linkStock).text("Skjul lager");
        }
        else {
            $(".lager").css("display", "none");
            $(linkStock).attr("rel", "show");
            $(linkStock).text("Vis lager");
        }
    }

    $("#linkProductnumber").click(function () {
        if ($(this).attr("rel") == 'show') {
            $.cookie('show_productnumber', 'true', { expires: 1 });
            $(".produktnumre").show();
            $(this).attr("rel", "hide");
            $(this).text("Skjul produktnumre");
        }
        else {
            $.cookie('show_productnumber', 'false');
            $(".produktnumre").hide();
            $(this).attr("rel", "show");
            $(this).text("Vis produktnumre");
        }
    });

    $("#linkStock").click(function () {
        if ($(this).attr("rel") == 'show') {
            $.cookie('show_stock', 'true', { expires: 1 });
            $(".lager").show();
            $(this).attr("rel", "hide");
            $(this).text("Skjul lagerstatus");
        }
        else {
            $.cookie('show_stock', 'false');
            $(".lager").hide();
            $(this).attr("rel", "show");
            $(this).text("Vis lagerstatus");
        }
    });





    //Trustpilot
    //    $('#tp_review_id0,#tp_review_id1,#tp_review_id2').addClass("item");
    //    $('.item:first').addClass('active');

    //    $('.tpc_widget').css("height", $('.active:first').height() + 175);
    //    rotateSwitch(); //Run function on launch

    //Infobar i toppen
//        if ($.cookie('infobar') != '1') {
//            var infobar = $("#infobar");
//            var infobar2 = $("#infobar2");
//            //$("#ShopContentLayOutTable").prepend(infobar);
//            $(infobar).insertBefore("#ContentContainer_DIV");
//            $(infobar2).insertBefore("#Table17");
//            $(infobar).css("display", "block");
//            $(infobar2).css("display", "block");
//            $('#Table17').css("margin-top", "6px");
//        }

//        $('#infobarHide').bind('click', function () {
//            $.cookie('infobar', '1');
//            //$('#infobar').hide("fold", { size: 1 }, 1500);
//            $('#infobar').css('display', 'none');
//            $('#infobar2').css('display', 'none');
//            $('#Table17').css("margin-top", "10px");
//        });



    //slut crap
});


//Paging  and Slider Function
rotate = function () {
    $('.item').removeAttr('style');
    $active.fadeIn(900);
    var h = $active.height() + 175;
    $('.tpc_widget').css("height", h);
    $('.item').removeClass('active'); //Remove all active class
    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
};

//Rotation  and Timing Event
rotateSwitch = function () {
    play = setInterval(function () { //Set timer - this will repeat itself every 7 seconds
        $active = $('li.active').next(); //Move to the next paging
        $active.fadeOut(900);
        if ($active.length === 0) { //If paging reaches the end...
            $active = $('.item:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
    }, 12000); //Timer speed in milliseconds (7 seconds)
};


