
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel = {};
//////////////////////////////////////////////////////////////////////////////////////////////////////////// #START# MAIN MENU #START#
Cattel.PROTO_MainMenu = function(){
	////////////////////////////////////
	this.Items0 = new Array();
	this.Items1 = new Array();
	this.Items2 = new Array();
	this.closeTimer = null;
	////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel.PROTO_MainMenu.prototype.Init = function(){
	////////////////////////////////////
	this.MMenu0 = document.getElementById("mmenu0");
	this.MMenu1 = document.getElementById("mmenu1");
	////////////////////////////////////
	var InnerHTML = this.MMenu0.innerHTML;
	for( var i=0; i<this.Items0.length; i++ ){
		InnerHTML += this.Items0[i].HTML;
	} 
	this.MMenu0.innerHTML = InnerHTML;
	////////////////////////////////////
	if( this.MMenu1 ){
		InnerHTML = this.MMenu1.innerHTML;
		for( var j=0; j<this.Items1.length; j++ ){
			var ID = this.Items1[j].ID;
			InnerHTML += this.Items1[j].HTML1;
			if( this.Items2[ID].length>0 ){
				InnerHTML += '  <div class="mn1_2_tendina" id="CMMtendina'+ID+'" style="display:block;">' + '\n';
				InnerHTML +=  this.Items2[ID].join("\n") + '\n';
				InnerHTML += '  </div>' + '\n';
			}
			InnerHTML += this.Items1[j].HTML2;
		}
		////////////////////////////////////
		this.MMenu1.innerHTML = InnerHTML;
		this.Close();
		////////////////////////////////////
		var w = 0;
		for( var j=0; j<this.Items1.length; j++ ){
			var Item = document.getElementById('CMMitem'+this.Items1[j].ID);
			this.addItemEvent(this.Items1[j].ID);
			w += Item.offsetWidth;
		}
		if( this.Items1.length>0 ){
			var pLeft = Math.floor((this.MMenu1.offsetWidth-w)/2);
			var Item = document.getElementById('CMMitem'+this.Items1[0].ID);
			Item.style.paddingLeft = pLeft+'px';
		}
		////////////////////////////////////
	}
	////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel.PROTO_MainMenu.prototype.addItem = function( n, xId, xMaster, xLink, xTitle, xText, xSel, xTarget, xLast ){
	////////////////////////////////////
	var ItemHTML = '';
	if( n==0 ){
		////////////////////////////////////
		ItemHTML =  '<div class="mn1_0_item'+xSel+'">' + '\n';
		ItemHTML += '  <a href="'+xLink+'" class="mn1_0_link'+xSel+'" title="'+xTitle+'" '+xTarget+'><b>'+xText+'</b></a>' + '\n';
		ItemHTML += '  <div class="mn1_0_item'+xLast+'"></div>' + '\n';
		ItemHTML += '</div>' + '\n';
		this.Items0.push( new Object({ ID:xId, HTML:ItemHTML }) );
		////////////////////////////////////
	} else if( n==1 ){
		////////////////////////////////////
		var ItemHTML1 = '  <div class="mn1_1_item" id="CMMitem'+xId+'">' + '\n';
		var ItemHTML2 = '  <a href="'+xLink+'" class="mn1_1_link'+xSel+'" title="'+xTitle+'" '+xTarget+'><b>' + xText + '</b></a>' + '\n' + '</div>' + '\n';
		this.Items1.push( new Object({ ID:xId, HTML1:ItemHTML1, HTML2:ItemHTML2 }) );
		this.Items2[xId] = new Array();
		////////////////////////////////////
	} else {
		////////////////////////////////////
		var Master = xMaster.split(",");
		var Ind = 'k'+Master[3];
		ItemHTML =  '  <div class="mn1_2_item'+xLast+'">' + '\n';
		ItemHTML += '    <a href="'+xLink+'" class="mn1_2_link'+xSel+'" title="'+xTitle+'" '+xTarget+'><b>'+xText+'</b></a>' + '\n';
		ItemHTML += '  </div>' + '\n';
		this.Items2[Ind].push( ItemHTML );
		////////////////////////////////////
	}
	////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel.PROTO_MainMenu.prototype.addItemEvent = function( ID ){
	////////////////////////////////////
	var tgT = document.getElementById('CMMitem'+ID);
	var _Self = this;
	this.Event( tgT, 'mouseover', function(){	
			_Self.TimerEnd( ID );
			_Self.Open( ID, true );
		}, false);
	this.Event( tgT, 'mouseout', function(){
			_Self.TimerInit( ID );
		}, false);
	////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel.PROTO_MainMenu.prototype.Open = function( ID, isOpen ){
	this.Close();
	this.Show( ID, ((isOpen==true)?'':'none') );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel.PROTO_MainMenu.prototype.Close = function(){
	for( var j=0; j<this.Items1.length; j++ ){
		var ID = this.Items1[j].ID;
		this.Show( ID, 'none' );
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel.PROTO_MainMenu.prototype.TimerInit = function( ID ){
	var _Self = this;
	this.closeTimer = window.setTimeout(function(){ 
		_Self.Close(); 
	}, 500);
}	
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel.PROTO_MainMenu.prototype.TimerEnd = function( ID ){
	clearTimeout( this.closeTimer );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel.PROTO_MainMenu.prototype.Show = function( ID, show ){

	var tgTendina = document.getElementById( "CMMtendina" + ID );
	if( tgTendina ){
		if( show=='none' || tgTendina.innerHTML=='' ){
			tgTendina.style.display = 'none';
		} else {
			tgTendina.style.display = '';
		}
	}

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Cattel.PROTO_MainMenu.prototype.Event = function( element, eventType, handler, capture ){
	//////////////////////////////////// 
	try	{
		if( element.addEventListener ){
			element.addEventListener(eventType, handler, capture);
		}	else if( element.attachEvent ){
			element.attachEvent('on' + eventType, handler);
		} else {
			alert("Unsupported method [CattelMenu_Event]!" + "\n" + handler)
			return;
		}
		return handler;
	}
	//////////////////////////////////// 
	catch (e) {  alert('Cattel Menu Event Error [' + element + ']' + "\n" + e + "\n" + handler );  }
	//////////////////////////////////// 
}


/*
var startMenuInd = -1;
var closeTimer = null;
//////////////////////////////////// 
function CattelMenu_Open( n, isOpen ){
	CattelMenu_Close();
	CattelMenu_Show( n, ((isOpen==true)?'':'none') );
}
//////////////////////////////////// 
function CattelMenu_Close(){
	for( i=0; i<6; i++ ){
		CattelMenu_Show( i, 'none' );
	}
}
//////////////////////////////////// 
function CattelMenu_TimerInit( n ){
	closeTimer = window.setTimeout(function(){ 
		CattelMenu_Close(); 
	}, 500);
}	
function CattelMenu_TimerEnd( n ){
	clearTimeout( closeTimer );
}
//////////////////////////////////// 
function CattelMenu_Show( n, show ){
	var tgTendina = document.getElementById( "MMenu" + n );
	if( tgTendina ){
		if( show=='none' || tgTendina.innerHTML=='' ){
			tgTendina.style.display = 'none';
		} else {
			tgTendina.style.display = '';
			var tgBt = document.getElementById( "MMtendina" + n );
			var P = new Array( tgBt.offsetLeft+1, tgBt.offsetTop );		
			P = CattelMenu_Offset( tgBt, P );
			tgTendina.style.left = P[0] + 'px';
		
			
			if( P[1]<500 ){
				tgTendina.style.top = P[1] + 'px';	
				tgTendina.style.padding = '20px 0px 5px 0px';										
				
				if (tgTendina == document.getElementById( "MMenu1" )){
					tgTendina.style.padding = '10px 0px';
				}
				
			} else {
			
				tgTendina.style.top = P[1]-tgTendina.offsetHeight+15 + 'px';										
			}
			
		}
	}
}
//////////////////////////////////// 
function CattelMenu_Sub( Tsel, Ttext, Tlink, Tmaster ){
	////////////////////////////////////
	var tgBt = document.getElementById( "MMtendina" + (startMenuInd+1) );
	var myInd = (startMenuInd+1);
	if( tgBt ){
		//////////////////////////////////// 
		CattelMenu_Event( tgBt, 'mouseover', function(){	
				CattelMenu_TimerEnd( myInd );
				CattelMenu_Open( myInd, true );
			}, false);
		CattelMenu_Event( tgBt, 'mouseover', function(){
				CattelMenu_TimerEnd( myInd );
			}, false);
		CattelMenu_Event( tgBt, 'mouseout', function(){
				CattelMenu_TimerInit( myInd );
			}, false);
		//////////////////////////////////// 
		if( Tmaster!='0,1,30' ){	
			tgBt.innerHTML = Ttext;
		}
	}
	////////////////////////////////////
	var tgTendina = document.getElementById( "MMenu" + startMenuInd );
	var strTendina = '';
	if( tgTendina ){
		for(var i=0; i<arrMn.length; i++ ){	
			strTendina += '<div class="menu1_2_0item' + arrMn[i].Sel + '"';
			strTendina += ' onMouseOver="javascript:CattelMenu_TimerEnd(' + myInd + ')"';
			strTendina += ' onMouseOut="javascript:CattelMenu_TimerInit(' + myInd + ')"';
			strTendina += '><a href="' + arrMn[i].Link + '" class="menu1_2_1' + arrMn[i].Sel + '"';
			strTendina += '>' + arrMn[i].Text + '</a></div>';
		}
		tgTendina.innerHTML = strTendina + tgTendina.innerHTML;
	}
	//////////////////////////////////// 
	arrMn = new Array();
	startMenuInd += 1;
	//////////////////////////////////// 
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
CattelMenu_Event = function( element, eventType, handler, capture ){
	//////////////////////////////////// 
	try	{
		if( element.addEventListener ){
			element.addEventListener(eventType, handler, capture);
		}	else if( element.attachEvent ){
			element.attachEvent('on' + eventType, handler);
		} else {
			alert("Unsupported method [CattelMenu_Event]!" + "\n" + handler)
			return;
		}
		return handler;
	}
	//////////////////////////////////// 
	catch (e) {  alert('CattelMenu_Event Error [' + element + ']' + "\n" + e + "\n" + handler );  }
	//////////////////////////////////// 
}
//////////////////////////////////// 
function CattelMenu_Offset( xTg, xPos ){
	if( xTg.offsetParent!=null ){
		xPos[0] += xTg.offsetParent.offsetLeft; xPos[1] += xTg.offsetParent.offsetTop;
		xPos = CattelMenu_Offset( xTg.offsetParent, xPos );
	}
	return xPos ;
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////
