function switcher(objectName, initState)
{
	Object.extend(this, new myEvent());

	this.objectName	= objectName;
	this.state		= initState;

	this.isInit		= 0;
	this.cookie		= 'sw_'+this.objectName;
}

/** 
*	Initialize switcher object
*/
switcher.prototype.init = function()
{
	this.isInit = 1;
}

/** 
*	Switch state
*/
switcher.prototype.turn = function()
{
	if (parseInt(this.state))
	{
		this.off();
	}
	else
	{
		this.on();
	}
}

/** 
*	On
*/
switcher.prototype.on = function()
{
	this._setState(1);
}

/** 
*	Off
*/
switcher.prototype.off = function()
{
	this._setState(0);
}

//** Implementation

switcher.prototype._setState = function(value)
{
	if (!this.isInit)
		return;

	this.state = value;

	if (this.cookie)
		document.cookie = this.cookie+"="+value+"; expires=Fri, 31 Dec 2030 23:59:59 GMT;";

	if (this.state)
		this.notify('eOn');
	else
		this.notify('eOff');		
	
}


function _switch(on, off, tabPrefix)
{
	if( E(on).innerHTML.match(/^\s*<span.*?>(\S+)<\/span>\s*$/i) )
	{
		var url = RegExp.$1.replace(/&amp;/g,'&');
		var indicator = ' <img src="/img/ajax/tiny_red.gif" alt="" /> ';

		var tab = E(tabPrefix+on).firstChild;
		while (tab && tab.nodeType != 1) tab = tab.nextSibling;
		tab.innerHTML += indicator;

		ajaxLoadText({
			url:url,
			forse:1,
			onready:function( text )
			{
				E(on).innerHTML = text;
				evalJS(text, function(){
					combyOnLoad(1);
					_switch(on,off,tabPrefix);
				});
				E(on).className			= 'active';
				E(off).className		= 'disable';
				E(tabPrefix+on).className	= 'active';
				E(tabPrefix+off).className	= 'disable';
				var len = tab.innerHTML.length;
				tab.innerHTML = tab.innerHTML.substr(0, len-indicator.length+2);
			}
		});
	}else{
				E(on).className			= 'active';
				E(off).className		= 'disable';
				E(tabPrefix+on).className	= 'active';
				E(tabPrefix+off).className	= 'disable';
				E(on).style.visibility 		= "visible";
				E(off).style.visibility 	= "visible";
	}
	return false;
}

function tabSwitcher (tabPrefix, boxPrefix, tabCount, selectedTab){
	for(i=0;i<tabCount;i++){
			E(tabPrefix+i).className		= 'disable';
			E(boxPrefix+i).className	= 'disable';
	}
	E(tabPrefix+selectedTab).className = 'active';
	E(boxPrefix+selectedTab).className = 'active';
	return false;
}
