///////////////////////////////////////////////////////////////////////////////////////
/////////           Cap Gemini Ernst & Young Italia S.p.A.                        /////
/////////           Interface Design Lab                                          /////
/////////           Copyright: Cap Gemini Ernst & Young Italia S.p.A.             /////
/////////           Author: Luca Baroni                                           /////
////////////////////////////////////////////////////////////////////////////////////////

setTxtOver = "#000000";
setTxtColor = "#ffffff";
setCellWidth = 260
setCellHeight = 20
setFontSize = 12

// *****************************************************
// * This function create the IS Object for recognize
// * the Browser 
// *****************************************************
function BrowserCheck() {
	var b 	= navigator.appName;
	var os 	=  navigator.platform;
	if (b=="Netscape") this.b = "ns" 
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.os = os;
	this.win = (this.os=="Win32")
	this.mac = (this.os=="MacPPC")
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns3 = (this.b=="ns" && this.v<4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns6 = (this.b=="ns" && this.v>4)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
}
is = new BrowserCheck()
// *****************************************************
// * This function create the Menu Object 
// *****************************************************
function Menu(id,posx,posy,colorebg,colorehi,txtcolor,txtover) {
	this.name 		= id
	this.x 			= posx
	this.y 			= posy
	this.itemH 		= setCellHeight // **************************************************
	this.parent 	= parent
	this.items 		= new Array()
	this.add 		= AddItem 
	this.build 		= BuildItem
	this.activate	= Activate
	this.menucolor  = colorebg
	this.menucolorh = colorehi
	this.txtcolor	= txtcolor
	this.txtover	= txtover
}
// *****************************************************
// * This function add Items sub menu and generates Array 
// *****************************************************
function AddItem(text,link,parent) {
	var i 				= this.items.length
	this.items[i] 			= new Array()
	this.items[i].parent	= parent
	this.items[i].name 		= parent+'Item'+i
	this.items[i].selected 	= false
	this.items[i].text 		= text
	this.items[i].link 		= link
	this.items[i].y 		= setCellHeight // ************************************************** no
	this.items[i].w 		= setCellWidth
	if (this.itemH) {
		this.h 			+= this.itemH+this.itemSpacing
		this.items[i].y 	= i*this.itemH+i
	}
}
// *****************************************************
// * This function build the style and the html code 
// *****************************************************
function BuildItem () {
	this.fnt = fntname
	this.fntsize = fntsize
	this.locolor = "#ffffff" //"#EDB341" // Colore back celle (sostituire anche in top_nav_bar.js)
	this.hicolor = this.menucolor
	this.totalItem = this.items.length
	this.totalHeight = (this.totalItem*setCellHeight)+this.totalItem
	this.css = ''
	this.css += '<style>\n'

	if (is.ns4) { // CHECKING IF THE BROWSER IF NAVIGATOR 4.X
		this.css += '#'+this.name+' {position: absolute; top:'+this.x+'; left: '+this.y+'; layer-background-color:'+this.menucolor+';clip: rect(0,' + setCellWidth + ','+(this.totalHeight+1)+',0); z-index: 15; visibility: hidden}\n'
 		for (var i=0;i<this.items.length;i++) {
			this.css += '#'+this.name+'Item'+i+' {position: absolute; top:'+this.items[i].y+'; left:0; layer-background-color:'+this.locolor+'; clip: rect(1,' + (setCellWidth-1) + ','+(setCellHeight+1)+',1); font-family:'+this.fnt+'; font-size: '+setFontSize+'px; z-index: 15; color:'+this.txtcolor+'}\n'
		}
	} else if (is.ns6) { // CHECKING IF THE BROWSER IF NETSCAPE 6
		this.css += '#'+this.name+' {position: absolute; top:'+this.x+'; left: '+this.y+'; background-color: '+this.menucolor+'; width: ' + setCellWidth + '; height:'+(this.totalHeight-1)+'; padding: 1px; z-index: 15; visibility: hidden}\n'
 		for (var i=0;i<this.items.length;i++) {
			this.css += '#'+this.name+'Item'+i+' {position: absolute; top:'+(1+this.items[i].y)+'; background-color:'+this.locolor+'; width: 98%; height: '+setCellHeight+';font-family:'+this.fnt+'; font-size: '+setFontSize+'px; z-index: 15; color:'+this.txtcolor+'; cursor: hand;}\n'
		}
	} else if (is.ie) { // CHECKING IF THE BROWSER IF EXPLORER 4 
		this.css += '#'+this.name+' {position: absolute; top:'+this.x+'; left: '+this.y+'; background-color: '+this.menucolor+'; width: ' + setCellWidth + '; height:'+(this.totalHeight+1)+'; padding: 1px; z-index: 15; visibility: hidden}\n'
 		for (var i=0;i<this.items.length;i++) {
			this.css += '#'+this.name+'Item'+i+' {position: absolute; top:'+(1+this.items[i].y)+'; background-color:'+this.locolor+'; width: 100%; height: '+setCellHeight+';font-family:'+this.fnt+'; font-size: '+setFontSize+'px; z-index: 15; color:'+this.txtcolor+'; cursor: hand;}\n'
		}
	}
	this.css += '</style>'
	this.div = ''
	this.div += '<div id="'+this.name+'">\n'
	for (var i=0;i<this.items.length;i++) {this.div += '<div id="'+this.name+'Item'+i+'">'+this.items[i].text+'</div>\n'}
	this.div += '</div>'
}
// *****************************************************
// * This function activate the Menu 
// *****************************************************
function Activate() {
	for (var i=0;i<this.items.length;i++) {
		//alert("Parent element: " + this.items[i].parent)
		//alert("this.menucolor = " + this.menucolor)
		MakeDiv(this.items[i].name,this.items[i].link,this.items[i].text,this.items[i].parent,this.menucolorh)
	}
}
// *****************************************************
// * This function set the Div Objects and build them 
// *****************************************************
function MakeDiv(id,pagetoload,testo,nestref,colore) {
	//alert("Entro in Makediv:\nID:"+id+"\nPag2Load: "+pagetoload+"\ntesto: "+testo+"\nNestRef: "+nestref)
	if (is.ns4) {
		this.css 			= document.layers[nestref].document.layers[id]
		this.elm 			= this.event = this.css
		this.doc 			= this.css
		this.x 				= this.css.left
		this.y 				= this.css.top
		this.w 				= this.css.clip.width
		this.h 				= this.css.clip.height
		this.z 				= this.css.visibility
		this.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE)
	
	} else { // THIS CODE WAS DEVELOPED FOR BOTH EXPLORER AND NETSCAPE 6
		if (is.ie4) {
			this.elm 			= document.all[id]
			this.css 			= document.all[id].style
		} else {
			this.elm 			= document.getElementById(id)
			this.css 			= document.getElementById(id).style
		}
		this.doc 			= document
		this.x 				= this.elm.offsetLeft
		this.y 				= this.elm.offsetTop
		this.w 				= this.css.pixelWidth 
		this.h 				= this.css.pixelHeight 
		this.z 				= this.css.visibility
		this.css.bgColor	= locolor
	}
	this.elm.visibile = false
	this.elm.color = colore
	this.elm.nestref = nestref
	//alert("this" + this.elm.color)
	this.elm.text = testo
	this.elm.link = pagetoload
	// Defines Methods	
	if (is.ns6) { // HANDLING EVENT OBJECT FOR NETSCAPE 6
		this.elm.addEventListener("mouseover", MouseOver, false);
  		this.elm.addEventListener("mouseout", MouseOut, false);
		this.elm.addEventListener("mouseup", MouseUp, false);
	
	} else if (is.ie) { // HANDLING EVENT OBJECT FOR EXPLORER
		this.elm.onmouseover	= MouseOver
		this.elm.onmouseout 	= MouseOut
		this.elm.onmouseup 		= MouseUp
	}
	this.elm.onmouseover	= MouseOver
		this.elm.onmouseout 	= MouseOut
		this.elm.onmouseup 		= MouseUp
	this.elm.page 			= pagetoload
}
// *****************************************************
// * This function set the BackgroundColor of the Divs
// * based on the variable hicolor - ONMOUSEOVER Event
// *****************************************************
function MouseOver(e) {
	if (is.ns4) {
		var x = (is.ns)? e.layerX:event.offsetX
		var y = (is.ns)? e.layerY:event.offsetY
	}
	vis = true
	if (is.ns4)	{
		this.bgColor = this.color
	} else {
	  	this.style.backgroundColor 	= this.color;
	  	this.style.color = setTxtOver //"#FFD427" //this.txtover
	}
	
	return false
}
// *****************************************************
// * This function set the BackgroundColor of the Divs
// * based on the variable locolor - ONMOUSEOUT Event
// *****************************************************
function MouseOut(e) {
	if (is.ns4) {
			var x = (is.ns)? e.layerX:event.offsetX
			var y = (is.ns)? e.layerY:event.offsetY
	}
	if (is.ns4) {
		this.bgColor =  locolor
	} else {
		this.style.backgroundColor 	= locolor;
		this.style.color = setTxtColor
	}
	
	vis = false
	myparent = this.nestref

	setTimeout('ClearAll("'+myparent+'")',1000)
	return false
}
// *****************************************************
// * This function check if the menu is visible: if it's
// * false, then Hide the menu
// *****************************************************
function ClearAll(parent) {
	//alert("This is my Parent: " + parent + "\Vis:" + vis)
	if (vis == false) {
				//alert("Entro dentro Visibile = falso");
				if (is.ns4) {document.layers[parent].visibility = 'hidden'}
				else if (is.ie4) {document.all[parent].style.visibility = 'hidden'}
				else {document.getElementById(parent).style.visibility = 'hidden'}
			
			if (parent == "container0") {document.menunewbuild.src = 'images/ey_menu_newbuild_off.gif'}	
			else if (parent == "container1") {document.menucompanies.src = 'images/ey_menu_companies_off.gif'}
			//else if (parent == "container2") {document.menucompanies.src = 'images/ey_menu_companies_off.gif'}
			//else if (parent == "container3") {document.menuproject.src = 'images/ey_menu_project_off.gif'}
			vis = false
		
	}else { 
		//alert(this.name)
		//alert("Entro dentro Visibile = Vero");
		return false}
}
// *****************************************************
// * This function redirect the user to another page 
// * based on the variable pagetoload - ONCLICK Event
// *****************************************************
function MouseUp(e) {
	var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft
	var y = (is.ns)? e.pageY : event.y+document.body.scrollTop
	window.top.location.href = this.page
}	

