var minReqScreenHeight = 576;
var minReqScreenWidth = 1024;
var minReqFlashVersion = "10";
var minReqAcrobatVersion = "6";

var acrobatInfo = perform_acrobat_detection();

var cookieCheck = navigator.cookieEnabled;
var flashCheck = versionPass(getSwfVer(), minReqFlashVersion);

$().ready(function() {
    checkRequirements();
    inputLabelsSetup();
    setupNavManu();
    setupButtons();
    $("#lb_username :input").focus();

    $("#ec-body").removeClass("hidden");
    $("#ec-body").hide();
    $(".ec-toggleBtn").click(function() {
        $("#ec-body").slideToggle(250);
    });
});
function checkRequirements() {
    var warningMsgText = "";
    if(display.height < minReqScreenHeight || display.width < minReqScreenWidth) {
        warningMsgText += WARNING_SCREEN_RES + "<br>";
    }
    if(!cookieCheck) {
        warningMsgText += WARNING_COOKIES + "<br>";
    }
    if(acrobatInfo.acrobat_ver == null)acrobatInfo.acrobat_ver = 0;
    if(os.name == "Mac OS" || os.name == "iOS" || browser.name == "Chrome" || versionPass(acrobatInfo.acrobat_ver, 6)) {
        acrobatInfo.check = true;
    } else {
        acrobatInfo.check = false;
        warningMsgText += WARNING_UPDATE_ACROBAT + "<br>";
    }
    if(os.name != "iOS" && !flashCheck) {
        warningMsgText += WARNING_UPDATE_FLASH + "<br>";
    }
    if(warningMsgText != "") {
        $("#warningMsg").html(warningMsgText);
        $("#warningMsg").show();
    }
}
function inputLabelsSetup() {
    var t, currTmr = null;
    $(".lblFrmFld input").each(function(i, e) {
        $(e).val("");
        $(e).focus(function() {
            if(currTmr == null)currTmr = $(e).parent().attr("id");
            $(e).next().addClass("focus");
            t = setTimeout(function() {
                if(currTmr == $(e).parent().attr("id")) {
                    if($(e).val() == "") {
                        $(e).next().removeClass("hasText");
                    } else {
                        $(e).next().addClass("hasText");
                    }
                    setTimeout(arguments.callee, 50);
                    currTmr = $(e).parent().attr("id");
                }
            });
        });
        $(e).keydown(function() {
            $("#loginVal").removeClass("show").addClass("hide");
            setTimeout(function() {
                $("#loginVal").removeClass("hide");
            }, 250);
        });
        $(e).blur(function() { currTmr = null });
        $(e).siblings(".fieldLabel").click(function() {
            $(e).focus();
        });
    });
}
function setupNavManu() {
    var listItemWidth;
    $.each($("#navMenu ul"), function(i, list) {
        $(list).css({display: "block"});
        listItemWidth = $(this).prev().outerWidth(true) + (browser == "IE" && browserVersion < 8 ? 0 : 2);
        $.each($(list).children(), function(j, listItem) {
            if($(listItem).outerWidth(true) > listItemWidth)listItemWidth = $(listItem).outerWidth(true);
        });
        $(list).children("li").width(listItemWidth + 1);
        $(list).removeAttr("style");
    });
}
function setupButtons() {
    $(".btn").mousedown(function() {
        $(this).children(".left").addClass("active");
        $(this).children(".right").addClass("active");
    });
    $(".btn").mouseup(function() {
        $(this).children(".active").removeClass("active");
    });
}

function getOpenWinParams(amountToSubtractFromScreenWidth, amountToSubtractFromScreenHeight) {
    var width = screen.width - amountToSubtractFromScreenWidth;
    var height = screen.height - amountToSubtractFromScreenHeight;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=yes';
    params += ', location=yes';
    params += ', menubar=yes';
    params += ', resizable=yes';
    params += ', scrollbars=yes';
    params += ', status=yes';
    params += ', toolbar=yes';
    return params;
}
