﻿//set drawmode false

var yesDraw = false;
var noDraw = false;

$(document).ready(function () {

    $(window).resize(function () {
        if ($(window).width() < $('.bodyWrapper').width()) {

            $('.bodyWrapper').css({ 'margin-left': '0', 'left': '0' });
            //$('.footer').css({ 'margin-left': '0', 'left': '0' });
        }

        else {
            $('.bodyWrapper').css({ 'margin-left': '-480px', 'left': '50%' });
            // $('.footer').css({ 'margin-left': '-480px', 'left': '50%' });
        }
    });

    if ($(window).width() < $('.bodyWrapper').width()) {

        $('.bodyWrapper').css({ 'margin-left': '0', 'left': '0' });
        //$('.footer').css({ 'margin-left': '0', 'left': '0' });
    }

    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

    /***nav bar hightlight***/
    if (sPage == "Default.aspx") {
        $('#home').css({ "color": "#f58220" });
    }
    if (sPage == "Solutions.aspx") {
        $('#sol').css({ "color": "#f58220" });

    }
    if (sPage == "Community.aspx") {
        $('#com').css({ "color": "#f58220" });
    }
    if (sPage == "Team.aspx") {
        $('#team').css({ "color": "#f58220" });
    }

    /*******community*****/

    $('#comCont').mouseenter(function () {
        $('#inst').animate({ bottom: '-1em' }, '250', 'easeInOutCubic');
    });

    $('#comCont').mouseleave(function () {
        $('#inst').animate({ bottom: '0px' }, '250', 'easeInOutCubic');
    });

    $('#teamContainer').mouseenter(function () {
        $('#inst').animate({ bottom: '-1em' }, '250', 'easeInOutCubic');
    });

    $('#teamContainer').mouseleave(function () {
        $('#inst').animate({ bottom: '0px' }, '250', 'easeInOutCubic');
    });

    /******************************************************color divs*********/

    $('#frontOne').hover(
        function () { $(this).attr("hovered", "true") },
        function () { $(this).attr("hovered", "false") }
    );

    $('#frontOne').mouseenter(function () {
        $('#midOne').animate({ top: '-1%' }, 250, 'easeInOutCubic');
        $('#backOnetxt').animate({ top: '50%' }, 250, 'easeInOutCubic').delay('250');
    });
    if (typeof $('#frontOne').attr("hovered") == 'undefined' || $('#frontOne').attr("hovered") == 'false') {
        $('#midOne').stop().animate({ top: '-101%' }, 700, 'easeInOutCubic');
        $('#backOnetxt').animate({ top: '101%' }, 700, 'easeInOutCubic')
    }

    $('#frontOne').mouseleave(function () {
        $('#midOne').stop().animate({ top: '-101%' }, 700, 'easeInOutCubic');
        $('#backOnetxt').animate({ top: '101%' }, 700, 'easeInOutCubic');
    });

    $('#frontTwo').hover(
        function () { $(this).attr("hovered", "true") },
        function () { $(this).attr("hovered", "false") }
    );

    $('#frontTwo').mouseenter(function () {
        $('#midTwo').animate({ top: '-1%' }, 250, 'easeInOutCubic');
        $('#backTwotxt').animate({ top: '50%' }, 250, 'easeInOutCubic').delay('250');
    });
    if (typeof $('#frontTwo').attr("hovered") == 'undefined' || $('#frontTwo').attr("hovered") == 'false') {
        $('#midTwo').stop().animate({ top: '-101%' }, 700, 'easeInOutCubic');
        $('#backTwotxt').animate({ top: '101%' }, 700, 'easeInOutCubic')
    }

    $('#frontTwo').mouseleave(function () {
        $('#midTwo').stop().animate({ top: '-101%' }, 700, 'easeInOutCubic');
        $('#backTwotxt').animate({ top: '101%' }, 700, 'easeInOutCubic');
    });

    $('#frontThree').hover(
        function () { $(this).attr("hovered", "true") },
        function () { $(this).attr("hovered", "false") }
    );

    $('#frontThree').mouseenter(function () {
        $('#midThree').animate({ top: '-1%' }, 250, 'easeInOutCubic');
        $('#backThreetxt').animate({ top: '50%' }, 250, 'easeInOutCubic').delay('250');
    });
    if (typeof $('#frontThree').attr("hovered") == 'undefined' || $('#frontThree').attr("hovered") == 'false') {
        $('#midThree').stop().animate({ top: '-101%' }, 700, 'easeInOutCubic');
        $('#backThreetxt').animate({ top: '101%' }, 700, 'easeInOutCubic')
    }

    $('#frontThree').mouseleave(function () {
        $('#midThree').stop().animate({ top: '-101%' }, 700, 'easeInOutCubic');
        $('#backThreetxt').animate({ top: '101%' }, 700, 'easeInOutCubic');
    });

    $('#frontFour').hover(
        function () { $(this).attr("hovered", "true") },
        function () { $(this).attr("hovered", "false") }
    );

    $('#frontFour').mouseenter(function () {

        $('#midFour').animate({ top: '-1%' }, 250, 'easeInOutCubic');
        $('#backFourtxt').animate({ top: '50%' }, 250, 'easeInOutCubic').delay('250');
    });
    if (typeof $('#frontFour').attr("hovered") == 'undefined' || $('#frontFour').attr("hovered") == 'false') {
        $('#midFour').stop().animate({ top: '-101%' }, 700, 'easeInOutCubic');
        $('#backFourtxt').animate({ top: '101%' }, 700, 'easeInOutCubic')
    }

    $('#frontFour').mouseleave(function () {
        $('#midFour').stop().animate({ top: '-101%' }, 700, 'easeInOutCubic');
        $('#backFourtxt').animate({ top: '101%' }, 700, 'easeInOutCubic');
    });

    /********Team******/

    $('#teamBlankone').hover(
        function () { $(this).attr("hovered", "true") },
        function () { $(this).attr("hovered", "false") }
    );

    $('#teamBlankone').mouseenter(function () {
        $('#teamFrontone').animate({ left: '-100%' }, '5000');
        $('#teamBackonetxt').animate({ left: '10%' }, '250');
    });

    if (typeof $('#teamBlankone').attr("hovered") != 'undefined' || $('#teamBlankone').attr("hovered") != 'false') {
        $('#teamFrontone').stop().animate({ left: '0%' }, '800');
        $('#teamBackonetxt').animate({ left: '-101%' }, '500');
    }

    $('#teamBlankone').mouseleave(function () {
        $('#teamFrontone').stop().animate({ left: '0%' }, '800');
        $('#teamBackonetxt').animate({ left: '-101%' }, '500');
    });

    $('#teamBlanktwo').hover(
        function () { $(this).attr("hovered", "true") },
        function () { $(this).attr("hovered", "false") }
    );

    $('#teamBlanktwo').mouseenter(function () {
        $('#teamFronttwo').animate({ right: '-100%' }, '5000');
        $('#teamBacktwotxt').animate({ left: '10%' }, '250');
    });

    if (typeof $('#teamBlanktwo').attr("hovered") != 'undefined' || $('#teamBlanktwo').attr("hovered") != 'false') {
        $('#teamFronttwo').stop().animate({ right: '0%' }, '800');
        $('#teamBacktwotxt').animate({ left: '-101%' }, '500')
    }

    $('#teamBlanktwo').mouseleave(function () {
        $('#teamFronttwo').stop().animate({ right: '0%' }, '800');
        $('#teamBacktwotxt').animate({ left: '-101%' }, '500');
    });

    $('#teamBlankthree').hover(
        function () { $(this).attr("hovered", "true") },
        function () { $(this).attr("hovered", "false") }
    );

    $('#teamBlankthree').mouseenter(function () {
        $('#teamFrontthree').animate({ left: '-100%' }, '5000');
        $('#teamBackthreetxt').animate({ left: '10%' }, '250');
    });

    if (typeof $('#teamBlankthree').attr("hovered") != 'undefined' || $('#teamBlankthree').attr("hovered") != 'false') {
        $('#teamFrontthree').stop().animate({ left: '0%' }, '800');
        $('#teamBackthreetxt').animate({ left: '-101%' }, '500');
    }

    $('#teamBlankthree').mouseleave(function () {
        $('#teamFrontthree').stop().animate({ left: '0%' }, '800');
        $('#teamBackthreetxt').animate({ left: '-101%' }, '500');
    });

    $('#teamBlankfour').hover(
        function () { $(this).attr("hovered", "true") },
        function () { $(this).attr("hovered", "false") }
    );

    $('#teamBlankfour').mouseenter(function () {
        $('#teamFrontfour').animate({ right: '-100%' }, '5000');
        $('#teamBackfourtxt').animate({ left: '10%' }, '250');
    });

    if (typeof $('#teamBlankfour').attr("hovered") != 'undefined' || $('#teamBlankfour').attr("hovered") != 'false') {
        $('#teamFrontfour').stop().animate({ right: '0%' }, '800');
        $('#teamBackfourtxt').animate({ left: '-101%' }, '500');
    }

    $('#teamBlankfour').mouseleave(function () {
        $('#teamFrontfour').stop().animate({ right: '0%' }, '800');
        $('#teamBackfourtxt').animate({ left: '-101%' }, '500');
    });

    /*team text*/

    var currentTxt = window.location.hash.slice(1)

    if (!(currentTxt == 'Jobs' || currentTxt == 'Story' || currentTxt == 'News' || currentTxt == 'Exec')) {
        currentTxt = 'Story';
    }

    $('#' + currentTxt).css({ 'display': 'block' });

    $('#teamBlankone').click(function () {
        window.location.hash = 'Story';
        $('#' + currentTxt).css({ "display": "none" });
        $('#Story').css({ "display": "block" });
        currentTxt = 'Story';
    });

    $('#teamBlanktwo').click(function () {
        window.location.hash = 'Jobs';
        $('#' + currentTxt).css({ "display": "none" });
        $('#Jobs').css({ "display": "block" }).delay('800');
        currentTxt = 'Jobs';
    });

    $('#teamBlankthree').click(function () {
        window.location.hash = 'Exec';
        $('#' + currentTxt).css({ "display": "none" });
        $('#Exec').css({ "display": "block" });
        currentTxt = 'Exec';
    });

    $('#teamBlankfour').click(function () {
        window.location.hash = 'News';
        $('#' + currentTxt).css({ "display": "none" });
        $('#News').css({ "display": "block" });
        currentTxt = 'News';
    });

    /******************************In the News*****/

    if (sPage == "InTheNews.aspx") {
        var prid = location.search.slice(1);

        if (isNaN(prid) == false) {
            $(function () {
                $('.press-release:not(.press-release[id=' + prid + '])').hide();
            });
        }
        else {
            $('#Press').hide();
            $('body').append('<div style="position:absolute; top:100px; left:25%;"> <h1>So sorry, it appears that the page you are looking for is not here.<h1></div>');
        }
    }

    if (sPage == "Employment.aspx") {
        var prid = location.search.slice(1);

        if (isNaN(prid) == false) {
            $(function () {
                $('.employmentOps:not(.employmentOps[id=' + prid + '])').hide();
            });

            $(function () {
                $('.apply:not(.apply[id=' + prid + '])').hide();
            });
        }
        else {
            $('#Employment').hide();
            $('body').append('<div style="position:absolute; top:100px; left:25%;"> <h1>So sorry, it appears that the page you are looking for is not here.<h1></div>');
        }
    }

    /****contact****/

    var searchModLeft = $('#searchMod').position().left;

    $('#contactMove').click(function () {
        if ($('#contact').attr('active') != 'active') {
            //$('#resultsDiv').fadeIn();
            $('#resultsDiv').fadeOut();
            $('#searchMod').animate({ "left": searchModLeft }, 250);
            $('#searchLbl').animate({ "left": "-26px" }, 250);
            $('#searchMod').attr('active', '');
            $('#contact').animate({ "left": "0px" }, 250);
            $('#contactLbl').animate({ "left": "0px" }, 250);
            $('#contact').attr('active', 'active');
            $('.bodyWrapper').css({ 'overflow': 'hidden' });

        }
        else {
            //$('#resultsDiv').fadeOut();
            

            $('#contact').animate({ "left": "-611px" }, 250);
            $('#contactLbl').animate({ "left": "-26px" }, 250);
            $('#contact').attr('active', '');
        }

    });

    $('#front1').mouseenter(function () { slideDown(this) });
    $('#front2').mouseenter(function () { slideDown(this) });
    $('#front3').mouseenter(function () { slideDown(this) });
    $('#front4').mouseenter(function () { slideDown(this) });

});                                     //end doc ready

