// An show/hide object - like a header. Added for colapsible news fader. We hope.
function smfToggle(uniqueId, initialState)
{
   this.uid = uniqueId;
   this.state = initialState;
   this.use_cookie = 0;
   // Needed for setting theme options - kept hidden!
   var themeOptions = Array(5);
   themeOptions[0] = null;
   this.useCookie = useCookie;
   this.toggle = toggleHeader;
   this.setOptions = setOptions;
   this.imageToggles = new Array();
   this.panelToggles = new Array();
   this.addToggleImage = addToggleImage;
   this.addTogglePanel = addTogglePanel;

   // Should the shrinker use a cookie?
   function useCookie(mode)
   {
      this.use_cookie = mode ? 1 : 0;
   }

   // Actually shrink the header!
   function toggleHeader(mode)
   {
      // Just a toggle?
      if (mode == null)
         mode = !this.state;

      // Do we need to set a cookie?
      if (this.use_cookie)
         document.cookie = this.uid + '=' + (mode ? 1 : 0);

      // Set a theme option?
      if (themeOptions[0] != null)
      {
         var curMode = themeOptions[2] ? !mode : mode;
         smf_setThemeOption(themeOptions[0], curMode ? 1 : 0, themeOptions[3] == 0 ? null : themeOptions[3], themeOptions[1], themeOptions[4]);
      }

      // Toggle the images.
      var x = 0;
      for (x = 0; x < this.imageToggles.length; x++)
      {
         var curImage = document.getElementById(this.imageToggles[x][0]);
         if (curImage)
            curImage.src = mode ? this.imageToggles[x][2] : this.imageToggles[x][1];
      }

      // Now toggle the panels.
      for (x = 0; x < this.panelToggles.length; x++)
      {
         // Inverse?
         var curMode = this.panelToggles[x][1] ? !mode : mode;
         var curPanel = document.getElementById(this.panelToggles[x][0]);
         if (curPanel)
            curPanel.style.display = curMode ? "none" : "";
      }

      this.state = mode;
   }

   // Set the theme option that should change with this.
   function setOptions(newThemeOptions, sessID, flip, themeID, preferenceKey)
   {
      themeOptions[0] = newThemeOptions;
      themeOptions[1] = sessID;
      themeOptions[2] = flip == null ? 0 : 1;
      themeOptions[3] = themeID == null ? 0 : themeID;
      themeOptions[4] = preferenceKey == null ? '' : ';admin_key=' + preferenceKey;
   }

   // Add an image to toggle (id, mode = 0 image, mode = 1 image)
   function addToggleImage(imageID, mode0Image, mode1Image, useImagePath)
   {
      var curIndex = this.imageToggles.length;
      this.imageToggles[curIndex] = Array(3);
      this.imageToggles[curIndex][0] = imageID;
      this.imageToggles[curIndex][1] = (useImagePath == null ? smf_images_url : '') + mode0Image;
      this.imageToggles[curIndex][2] = (useImagePath == null ? smf_images_url : '') + mode1Image;
   }

   // Add a panel which should toggle with the header.
   function addTogglePanel(panelID, flip)
   {
      var curIndex = this.panelToggles.length;
      this.panelToggles[curIndex] = Array(2);
      this.panelToggles[curIndex][0] = panelID;
      this.panelToggles[curIndex][1] = flip == null ? 0 : 1;
   }
}
