/***

|Name|ToggleSideBarMacro|
|Created by|SaqImtiaz|
|Location|http://tw.lewcid.org/#ToggleSideBarMacro|
|Version|1.0|
|Requires|~TW2.x|
!Description:
Provides a button for toggling visibility of the SideBar. You can choose whether the SideBar should initially be hidden or displayed.

!Demo
<<toggleSideBar "Toggle Sidebar">>

!Usage:
{{{<<toggleSideBar>>}}} <<toggleSideBar>>
additional options:
{{{<<toggleSideBar label tooltip show/hide>>}}} where:
label = custom label for the button,
tooltip = custom tooltip for the button,
show/hide = use one or the other, determines whether the sidebar is shown at first or not.
(default is to show the sidebar)

You can add it to your tiddler toolbar, your MainMenu, or where you like really.
If you are using a horizontal MainMenu and want the button to be right aligned, put the following in your StyleSheet:
{{{ .HideSideBarButton {float:right;} }}}

!History
*23-07-06: version 1.0: completely rewritten, now works with custom stylesheets too, and easier to customize start behaviour. 
*20-07-06: version 0.11
*27-04-06: version 0.1: working.

!Code
***/
//{{{
config.macros.toggleColumnist={};

config.macros.toggleColumnist.settings={
         styleHide :  "#columnistContainer{display:none;}\n"+"#contentWrapper #displayArea { margin-left: 1em;}\n"+"",
         styleShow : " ",
         arrow1: "→",
         arrow2: "←"
};

config.macros.toggleColumnist.handler=function (place,macroName,params,wikifier,paramString,tiddler)
{
          var tooltip= params[1]||'toggle Columnist';
          var mode = (params[2] && params[2]=="hide")? "hide":"show";
          var arrow = (mode == "hide")? this.settings.arrow1:this.settings.arrow2;
          var label= (params[0]&&params[0]!='.')?params[0]+" "+arrow:arrow;
          var theBtn = createTiddlyButton(place,label,tooltip,this.ontoggleColumnist,"button HideColumnistButton");
          if (mode == "hide")
             { 
             (document.getElementById("columnistContainer")).setAttribute("toggle","hide");
              setStylesheet(this.settings.styleHide,"toggleColumnistStyles");
             }
};

config.macros.toggleColumnist.ontoggleColumnist = function(){
          var Columnist = document.getElementById("columnistContainer");
          var settings = config.macros.toggleColumnist.settings;
          if (Columnist.getAttribute("toggle")=='hide')
             {
              setStylesheet(settings.styleShow,"toggleColumnistStyles");
              Columnist.setAttribute("toggle","show");
              this.firstChild.data= (this.firstChild.data).replace(settings.arrow1,settings.arrow2);
              }
          else
              {    
               setStylesheet(settings.styleHide,"toggleColumnistStyles");
               Columnist.setAttribute("toggle","hide");
               this.firstChild.data= (this.firstChild.data).replace(settings.arrow2,settings.arrow1);
              }

     return false;
}

setStylesheet(".HideColumnistButton .button {font-weight:bold; padding: 0 5px;}\n","toggleColumnistButtonStyles");

//}}}