
	// **************************************************************************************************************************
	//
	// Title :			cimexNav.js
	// Author : 		Ben Sekulowicz-Barclay
	//
	// Description : 	v0.1
	//
	// **************************************************************************************************************************

	var cimexNav = Class.create();

	cimexNav.prototype = {

		initialize: function(w, p, c) {
			this.w = w;			
			this.p = p;
			this.c = c;
			
			Event.observe(window, "load", this.onLoadStart, false);
		},

		// ONLOAD TRIGGERS ******************************************************************************************************

		onLoadStart: function() {					
			for (var i = 0; i < cxNav.c.length; i++) {
				if ($(cxNav.c[i])) {					
							
					var a = cxNav.createHTML("A", "", "");						
					var p = cxNav.createHTML("P", "", "close");						
					a.setAttribute("href", "#");							
					a.appendChild(document.createTextNode("Close"));
					p.appendChild(a);						
					$(cxNav.c[i]).appendChild(p);	
							
					Event.observe(a, "click", cxNav.onClickHide, false);										
					a.onclick = function() { return false; }					
					
					Element.addClassName($(cxNav.c[i]), "cxNav");
					
					cxNav.hideMenu();
				}
			}
			
			for (var i = 0; i < cxNav.p.length; i++) {
				if ($(cxNav.p[i])) {
					Event.observe($(cxNav.p[i]), "click", cxNav.onClickShow, false);
					$(cxNav.p[i]).onclick = function() { return false; }				
				}
			}
// Modif for problem of <a name> for all browsers execpt IE
 if(window.location.hash != "") { window.location.hash=window.location.hash; }


// Modif for problem of <a name> for all IE browsers

//if(!window.location.search.match(/^$|=/)) {
//  var h=window.location.search.replace(/^\?/,"#");
// var oRE=new RegExp("\\"+window.location.search);
//  window.location.href=window.location.href.replace(oRE,h);
//}

		},
		
		// ONCLICK TRIGGERS *****************************************************************************************************

		onClickShow: function(e) {		
			// Setup the event target variable, (IE bug)
			if (document.all) {
				var clicked = Event.element(e);	
			} else {
				var clicked = this;	
			}
				
			cxNav.hideMenu();
					
			for (var i = 0; i < cxNav.p.length; i++) {
				if (cxNav.p[i] == clicked.getAttribute("id")) {
					cxNav.showMenu(i);
				}
			}
			
			Element.addClassName(clicked.parentNode, "cxNavCurrent");
		},
		
		onClickHide: function() { cxNav.hideMenu(); },
		
		// **********************************************************************************************************************
		
		showMenu: function(i) {
			var old = $(this.p[i]).parentNode;
			var x = 0;
			var y = 0;

			while(old != $(this.w)) {
				x += old.offsetLeft;
				y += old.offsetTop;
				old = old.parentNode;
			}
			
			$(this.c[i]).style.top = y + $(this.p[i]).offsetHeight + "px";
			$(this.c[i]).style.left = x - $(this.c[i]).offsetWidth + $(this.p[i]).offsetWidth/1.9 + "px";
// Modif for Main menu 301106 Cyril
//			$(this.c[i]).style.left = "60px";
		},
		
		hideMenu: function() {
			for (var i = 0; i < this.c.length; i++) {
				$(this.c[i]).style.top = "-999em";
				$(this.c[i]).style.left = "-999em";	
				
				
				Element.removeClassName($(this.p[i]).parentNode, "cxNavCurrent");
			}
		},
		
		// **********************************************************************************************************************
		
		createHTML: function(e, i, c) {
			var newElement = document.createElement(e);			
			if (i != "") { newElement.setAttribute("id", i); }			
			if (c != "") { newElement.className = c; }			
			return newElement;
		}
	
		// FIN ******************************************************************************************************************
	};     

   function go2h() {
     if(window.location.search.match(/hash=/)) {
       var sH="";
       var sS1=window.location.search.replace(/^\?/,"");
       var sS2="";
       var aKV=sS1.split(/\&/);
       for(var i=0;i<aKV.length;i++) {
         var a=aKV[i].split(/=/);
         if(a[0]=="hash") { sH=a[1]; }
         else { sS2+=(sS2=="" ? "" : "&")+aKV[i]; }
        }
        if(sH!="") { window.location.href=window.location.href.replace("?"+sS1,(sS2=="" ? "" : "?"+sS2)+"#"+sH); }
     }
   }

