﻿     var currentImageIndex = 0;
     var currentImage = "";
    var cancelled = false;
    var slides = new Array();
    slides[0] = "accountancyButton";
    slides[1] = "financialButton";
    slides[2] = "humanResourcesButton";
    slides[3] = "officeButton";

     $(document).ready(function () {
        OnDocumentReady();
     });
         

         function BeginSlideShow()
         {
              if(cancelled == false)
              {
                 if(currentImageIndex < slides.length -1)
                 {
                    currentImageIndex ++;
                 }
                 else
                 {
                    currentImageIndex = 0;
                 }
                 ScrollLatestJobs();
                 ShowText(slides[currentImageIndex]);
             }
         }
      


         function OnDocumentReady()
         {
            
           $('#imgText').children().
                 css({ 'opacity' : 1 }).
                 end().
                 css({ 'opacity' : 1 });
          
          //Show Initial Image
          ShowText("accountancyButton");

          
             $(document).bind("idle.idleTimer",  function(){
         $(document).idleTimer(5000);
         BeginSlideShow();
});


         $(document).bind("active.idleTimer", function(){
            cancelled = true;

});
//Set Idle Timeout so we can begin SlideShow/
         $(document).idleTimer(5000);

         }

         function ShowText(buttonId)
         {
            var imgTextUrl;  
            
             $(".hoverButton").children().
                 css({ 'opacity' : 1 }).
                 end().
                 css({ 'opacity' : 1 });


            $(".bigImage").stop(true, true);

            $('#imgText').stop(true,true);

            $('#imgText').children().
                     css({ 'opacity' : 0 }).
                     end().
                     css({ 'opacity' : 0 });


            $('#imgText').css('margin-top','40px');



            $(".bigImage").animate({
                opacity: 0
            },
                    1000,
                    'linear',
                    new function AnimateComplete() { }

                    );


            switch(buttonId)
            {
                case "officeButton":

                    imgTextUrl = "url(App_Themes/Default/images/home/large_office_strap.png)";


                    $("#officeImage").stop(true, true);

                    $("#officeImage").animate({
                        opacity: 1
                    },
                    1000,
                    'linear',
                    new function AnimateComplete() { HideButton(buttonId,imgTextUrl); }

                    );


                    currentImage = "officeImage";
                    break;
                     case "humanResourcesButton":

                       imgTextUrl = "url(App_Themes/Default/images/home/large_hr_strap.png)";
                       
                       $("#hrImage").stop(true,true);

                     $("#hrImage").animate({
                    opacity:1},
                    1000,
                    'linear',
                    new function AnimateComplete(){HideButton(buttonId,imgTextUrl);}
                    
                    );


                    currentImage = "hrImage";
                    break;
                     case "financialButton":
                
                     imgTextUrl = "url(App_Themes/Default/images/home/large_fs_strap.png)";


                      $("#fsImage").stop(true,true);

                     $("#fsImage").animate({
                    opacity:1},
                    1000,
                    'linear',
                    new function AnimateComplete(){HideButton(buttonId,imgTextUrl);}
                    
                    );
                     currentImage = "fsImage";
           
                    break;
                case "accountancyButton":

                    imgTextUrl = "url(App_Themes/Default/images/home/large_acc_strap.png)";

                    $("#accImage").stop(true, true);

                    $("#accImage").animate({
                        opacity: 1
                    },
                    1000,
                    'linear',
                    new function AnimateComplete() { HideButton(buttonId,imgTextUrl); }

                    );

                    currentImage = "accImage";

                    break;
            }


         
         }
        
        function HideButton(id,imageUrl)
        {
          $("#" + id).children().
                 css({ 'opacity' : 0 }).
                 end().
                 css({ 'opacity': 0 });

          $('#imgText').delay(1000).css("background-image", imageUrl).css('margin-top','40px').animate({
                 opacity: 1,
                 marginTop : '-=20px',

             }, 1500, function () {
                 // Animation complete.
             });



        }
     

