﻿var timeoutFunctionsArray = new Array();
var slideTime = 15000;
function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}
if (gup("view") != "")
    window.location = "index.aspx";
$(document).ready(function() {
    
    ShowExpertise();
    timeoutFunctionsArray.push(setTimeout("StartCycleViews()", slideTime));
    //fnLoadPngs();
    //$('#HomeAnimatedArea').mouseleave(function() {
    $('#HomeAnimatedArea').hover(function() {
        StopCycleViews();
        clearAllTimeouts()
    });
    $('#HomeAnimatedArea').mouseleave(function() {
        //alert('leaving. cyclerunning: ' + cycleRunning + ', timeoutFunctionsArray.length: ' + timeoutFunctionsArray.length);
        //alert('Startagain');
        //alert(timeoutFunctionsArray.length);
        //alert(cycleRunning);
        if (timeoutFunctionsArray.length <= 1 && !cycleRunning) {
            cycleRunning = true;
            if ($(OverlayCycle[0]).css('opacity') == 1.0) {
                currentView = 0;
            }
            if ($(OverlayCycle[1]).css('opacity') == 1.0) {
                currentView = 1;
            }
            if ($(OverlayCycle[2]).css('opacity') == 1.0) {
                currentView = 2;
            }
            clearAllTimeouts();
            timeoutFunctionsArray.push(setTimeout("StartCycleViews()", slideTime));
        }
    });
    $('#DedicationToggle').hover(function() {
        ShowDedication();
        StopCycleViews();
        clearAllTimeouts()
    });

    $('#ExperienceToggle').hover(function() {
        ShowExperience();
        StopCycleViews();
        clearAllTimeouts()
    });

    $('#ExpertiseToggle').hover(function() {
        ShowExpertise();
        StopCycleViews();
        clearAllTimeouts()
    });
});

function clearAllTimeouts() {
    if (timeoutFunctionsArray.length > 0) {
        for (var i in timeoutFunctionsArray) {
            clearTimeout(timeoutFunctionsArray[i]);
        }
    }
    while (timeoutFunctionsArray.length > 0)
        timeoutFunctionsArray.pop();
    return;
}
var currentView = 0;
var HomepageImages;
HomepageImages = new Array(3);
HomepageImages[0] = "url('assets/img/Home-Page-Master_01.jpg')";
HomepageImages[1] = "url('assets/img/Home-Page-Partner_01.jpg')";
HomepageImages[2] = "url('assets/img/Home-Page-Staffing_01.jpg')";

var HomepageGraphicCon;
HomepageGraphicCon = new Array(3);
HomepageGraphicCon[0] = "#ExpertiseGraphicContainer";
HomepageGraphicCon[1] = "#DedicationGraphicContainer";
HomepageGraphicCon[2] = "#ExperienceGraphicContainer";


var HomepageText;
HomepageText = new Array(3);
HomepageText[0] = "#ExpertiseText";
HomepageText[1] = "#DedicationText";
HomepageText[2] = "#ExperienceText";

var OverlayCycle;
OverlayCycle = new Array(3);
OverlayCycle[0] = "#ExpertiseOverlay";
OverlayCycle[1] = "#DedicationOverlay";
OverlayCycle[2] = "#ExperienceOverlay";

var cycleRunning = true;
var tCurr;
var tNxt;
function StartCycleViews() {
    if (cycleRunning)
    {
        var nextView = currentView;
        nextView = currentView + 1;
        if (nextView > 2)
            nextView = 0;


        //$('#SkylineBGEffect').css('background-image', HomepageImages[currentView]);
        $(HomepageGraphicCon[nextView]).show();
        $(HomepageGraphicCon[nextView]).css('opacity','');
        tCurr = currentView;
        tNxt = nextView;
        $(HomepageGraphicCon[currentView]).animate({ opacity: 0.0 }, 250, 'linear', function() {

        $(HomepageGraphicCon[tCurr]).hide();
        $(HomepageGraphicCon[tCurr]).css('zIndex', 4);
        $(HomepageGraphicCon[tNxt]).css('zIndex', 5);
        });
        /*$(HomepageGraphicCon[currentView]).fadeOut(250, function() {
            $('.SkylineContainer').css('background-image', HomepageImages[currentView]);
            $('.SkylineContainer').fadeIn(250);

        });*/
        $('.IndexTextArea').animate({ opacity: 0.0 }, 150, 'linear', function() {
            $('#ImageText').html($(HomepageText[tNxt]).html());
            $('.IndexTextArea').animate({ opacity: 1.0 }, 150);
        });
        
        var removeOverlays = nextView;

        $(OverlayCycle[nextView]).css('opacity',1.0);
        removeOverlays = removeOverlays + 1;
        if (removeOverlays > 2)
            removeOverlays = 0;
        $(OverlayCycle[removeOverlays]).css('opacity',0.7);    
            removeOverlays = removeOverlays + 1;
        if (removeOverlays > 2)
            removeOverlays = 0;
        $(OverlayCycle[removeOverlays]).css('opacity', 0.7);
        //alert($(HomepageText[currentView]).html());
        currentView = nextView;
        clearAllTimeouts();
        timeoutFunctionsArray.push(setTimeout("StartCycleViews()", slideTime));
    }

}

