//////////////////////////////////////////////
// Kasseler CMS: Content Management System  //
// ===========================              //
// Copyright (c)2007-2008 by Igor Ognichenko//
// http://www.kasseler-cms.net/             //
//////////////////////////////////////////////

function switchcontent(id){
    this.id = id;
    this.show = true;
    this.replaceTitle = false;
    this.title = document.getElementById(this.id + '-title');
    this.content = document.getElementById(this.id);
    this.TitleShow = 'show';
    this.TitleHide = 'hide';

    this.setCookie = function(name, value, expires, path, domain, secure){
        document.cookie = name + "=" + escape(value) +
            ((expires) ? "; expires=" + expires : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
    };

    this.getCookie = function(name){
        var cookie = " " + document.cookie;
        var search = " " + name + "=";
        var setStr = null;
        var offset = 0;
        var end = 0;
        if (cookie.length > 0) {
            offset = cookie.indexOf(search);
            if (offset != -1) {
                offset += search.length;
                end = cookie.indexOf(";", offset)
                if (end == -1) end = cookie.length;
                setStr = unescape(cookie.substring(offset, end));
            }
        }
    return(setStr);
    };

    this.init = function(){
        if(!this.title) return false;
        var tself = this;
        if(this.title) this.title.style.cursor = 'pointer';
        var cook = this.getCookie(this.id);
        if (this.show == false && cook!='show') this.content.style.display = 'none'
        if (cook=='hide') this.content.style.display = 'none'
        if (this.replaceTitle == true && cook=='null' && this.show == true) this.title.innerHTML = this.TitleShow;
        if (this.replaceTitle == true && cook=='null' && this.show == fasle) this.title.innerHTML = this.TitleHide;
        if (this.replaceTitle == true && cook=='hide') this.title.innerHTML = this.TitleHide;
        if (this.replaceTitle == true && cook=='show') this.title.innerHTML = this.TitleShow;
        if(this.title) this.title.onclick = function(){
            if (tself.content.style.display == 'none'){
                 tself.setCookie(tself.id, 'show');
	         tself.content.style.display = 'block';
	         if (tself.replaceTitle == true) tself.title.innerHTML = tself.TitleShow;
	    } else {
	         tself.content.style.display = 'none';
	         tself.setCookie(tself.id, 'hide');
	         if (tself.replaceTitle == true) tself.title.innerHTML = tself.TitleHide;
	    }
	    return false;
        } 
    };
}
