﻿      var tabCurrentTab;
      var tabPreviousTab;
      var tabScrollDistance = 300;
      var tabScrollDelay = 750;
      var tabStartTab = 0;
      
      $(document).ready(function() { SetupPage(); });



      function SetupPage() {

          //Init Tabs  
          InitializeTabs();

          $(".Tab-Container .Tab").corner("6px");
          $("#Tab-Content-Container").corner("8px bl br");
          

          $(".Tab").hover
            (
                  function() { HiliteTab(this); }
                , function() { DeHiliteTab(this); }
            ).click
            (
                function() { SelectTab(this); }
            )

      } // SetupPage




      function CreateTabs() {

          //create the tab strip
          $("#Tabs").append(tabStrip.Render());

          //fade in the main canvas, and call the begin function();          
          $("#Inner-Content-Container").fadeIn("slow", function() { Begin(!isPageInDevelopment); });

      } // CreatTabs
      
      
      
      
      function Begin(loadTab){

          if (loadTab) {
              var obj = document.getElementById(tabStrip.tabs[tabStartTab].id);
              DoSelectTab(obj);
          }//if
      
      }// Begin
      
      
      
      
//      function DoSelectTabFunction(obj) {
//          
//          //reference the current tab
//          tabCurrentTab = tabStrip.tabsByName[obj.id];          
//          
//          //Do not change the tab if it is the same one
//          if( tabPreviousTab == null || tabCurrentTab.id != tabPreviousTab.id ){
//             
//              ShowLoader();
//             
//             //Call specific functions related to the tab 
//              switch (tabCurrentTab.id) {
//              
//                  case "Tab-Identify":
//                      {
//                          //tabStrip.tabs[1].Disable();
//                      }// case
//                   case "Tab-Join":
//                   {
//                        try
//                        {
//                            FillInCompanyInformation();
//                        }catch( er ){}
//                                            
//                        break;
//                   }
//                      
//              }//switch
//              
//              
//              LoadTabContent();
//          }// if
//          
//      }// DoSelectTabFunction        
//      
      
      var isLoading = false;
      
      //If the div does not exist, then create one to match the tab name, add it to the tabs div.
      function LoadTabContent(){
        
            if( isLoading == false ){
            
                isLoading = true;
                
                var obj = $("#Tab-Content-" + tabCurrentTab.id );
                
                if( obj.html() == null ){                
                   //the tab doesnt exist, so load it
                   LoadContent( tabCurrentTab.contentLocation );
                }else{
                    //It already exists and the content is loaded.
                    SwapTabContent();
                }//if        
                     
           }//if( isLoading )
        
      }//ContentLoadedB
      
      
      
        
      function LoadContent( page ){
        
        $.ajax
            ({
              url: page,
              cache: false,
              success: function(html){ ContentLoaded(html); }
            });
 
      }// LoadContent   
      
      
      
        
      function ContentLoaded( html ){
        
        
        var title = $("#Header", html).html();
        var content = $("#Content", html).html();        
        
        //create a new content div, get the tabs object
        var newTab = "<div id=\"Tab-Content-" + tabCurrentTab.id + "\" class=\"Tab-Content-Container Position-Absolute\"></div>";
        $("#Tab-Content").append( newTab );
        var contentTab = $("#Tab-Content-" + tabCurrentTab.id);
        contentTab.html(content);
        contentTab.hide();
        //contentTab.css("opacity", "0");
        //contentTab.css("left", tabScrollDistance);
        
            
        var titleTab = "<div id=\"Tab-Title-" + tabCurrentTab.id + "\" class=\"Tab-Title\"></div>";
        $("#Title-Container").append(titleTab);
        var titleObj = $("#Tab-Title-" + tabCurrentTab.id );
        titleObj.html(title);       
        titleObj.css( "opacity", "0");
        
        SwapTabContent();
        
      }//ContentLoaded
      
      //----------------------------------------------------------------------------------------------
      


      
      
      
      //---------------------------------------------------------------------------------------------------
      
      
      function SwapTabContent(){
      
        if( tabPreviousTab != null ){
        
            var titleObj = $("#Tab-Title-" + tabCurrentTab.id);
            var titleObjPrevious = $("#Tab-Title-" + tabPreviousTab.id);
            var contentTab = $("#Tab-Content-" + tabCurrentTab.id);
            var contentPreviousTab = $("#Tab-Content-" + tabPreviousTab.id);
            
            //determine the way to show the object
            var currentTabIndex =  tabStrip.tabsByName[tabCurrentTab.id].index;
            var previousTabIndex =  tabStrip.tabsByName[tabPreviousTab.id].index;
            
            var currentContentTabLeft = "0";
            var previousContentTabLeft = "-" + tabScrollDistance + "px";
            
            if( previousTabIndex != null && currentTabIndex < previousTabIndex ){
                
                currentContentTabLeft = "0";
                previousContentTabLeft = tabScrollDistance + "px";
                                
            }//if
            
            titleObj.animate( { bottom:"0", opacity:"1" });
            titleObjPrevious.animate( { bottom:"-77", opacity:"0" });

            //contentTab.show();
            //contentTab.animate({ left: currentContentTabLeft, opacity: "1" }, tabScrollDelay, function() { contentTab.removeClass("Position-Absolute"); });
            //contentPreviousTab.addClass("Position-Absolute");
            //contentPreviousTab.animate({ left: previousContentTabLeft, opacity: "0" }, tabScrollDelay, function() { contentPreviousTab.hide(); });
            
            contentPreviousTab.addClass("Position-Absolute");
            contentTab.removeClass("Position-Absolute");            
            contentTab.css( "top", "0px" );
                        
            contentPreviousTab.fadeOut(500);
            contentTab.fadeIn(500);
            
            
            
            

        }else{
            //there is no previous content being shown, so show the title
            var titleObj = $("#Tab-Title-" + tabCurrentTab.id);
            titleObj.animate( { bottom:"0", opacity:"1" });        
            
            var contentTab = $("#Tab-Content-" + tabCurrentTab.id);
            //contentTab.animate({ left: "0", opacity: "1" });
            contentTab.fadeIn(500);
            
            contentTab.removeClass("Position-Absolute");
            
        }//if  
        
        HideLoader();
        
        tabPreviousTab = tabCurrentTab;
        
        //set isloading swtich to false
        isLoading = false;
        
      }//SwapTabContent


         
      
      function ShowLoader(){
        $(".Loading-Container").show();
      }//ShowLoader()
      
      
      
      
      function HideLoader(){
        $(".Loading-Container").fadeOut();
      }//HideLoader()
      
    