﻿var timeoutFunctionsArray = new Array();
var slideTime = 7000;
var slideTimeClick = 10000;
var fadeTime = 750;
var cycleStart = Math.floor(Math.random() * 5);
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 () {
    //$('.menu #bgbutton').fadeTo(0, 0.5);
    //$('.menu ul li').hover(function () { $('a', this).fadeTo(0, 0.8); });
    //ShowExpertise();
    //currentview = cycleStart;
    $('.IndexImageContainers').each(function (index1, value) {
        if ($(this).filter(function (index) { return $('img:visible', this).length == 1; }).length == 1)
            currentView = index1;
    });
    $('.SwitchButtons a').eq(currentView).css('background-color', '#27436c');
    //    alert(currentView);
    timeoutFunctionsArray.push(setTimeout("StartCycleViews()", slideTime));
    //fnLoadPngs();
    //$('#HomeAnimatedArea').mouseleave(function() {
    $('#HomeAnimatedArea').hover(function () {
        StopCycleViews();
        clearAllTimeouts()
    });
    $('.SwitchButtons').click(function () {
        var IndexOfSwitch;
        var selectedID = $(this).attr('id');
        $('.SwitchButtons').each(function (index, value) {
            if ($(this).attr('id') == selectedID) {
                IndexOfSwitch = index;

            }
        });
        $('.IndexImageContainers').animate({ opacity: 0.0 }, 0);
        $('.IndexImageContainers').css('zIndex', 4);
        $('.IndexImageContainers').hide();
        $('.SwitchButtons a').css('background-color', '#7d8da6');
        $('.IndexImageContainers').eq(IndexOfSwitch).show();
        $('.IndexImageContainers').eq(IndexOfSwitch).animate({ opacity: 1.0 }, 0);
        $('.IndexImageContainers').eq(IndexOfSwitch).css('zIndex',5);
        $('.SwitchButtons a').eq(IndexOfSwitch).css('background-color', '#27436c');
        //if (timeoutFunctionsArray.length <= 1 && !cycleRunning) {
            cycleRunning = true;

            $('.IndexImageContainers').each(function (index1, value) {
                if ($(this).filter(function (index) { return $('img:visible', this).length == 1; }).length == 1)
                    currentView = index1;
            });
            clearAllTimeouts();
            timeoutFunctionsArray.push(setTimeout("StartCycleViews()", slideTimeClick));
        //}
        return false;
    });
    //    $('#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('" + $('#IndexImage1Container img').attr('src') + "')";
HomepageImages[1] = "url('" + $('#IndexImage2Container img').attr('src') + "')";
HomepageImages[2] = "url('" + $('#IndexImage3Container img').attr('src') + "')";
HomepageImages[3] = "url('" + $('#IndexImage4Container img').attr('src') + "')";
HomepageImages[4] = "url('" + $('#IndexImage5Container img').attr('src') + "')";

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 > 4)
            nextView = 0;


        //$('#SkylineBGEffect').css('background-image', HomepageImages[currentView]);
//        alert($('.IndexImageContainers').eq(nextView))
        $('.IndexImageContainers').eq(nextView).show();
        //$(HomepageGraphicCon[nextView]).css('opacity','');
        tCurr = currentView;
        tNxt = nextView;
        $('.IndexImageContainers').eq(tNxt).css('zIndex', 4);
        $('.IndexImageContainers').eq(tCurr).css('zIndex', 5);
        $('.IndexImageContainers').eq(tNxt).animate({ opacity: 1.0 }, 0);
        $('.IndexImageContainers').eq(tNxt).show();
        $('.IndexImageContainers').eq(tCurr).animate({ opacity: 0.0 }, fadeTime, 'linear', function () {

            //        $(HomepageGraphicCon[tCurr]).hide();
            //        $(HomepageGraphicCon[tCurr]).css('zIndex', 4);
            //        $(HomepageGraphicCon[tNxt]).css('zIndex', 5);
            $('.IndexImageContainers').eq(tCurr).hide();
            $('.SwitchButtons a').eq(tCurr).css('background-color', '#7d8da6');
            $('.SwitchButtons a').eq(tNxt).css('background-color', '#27436c');
            
        });
        /*$(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);
//        
        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);
}*/
