﻿$(document).ready(function () {
    $("#menu li").hide();

    BindTextBoxChange();

    /*$("#menu li").hoverIntent({
    sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
    interval: 100,   // number = milliseconds of polling interval
    over: showNav,  // function = onMouseOver callback (required)
    timeout: 0,   // number = milliseconds delay before onMouseOut function call
    out: hideNav    // function = onMouseOut callback (required)
    });*/

    $("#menu").superfish({ disableHI: true });

    $("#menu li li li *").hover(function () {
        $(this).parent().parent().parent().children("a").addClass("childselected");
    },
    function () {
        $(this).parent().parent().parent().children("a").removeClass("childselected");
    });
    
    $("#menu li li li li *").hover(function () {
        $(this).parent().parent().parent().children("a").addClass("childselected");
        $(this).parent().parent().parent().parent().parent().children("a").addClass("childselected");
    },
    function () {
        $(this).parent().parent().parent().children("a").removeClass("childselected");
        $(this).parent().parent().parent().parent().parent().children("a").removeClass("childselected");
    });

    $(".imageContainer img").live('click', function () {
        $("#video iframe").hide();
    });

    $(".imageContainer a:first").hide();

    $("#page *").highlight("seatply", "highlight");

    $(".print").click(function () { window.print(); });

    $("#client-page tbody tr:first-child td").css("padding-top", "10px");
});

$(window).load(function () 
{
    $("#menu li").show();
    $("#page *").highlight("seatply", "highlight");
});

function showNav() {
    if (!$(this).hasClass("childselected")) {
        $(this).addClass("childselected");
    }
}

function hideNav() {
    if (!$(this).hasClass("childselected")) {
        $(this).removeClass("childselected");
    } 
}

function BindTextBoxChange() {
    $(".tempTexted").each(function () {
        $(this).unbind('focus');
        $(this).unbind('blur');

        if ($(this).parent().children("#hidden_" + $(this).attr("id")).length === 0) {
            $(this).parent().append("<input type='hidden' id='hidden_" + $(this).attr("id") + "' value='" + $(this).val() + "' />");
        }

        $(this).focus(function () {
            if ($(this).val() === $("#hidden_" + $(this).attr("id")).val()) {
                $(this).val("");

                if ($(this).hasClass("hiddenText")) {
                    $(this).replaceWith("<input type='password' id='" + $(this).attr("id") + "' class='FieldBox tempTexted hiddenText' />");
                    $("#" + $(this).attr("id")).focus();
                    BindTextBoxChange()
                }
            }
        }).blur(function () {
            if ($(this).val() === "") {
                $(this).val($("#hidden_" + $(this).attr("id")).val());
                if ($(this).hasClass("hiddenText")) {
                    $(this).replaceWith("<input type='text' id='" + $(this).attr("id") + "' class='FieldBox tempTexted hiddenText' value='" + $("#hidden_" + $(this).attr("id")).val() + "' />");
                    BindTextBoxChange();
                }
            }
        });
    })
}

//Function to highligh the string, enclose it in a span and give it the proper class.
jQuery.fn.highlight = function (str, className) {
    var regex = new RegExp(str, "gi");
    return this.each(function () {
        $(this).contents().filter(function() {
            return this.nodeType == 3 && regex.test(this.nodeValue);
        }).replaceWith(function() {
            return (this.nodeValue || "").replace(regex, function(match) {
                return "<span class=\"" + className + "\">" + match + "</span>";
            });
        });
    });
};
