$(function() {
    // sIFR implementation
    if (typeof sIFR == "function") {
        sIFR.replaceElement(named({ sSelector: ".carrotflower", sFlashSrc: "images/flash/Carrotflower.swf", sColor: "#000000", sWmode: "transparent" }));
        sIFR.replaceElement(named({ sSelector: ".carrotflower-pink", sFlashSrc: "images/flash/Carrotflower.swf", sColor: "#cc6690", sWmode: "transparent" }));
        sIFR.replaceElement(named({ sSelector: "tr.header th span", sFlashSrc: "images/flash/Carrotflower.swf", sColor: "#000000", sWmode: "transparent" }));
    };

    // remove background for "other" browsers
    $("#categories-panel ul li:last-child ul").css("background", "none");

    // asp.net validator correction
    //check on page start (for f.e. firefox)
    $("span.validator").each(function(e) {
        var controlToValidate = $("#" + this.controltovalidate);
        var validators = controlToValidate.attr("Validators");
        if (validators == null) return;
        var message = "";

        var isValid = true;
        $(validators).each(function() {
            if (this.isvalid !== true) {
                isValid = false;
                message = $(this).attr("title");
            }
        });

        if (isValid) {
            controlToValidate.removeClass("error");
            controlToValidate.attr("title", "");
        } else {
            controlToValidate.addClass("error");
            controlToValidate.attr("title", message);
        }
    });


    //check on validator change
    $("span.validator").bind("DOMAttrModified propertychange", function(e) {
        // exit early if IE because it throws this event lots more
        if (e.originalEvent.propertyName && e.originalEvent.propertyName != "isvalid") return;

        var controlToValidate = $("#" + this.controltovalidate);
        var validators = controlToValidate.attr("Validators");
        if (validators == null) return;
        var message = "";

        var isValid = true;
        $(validators).each(function(e) {
            if (this.isvalid !== true) {
                isValid = false;
                message = $(this).attr("title");
            }
        });

        if (isValid) {
            controlToValidate.removeClass("error");
            controlToValidate.attr("title", "");
        } else {
            controlToValidate.addClass("error");
            controlToValidate.attr("title", message);
        }
    });
});
