$(document).ready(function () {
    $(".registerlnk").click(function (e) {
        e.preventDefault();
        this.blur();
        OpenModal("/RegistrationForm.aspx?type=register", 947, 690);
        _gaq.push(['_trackEvent', 'Show Modal Form', "Registration"]);
    });

    $(".loginlnk").click(function (e) {
        e.preventDefault();
        this.blur();
        OpenModal("/RegistrationForm.aspx", 182, 690);
        _gaq.push(['_trackEvent', 'Show Modal Form', "Login"]);
    });

    $("#makinoMenuBtnCntnr").hover(function () {
        $("#makinoDDMenu").stop().show();
    },
    function () {
        $("#makinoDDMenu").stop().hide();
    });
    /*
    e.preventDefault();
    this.blur();

    if (this.className == "on") {
    this.className = "";
    $("#makinoDDMenu").slideUp(100);
    }
    else {
    this.className = "on";
    $("#makinoDDMenu").slideDown(100);
    }

    });
    */

    $("a").each(function () {
        var href = $(this).attr("href").toLowerCase();
        if (href.indexOf("https://") != -1 || href.indexOf("http://") != -1) {
            if (href.indexOf(document.domain) == -1) {
                $(this).click(function () {
                    _gaq.push(['_trackEvent', 'External Link Click', href, location.href]);
                });
            }
        }
        else {
            if (href.indexOf(".pdf") != -1) {
                $(this).click(function () {
                    _gaq.push(['_trackEvent', 'Download', this.title == "" ? this.href : this.title, location.href]);
                });
            }
        }
    });


});

function ShowRegistrationForm() {
    $("#modal").animate({ height: 947 }, 300);
    $("#modal").html("<a class='closeBtn' href='javascript:CloseModal()'></a><iframe src='/RegistrationForm.aspx?type=register' height='957' width='687' scrolling='no' frameBorder='0'></iframe>");
    _gaq.push(['_trackEvent', 'Show Modal Form', "Registration"]);
}

function ShowLoginForm() {
    $("#modal").animate({ height: 182 }, 300, function () {
        window.scrollTo(0, 0);
    });
    $("#modal").html("<a class='closeBtn' href='javascript:CloseModal()'></a><iframe src='/RegistrationForm.aspx' height='182' width='687' scrolling='no' frameBorder='0'></iframe>");
    _gaq.push(['_trackEvent', 'Show Modal Form', "Login"]);
}

function ShowForgotPasswordForm() {
    $("#modal").html("<a class='closeBtn' href='javascript:CloseModal()'></a><iframe src='/RegistrationForm.aspx?type=forgot' height='150' width='687' scrolling='no' frameBorder='0'></iframe>");
    _gaq.push(['_trackEvent', 'Show Modal Form', "Forgot Password"]);
}

function CloseModal(param) {
    $("#modal").fadeOut(200);
    $("#overlay").fadeOut(200);

    if (param == "refresh") {
        window.location.href = window.location.pathname;
    }
}

function OpenModal(src, Height, Width) {
    $("#modal").css("height", Height + "px").html("<a class='closeBtn' href='javascript:CloseModal()'></a><iframe src='" + src + "' height='" + Height + "' width='" + Width + "' scrolling='no' frameBorder='0'></iframe>");
    $("#overlay").fadeTo(200, 0.7);
    $("#modal").fadeIn(200);
    if ($("body").height() > $(document).height()) {
        $("#overlay").height($("body").height() + 50);
    }
    else {
        $("#overlay").height($(document).height() - 4);
    }
}
$(window).resize(function () {
    if ($("body").height() > $(document).height()) {
        $("#overlay").height($("body").height());
    }
    else {
        $("#overlay").height($(document).height());
    }
});