function getElementsByClass(searchClass, domNode, tagName) {
    if (domNode == null) domNode = document;
    if (tagName == null) tagName = '*';
    var el = new Array();
    var tags = domNode.getElementsByTagName(tagName);
    var tcl = " " + searchClass + " ";
    for (i = 0, j = 0; i < tags.length; i++) {
        var test = " " + tags[i].className + " ";
        if (test.indexOf(tcl) != -1)
            el[j++] = tags[i];
    }
    return el;
}


var interval = setInterval(checkDivs, 250);

function checkDivs() {

    $(document).bind('mousemove', function (e) {
        var elems = getElementsByClass('frontDivcenter');
        $(elems).each(function () {

            $item = $(this);
            itemID = $(this).attr('id');
            var offset = $item.offset(),
                            width = $item.width(),
                            height = $item.height();

            if ($item.css('top') == '-300px') {

                if (e.pageX > offset.left && e.pageX < (offset.left + width)) {
                    var xAxis = 1
                }

                if (e.pageY > offset.top && e.pageY < (offset.top + height)) {
                    var yAxis = 1
                }

                $(document).unbind('mousemove');


                if (xAxis != '1' && yAxis != 1) {
                    //                
                    $item.stop().animate({ top: '-600px' }, 250, 'easeInOutCubic');
                }
            }

        });

    });

}


function stopInterval() {
    clearInterval(interval);
}





function slideDown(item) {
    $item = $(item);
    var offset = $item.offset();

    $item.animate({ top: '-300px' }, 250, 'easeInOutCubic').queue(slideUp(item));

};

function slideUp(item) {
    $item = $(item);
    var offset = $item.offset(),
    width = $item.width(),
    height = $item.height();





    $(document).mousemove(function (e) {

        if (e.pageX < offset.left || e.pageX > (offset.left + width) || e.pageY < offset.top || e.pageY > (offset.top + height)) {

            $(document).unbind("mousemove");

            $item.stop().animate({ top: '-600px' }, 250, 'easeInOutCubic');

        }
    });

}