function StopCycleViews() {
    cycleRunning = false;
    //$('.SkylineContainer').stop();
}

function ShowDedication() {
    $('#DedicationGraphicContainer').stop(true, false);
    $('.IndexTextArea').stop(true, false);
    $('.IndexTextArea').css('opacity', 1.0);
    $('#DedicationGraphicContainer').show();
    $('#DedicationGraphicContainer').css('opacity', '');
    $('#DedicationGraphicContainer').css('zIndex', 5);
    //$('.SkylineContainer').css('background-image', "url('assets/img/Home-Page-Partner_01.jpg')");
    $('#ImageText').html($('#DedicationText').html());
    $('#DedicationOverlay').css('opacity', 1.0);
    HideExpertise();
    HideExperience();
    currentView = 1;
    
}

function ShowExperience() {
    $('#ExperienceGraphicContainer').stop(true, false);
    $('.IndexTextArea').stop(true, false);
    $('.IndexTextArea').css('opacity', 1.0);
    $('#ExperienceGraphicContainer').show();
    $('#ExperienceGraphicContainer').css('opacity','');
    $('#ExperienceGraphicContainer').css('zIndex', 5);
    //$('.SkylineContainer').css('background-image', "url('assets/img/Home-Page-Staffing_01.jpg')");
    $('#ImageText').html($('#ExperienceText').html());
    $('#ExperienceOverlay').css('opacity', 1.0);
    HideExpertise();
    HideDedication();
    currentView = 2;
}

function ShowExpertise() {
    $('#ExpertiseGraphicContainer').stop(true, false);
    $('.IndexTextArea').stop(true, false);
    $('.IndexTextArea').css('opacity', 1.0);
    $('#ExpertiseGraphicContainer').show();
    $('#ExpertiseGraphicContainer').css('opacity', '');
    $('#ExpertiseGraphicContainer').css('zIndex', 5);
    //$('.SkylineContainer').css('background-image', "url('assets/img/Home-Page-Master_01.jpg')");
    $('#ImageText').html($('#ExpertiseText').html());
    $('#ExpertiseOverlay').css('opacity', 1.0);
    HideExperience();
    HideDedication();
    currentView = 0;
}

function HideDedication() {
    $('#DedicationGraphicContainer').css('zIndex', 4);
    $('#DedicationGraphicContainer').hide();
    $('#DedicationOverlay').css('opacity', 0.7);
}
function HideExperience() {
    $('#ExperienceGraphicContainer').css('zIndex', 4);
    $('#ExperienceGraphicContainer').hide();
   $('#ExperienceOverlay').css('opacity', 0.7);
}
function HideExpertise() {
    $('#ExpertiseGraphicContainer').css('zIndex', 4);
    $('#ExpertiseGraphicContainer').hide();
    $('#ExpertiseOverlay').css('opacity', 0.7);
}

/*function ExpertiseOverlayHide() {
    $('#ExpertiseOverlay').css('opacity', 0.7);
}

function ExperienceOverlayHide() {
    //$('#ExperienceOverlay').animate({ height: "3em", opacity: 0.7 }, 0);
    $('#ExperienceOverlay').css('opacity', 0.7);
}

function DedicationOverlayHide() {
   ///$('#DedicationOverlay').animate({ height: "3em", opacity: 0.7 }, 0);
   $('#DedicationOverlay').css('opacity', 0.7);
}*/