/****************************/
/******** © leamix **********/
/****** x8p@leamix.com ******/
/****************************/
var Menuscroll = function (menuId, itemId, hEnding, cEnding, hHoverClass, hOpenedClass, opened)
{
	var theHeaders = [];
	var theContainers = [];
	var whichOpened = null;
	
	var hRegExp = new RegExp("^"+itemId+"([0-9]+)"+hEnding+"$");
	var cRegExp = new RegExp("^"+itemId+"([0-9]+)"+cEnding+"$");
	
	var allDivs = X.$Tags('div', menuId);
	
	for (var i = 0, len = allDivs.length; i < len; i++)
	{
		var cDiv = allDivs[i]; 
		var tmp = cDiv.id + "";
		
		if (hRegExp.test(tmp))
		{	
			cDiv.headerNum = theHeaders.length;
			cDiv.onclick = function () { msHeaderClick(this.headerNum); };
			
			if (hHoverClass)
			{
				cDiv.onmouseover = function() { if (this.headerNum != whichOpened) Blocks.setClass(this, hHoverClass); }
				cDiv.onmouseout = function() { if (this.headerNum != whichOpened) Blocks.returnClass(this); }
			}
			
			theHeaders.push(cDiv);					
		}
		else if (cRegExp.test(tmp))
		{
			theContainers.push(cDiv);
			if (!Blocks.isHidden(cDiv))
				Blocks.hide(cDiv);
		}
	}
	
	if (opened !== false) msOpen(opened);
	
	function msOpen (containerNum)
	{
		if (whichOpened !== null) 
			msClose(whichOpened);
		whichOpened = containerNum;
		Blocks.show(theContainers[containerNum], "block");
		Blocks.setClass(theHeaders[containerNum], hOpenedClass);
	}
	
	function msClose (containerNum)
	{
		whichOpened = null;
		Blocks.hide(theContainers[containerNum]);
		Blocks.returnClass(theHeaders[containerNum]);
	}
	
	function msHeaderClick (containerNum)
	{
		if (containerNum !== whichOpened)
			msOpen(containerNum);
		else
			msClose(containerNum);
	}
}
