//**********************
// Toggler Constructor *
//**********************
function Toggler()
{	
	// get id's
	this.page	= document.getElementById('page');
	
	// set strings
	this.box_toggler_in_normal_class	= 'box_toggler_in_normal';
	this.box_toggler_in_hover_class		= 'box_toggler_in_hover';
	this.box_toggler_out_normal_class	= 'box_toggler_out_normal';
	this.box_toggler_out_hover_class	= 'box_toggler_out_hover';
	this.active_class					= 'active';
	this.show_class						= 'show';
	this.hide_class						= 'hide';
	
	// initialize object
	this.init();
}

//*******************************
// Function initialize togglers *
//*******************************
Toggler.prototype.init = function()
{
	// check for all box togglers
	var toggler_elements	= this.page.getElementsByTagName('span');
	
	if (toggler_elements.length > 0)
	{
		for (var a=0; a<toggler_elements.length; a++)
		{
			var toggler_element	= toggler_elements[a];
			
			// add events to box toggler
			if (toggler_element.className == this.box_toggler_in_normal_class || toggler_element.className == this.box_toggler_out_normal_class)
			{
				this.events(toggler_element);
			}
		}
	}
}

//**************************
// Function toggler events *
//**************************
Toggler.prototype.events = function(obj)
{
	// set object to var
	var _this = this;
	
	// hover event
	obj.onmouseover = function()
	{
		if (this.className == _this.box_toggler_in_normal_class)
		{
			this.className	= _this.box_toggler_in_hover_class;
		}
		else
		{
			this.className	= _this.box_toggler_out_hover_class;
		}
	}
	
	// mouseout event
	obj.onmouseout = function()
	{
		if (this.className == _this.box_toggler_in_hover_class)
		{
			this.className	= _this.box_toggler_in_normal_class;
		}
		else
		{
			this.className	= _this.box_toggler_out_normal_class;
		}
	}
	
	// click event
	obj.onclick = function()
	{
		// execute the toggler
		_this.execute(this);
	}
}

//***************************
// Function execute toggler *
//***************************
Toggler.prototype.execute = function(obj)
{
	// set object to var
	var _this = this;
	
	// set some vars
	var objWrapper	= obj.parentNode.parentNode;
	var objParent	= obj.parentNode;
	var saveNext	= false;
	var objSelected	= null;
	
	// get the right box to toggle
	for(var a=0; a<objWrapper.childNodes.length;a++)
	{
		var node = objWrapper.childNodes[a];
		
		// exclude textnodes (mozilla)
		if (node.nodeType != 3)
		{
			if (saveNext == true)
			{
				objSelected = node;
				saveNext = false;
			}
			if (node == objParent)
			{
				saveNext = true;
			}
		}
	}
	
	// execute the toggler
	if (obj.className == _this.box_toggler_in_hover_class)
	{
		// set icon
		obj.className	= _this.box_toggler_out_hover_class;
		
		// show box items
		var list_items	= objSelected.getElementsByTagName('li');
		for(var b=0; b<list_items.length;b++)
		{
			var list_item	= list_items[b];
			if (list_item.className == _this.hide_class)
			{
				list_item.className = _this.show_class;
			}
		}
	}
	else
	{
		// set icon
		obj.className	= _this.box_toggler_in_hover_class;
		
		// hide box items
		var list_items	= objSelected.getElementsByTagName('li');
		for(var b=0; b<list_items.length;b++)
		{
			var list_item	= list_items[b];
			if (list_item.className == _this.show_class)
			{
				list_item.className = _this.hide_class;
			}
		}
	}
}