var isBroke = false;
var errDiv = "";
var fail = false;
$(document).ready(function () {
    adjustFirmsBuckets();

    if ($("#fImage").attr("src") == '') {
        $('.homeFeatImage').hide();
        $('.homeFeatContent').width('470px');
    }




    $('#mainNav ul').superfish();
    $("#mainNav ul li ul").css("position", "absolute");

    $("#mainNav ul li ul li").click(function () {
        var thisLink = $(this).children().attr('href');
        window.location = thisLink;
    });

    $(".mouseOver").hover(function () {
        $(this).attr("src", $(this).attr("src").split(".").join("_ovr."));
    }, function () {
        $(this).attr("src", $(this).attr("src").split("_ovr.").join("."));
    });

    $('#contactUsForm input').focus(function () {
        $(this).css('color', '#000');
    });
    $('#contactUsForm input').focus(function () {
        $(this).css('color', '#000');
    });

    var bool = false;
    $('.featBlueRight').css('top', 24);
    $('#firmsIntMiddle-Mid ul li').hoverIntent(function () {
        bool = false;
        var id = $(this).attr('class');

        if ($('#' + id).hasClass('initial')) {
            $('#' + id).removeClass('initial');
            $('#' + id).attr('class', 'hidden');
            $('#' + id).css('display', 'block');
        } else {
            $('#div0').removeClass('initial');
            $('#div0').attr('class', 'hidden');
            if ($('#' + id).css('display') != 'block' && $('#' + id).css('opacity') == 1) {
                $('.hidden').hide();
                setTimeout("$('#" + id + "').fadeIn(300)", 150);
                setTimeout("checkNumOfHidden()", 200);
            }
        }

        $('#firmsIntMiddle-Mid ul li').css('background-color', '');
        $(this).css('background-color', '#003f77');
    }, function () {
        var id = $(this).attr('class');
        $('#firmsIntMiddle-Mid ul').mouseleave(function () { bool = true; });

        if (bool == false) {
            $('.hidden').hide();
        } else {

        }
    });

    //Move the far left nav drop down so it is right aligned
    var leftNavPos = $('.leftMainNav ul').position();
    //alert('test');
    $('.leftMainNav ul').css('left', leftNavPos.left + 50);  //For everything but IE
    if ($.browser.msie) {
        // alert("***" + parseInt($.browser.version) + " - " + $.browser.version + "***");
        if (parseInt($.browser.version) < 8) {
            //alert('hello world');
            $('.leftMainNav ul').css('margin-left', '50%');
            $('.leftMainNav ul').css('left', -214 + $('.leftMainNav ul').width());
            leftNavPos = $('.leftMainNav ul').position();
        } else {
            $('.leftMainNav ul').css('margin-left', '50%');
            $('.leftMainNav ul').css('left', '-55px');
            //leftNavPos = $('.leftMainNav ul').position();
            //$('.leftMainNav ul').css('left', parseInt(leftNavPos.left) + 102);
            //leftNavPos = $('.leftMainNav ul').position();
        }
    }



    $('#rightColumn input').focus(function () {
        if ($(this).val() == 'Position Title' || $(this).val() == 'First' || $(this).val() == 'Last') {
            $(this).val('');
        }
    });
    $('#contactUsForm input').focus(function () {
        if ($(this).val() == 'Position Title' || $(this).val() == 'First' || $(this).val() == 'Last') {
            $(this).val('');
        }
    });
    $('#contactUsFormBot input').focus(function () {
        if ($(this).val() == 'First' || $(this).val() == 'Last') {
            $(this).val('');
        }
    });

    $('#ctl00_ResumeSubmission_txtPosID').val(trim($('.positionID').text()));

    $('#searchBox').gSearch({ resultsDIV: 'gResults', searchContainer: 'gSearchBox', siteRestriction: 'helblingsearch.com', useCB: true, CBTitle: 'Search Results', resultsPerPage: 6 });
});

function checkNumOfHidden() {
    var numOfHidden = 0;
    $('.featBlueRight ul').each(function () {
        if ($(this).css('display') == 'block') {
            numOfHidden = numOfHidden + 1;
        }
    });
    if (numOfHidden > 1) {
        isBroke = true;
    } else {
        isBroke = false;
    }

    if (isBroke == true) {
        $('.hidden').hide();
        $('#firmsIntMiddle-Mid ul li').each(function () {
            if ($(this).css('background-color') == 'rgb(0, 63, 119)') {
                id = $(this).attr('class');
                $('#' + id).css('display', 'none');
                $('.hidden').hide();
                setTimeout("$('#" + id + "').fadeIn(300)", 150);
            }
        });
    }
}

function adjustFirmsBuckets() {
    var maxHeight;
    var heightArray = new Array();
    $('.featBlueRight ul').each(function () {
        heightArray.push($(this).height());
    });

    var firmsLeftHeight = $('#firmsIntLeft-Mid').height();
    var firmsMiddleHeight = $('#firmsIntMiddle-Mid').height();
    var firmsRightHeight = $('.featBlueRight').height();
    //var heightArray = [parseInt(firmsLeftHeight),parseInt(firmsMiddleHeight),parseInt(firmsRightHeight)];

    heightArray.sort(function (a, b) { return b - a });

    maxHeight = heightArray[0] + 36;



    $('#firmsIntLeft-Mid').css('height', maxHeight - 2);
    $('#firmsIntMiddle-Mid').css('height', maxHeight);
    $('#firmsIntRight-Mid').css('height', maxHeight);
}

function sendingMail(contactForm) {
    var formPos = $(contactForm).position();
    var formHeight = $(contactForm).height();
    var sendHeight = $('#sending').height();
    var sendWidth = $('#sending').width();
    $('#whiteOverlay').height(formHeight);
    $('#whiteOverlay').width(parseInt($(contactForm).width()) + 20);
    $('#whiteOverlay').css('top', formPos.top);
    $('#whiteOverlay').css('left', formPos.left);

    $('#sending').css('top', parseInt(formPos.top) + (parseInt(formHeight) / 2) - (parseInt(sendHeight) / 2));
    $('#sending').css('left', parseInt(formPos.left) + (parseInt(292) / 2) - (parseInt(sendWidth) / 2));
}

function thanks() {
    $('#whiteOverlay').fadeOut();
    $('#sending').fadeOut();
    setTimeout(function () { $.colorbox({ width: "250px", height: "190px", open: true, inline: true, href: "#thanksText" }); }, 1000);

    $('#ctl00_txtTitle').val('Position Title');
    //$("#ctl00_ddlIndustry").get(0).selectedIndex = 0;
    $('#ctl00_txtFName').val('First');
    $('#ctl00_txtLName').val('Last');
    $('#ctl00_txtCompany').val('');
    $('#ctl00_txtEmail').val('');
    $('#ctl00_txtPhone').val('');


    //setTimeout(function() { $('#cboxClose').trigger('click'); },500);
    setTimeout(function () { location.href = window.location; }, 3500);

}

function openIFrame(_URL, _width, _height) {
    $.colorbox({ width: _width, height: _height, iframe: true, href: _URL });
}

function mdlMessage(myHref) {
    setTimeout(function () { $.colorbox({ width: "250px", height: "190px", inline: true, open: true, href: myHref }); }, 1000);

    //setTimeout(function() { $.fn.colorbox.close(); }, 6000);
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}



function verlicon(data) {
    if (window.console && window.console.firebug) {
        //Firebug is enabled
        console.log(data);
    } else if (window.console) {
        console.log(data);
    }
}
