function RegisterTableStyles() {

    $(".datatable td").each(function () {
        if ($(this).parent(0).attr("href")) {
            $(this).css("cursor", "pointer");
        }
    });
    $(".datatable td").hover(function (e) {
        if ($(this).parent(0).attr("href")) {
            $(this).parent(0).find("td").addClass("hover");
        }
    }, function (e) {
        if ($(this).parent(0).attr("href")) {
            $(this).parent(0).find("td").removeClass("hover");
        }
    });
    $(".datatable td").click(function (e) {
        if (!$(e.target).is("a") && !$(e.target).is("img")) {
            if ($(this).parent(0).attr("href")) {
                window.location.href = $(this).parent(0).attr("href");
            }
        }
    });
}

//function initFilterButton() {
//    if ($(".filter-button").parent(0).hasClass("filter-closed")) {
//        $(".filter-button").html("Show Filter");
//    } else {
//        $(".filter-button").html("Hide Filter");
//    }
//}

//function RegisterFilter() {
//    $(".filter-button").click(function () {
//        if ($(this).parent(0).hasClass("filter-closed")) {
//            $(this).parent(0).removeClass("filter-closed");
//            $(".filter-content").show();
//        } else {
//            $(this).parent(0).addClass("filter-closed");
//            $(".filter-content").hide();
//        }
//        initFilterButton();
//    });
//}

$(document).ready(function () {
    /*** DATATABLE ***/

    RegisterTableStyles();

//    RegisterFilter();
//    initFilterButton();
    





    /** HOVER & DOWN IMAGES **/
    $(".image-button").hover(function () {
        var src = $(this).attr("src");
        if ($(this).attr("hover")) {
            $(this).attr("src", $(this).attr("hover"));
            $(this).attr("hover", src);
        }
    }, function () {
        var src = $(this).attr("src");
        if ($(this).attr("hover")) {
            $(this).attr("src", $(this).attr("hover"));
            $(this).attr("hover", src);
        }
    });
    $(".image-button").mousedown(function () {
        var src = $(this).attr("src");
        if ($(this).attr("down")) {
            $(this).attr("src", $(this).attr("down"));
            $(this).attr("down", src);
        }
    });
    $(".image-button").mouseup(function () {
        var src = $(this).attr("src");
        if ($(this).attr("down")) {
            $(this).attr("src", $(this).attr("down"));
            $(this).attr("down", src);
        }
    });

    /** SUBMIT FORM (IF POS) **/
    $(".image-button").click(function () {
        if ($(this).parents("form:first").length == 1 && $(this).parents("form:first").attr("rel") != "ajax")
            $(this).parents("form:first").submit();
    });


    $(".nav-items li").click(function () {
        var href = $(this).find("a").attr("href");
        window.location.href = href;
    });

    /** PRODUCT COMPARISONS **/
    if ($(".product-comparison").length > 0) {
        $(".product-comparison .comp-header li").click(function () {
            $(".product-comparison .active").removeClass("active");
            var rel = $(this).attr("rel");
            $(".product-comparison li[rel=" + rel + "]").addClass("active");
        });

        var nrCols = $(".comp-body li").length;
        $(".comp-body li.def").css("width", ((6 - (nrCols * 1)) * 20) + "%");

        /** LOOP THROUGH EVERY DIV OF EVERY LIST ITEM TO ADJUST LIST ITEM HEIGHTS **/
        var max = $(".comp-body li:first div").length;
        for (i = 0; i < max; i++) {
            var maxHeight = 0;
            $(".comp-body li").each(function () {
                var divs = $("div", $(this));
                if ($(divs[i]).height() > maxHeight) {
                    maxHeight = $(divs[i]).height();
                }
            });
            $(".comp-body li").each(function () {
                var divs = $("div", $(this));
                $(divs[i]).css("height", maxHeight);
            });
        }
        /** ONLOAD HIGHLIGHT **/
        if ($(".product-comparison .comp-header li.active").length > 0) {
            $(".product-comparison .comp-header li.active").each(function () {
                var rel = $(this).attr("rel");
                $(".product-comparison li[rel=" + rel + "]").addClass("active");
            });
        }

    }
    $("#news-items li").click(function () {
        var href = $("a", $(this)).attr("href");
        window.location.href = href;
    });

    /** ALL BUTTONS WITH HREF ATTRIBUTE **/
    $("input[type='button']").click(function () {
        if ($(this).attr("href")) {
            window.location.href = $(this).attr("href");
            return false;
        }
        return true;
    });


    /** EMAIL SUBSCRIPTION **/
    $("#email-subscribe-button").click(function () {
        var email = $("#subscribe-email").attr("value");
        $("#subscribe-email").removeClass("error");
        $.ajax({
            type: "POST",
            url: baseHref + "/edp/subscribe/",
            data: "email=" + email,
            dataType: "json",
            success: function (ob) {

                if (ob.response == false) {
                    $("#subscribe-email").addClass("error");
                }
                $(".subscribe-form").parent(0).find(".msg").fadeOut();
                $(".subscribe-form").parent(0).find("h2:first").after(ob.html);
                $(".subscribe-form").parent(0).find("p:first").hide();
                initCloseMessages();
                $(".subscribe-form").parent(0).find(".msg .msg-close").click(function () {
                    $(".subscribe-form").parent(0).find("p:first").show();
                });
            }
        });
        return false;
    });

});
