function initializeJQueryCode() {
    $(".validate").click(function () {
        $.validity.start();
        $(".requiredfield").require();
        $(".datefield").match("date");
        $(".emailfield").match("email");
        $(".integerfield").match("number");
        $(".numberfield").match("number");
        $(".numericfield").match("number");
        $(".decimalfield").match("number");
        $(".moneyfield").match("number");
        var result = $.validity.end();
        if (!result.valid) {
            $(".validity-summary-container").show();
            $('html, body').animate({ scrollTop: 0 }, 'fast');
        }
        return result.valid;
    });
    try {
        $(".datefield").datepicker({ changeMonth: true, changeYear: true, numberOfMonths: 1, showOtherMonths: true, selectOtherMonths: true, showButtonPanel: true, showOn: 'focus' });
        $(".datefield").datepicker('option', '{showAnim: slideDown}');
    } catch (err) { }
    try {
        $(".datefield").attr('autocomplete', 'off');
    } catch (err) { }

    // typekit fonts
    try { Typekit.load(); } catch (e) { }

    $('.jq_watermark').watermark();

    $('.marquee_cycle').cycle({
        fx: 'fade',
        speed: 1500,
        timeout: 5000
    });

    $('.quote_cycle').cycle({
        fx: 'blindY',
        speed: 750,
        timeout: 12000
    });

    $("a.colorbox_fa").colorbox({
        iframe: true,
        innerWidth: "1000",
        innerHeight: "80%",
        scrolling: true
    });

    $("a.colorbox_media").colorbox({
        iframe: true,
        innerWidth: "760",
        innerHeight: "535",
        scrolling: true
    });

    $(window).scroll(function () {

        _top = $(".quote").offset();

        if (_top == null) return;

        if ($(window).scrollTop() > _top.top) {
            $(".contact-bar").attr("style", "position:fixed;top:92px;width:100%;z-index:102");
        }

        if ($(window).scrollTop() <= _top.top) {
            $(".contact-bar").attr("style", "position:relative;top:0");
        }
    });
}

$(document).ready(function () {
    initializeJQueryCode();
});

function PopupWindow(aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, "PopupWin", "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function PopupNamedWindow(aName, aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, aName, "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function PopupUniqueWindow(aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, "PopupWin" + (new Date()).getTime(), "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function HideShowControl(ctrlid) {
    var ctrl = document.getElementById(ctrlid);
    if (ctrl.style.display == "none") {
        ctrl.style.display = "";
    }
    else {
        ctrl.style.display = "none";
    }
}

function HideControl() {
    var ctrl;

    for (i = 0; i < arguments.length; i++) {
        ctrl = document.getElementById(arguments[i]);
        if (ctrl.style.display != "none") {
            ctrl.style.display = "none";
        }
    }
}

function ShowControl() {
    var ctrl;

    for (i = 0; i < arguments.length; i++) {
        ctrl = document.getElementById(arguments[i]);

        if (ctrl.style.display == "none") {
            ctrl.style.display = "";
        }
    }
}
