Sections = {
    ClosedSections: new Array(),
    Initialising: false,
    CookieName: "HomeSections",
   
    Toggle: function(sectionID) {
        var section = document.getElementById('Section_'+sectionID);
        var toggler = document.getElementById('Toggler_'+sectionID);
      if(section && toggler) {
        toggler.blur();
        if(toggler.className == "toggler-hide" && section.style.display == "") {
            toggler.className = "toggler-show";
            toggler.innerHTML = "Show";
            if(!section.OriginalHeight) {
                section.OriginalHeight = section.offsetHeight;
            }
            if(this.Initialising) {
            section.style.height = "0";
            } else {
            section.Animate = new Animator({duration: 500});
            section.Animate.addSubject(new NumericalStyleSubject(section, 'height', section.offsetHeight, 0));
            section.Animate.seekTo(1);
            }
            this.ClosedSections.push(sectionID);
        } else {
            toggler.className = "toggler-hide";
            toggler.innerHTML = "Hide";
            if(this.Initialising) {
            section.style.height = section.OriginalHeight+"px";
            } else {
            section.Animate = new Animator({duration: 500});
            section.Animate.addSubject(new NumericalStyleSubject(section, 'height',0,section.OriginalHeight));
            section.Animate.seekTo(1);
            }
            var i = 0;
            while(i < this.ClosedSections.length) {
                if(this.ClosedSections[i] == sectionID) {
                    this.ClosedSections.splice(i,1);
                } else {
                    i++;
                }
            }
        }
        if(!this.Initialising) {
            Sections.SaveState();
        }
        }
        return false;
    },
    Init: function() {
    Cookie = Sections.Cookies.Get(this.CookieName);
    if(Cookie!= null) {
            Cookie = Cookie.split(",");
            this.Initialising = true;
            for(i = 0; i < Cookie.length; i++) {
                this.Toggle(Cookie[i]);
            }
            this.Initialising = false;
       }
    },
    SaveState: function() {
        if(this.ClosedSections.length > 0) {
        Sections.Cookies.Add(this.CookieName,this.ClosedSections.join());
        } else if(Sections.Cookies.Get(this.CookieName)) {
        Sections.Cookies.Delete(this.CookieName);
        }
    }
}

Sections.Cookies = {
    Add: function( name, value, expires, path, domain, secure ) 
    {
        var today = new Date();
        today.setTime( today.getTime() );
        if ( expires )
        {
             expires = expires * 1000 * 60 * 60 * 24;
        }
        var expires_date = new Date( today.getTime() + (expires) );

        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
    },
    Get: function( name ) {
        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) &&
        ( name != document.cookie.substring( 0, name.length ) ) )
        {
        return null;
        }
        if ( start == -1 ) return null;
        var end = document.cookie.indexOf( ";", len );
        if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
    },
    Delete: function( name, path, domain ) {
        if ( this.Get( name ) ) document.cookie = name + "=" +
        ( ( path ) ? ";path=" + path : "") +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}

