// ---------------------
//   nav handler class
// ---------------------
function navHandler_class() {
	this.main.vertical_menu.init();
}

navHandler_class.prototype =
{

// breadcrumb path links
// =====================
path_links:{
	bar: function(aLinks,cur_link)
	{
		var cur='&nbsp;//';
		if (cur_link)
			cur='/&nbsp;<a href="#">'+cur_link.name+'</a>';

		return '<a href="/">Home</a> // '+ aLinks.join("&nbsp;//&nbsp;")+cur+"<br/>";
	},
	branch:  function(branch,url,name,level)
	{
		if (name.charAt(0)=='_' || name.toLowerCase()=='Home')
		{
			return null;
		}

		return '<a href="'+url+'">'+name+'</a>';
	}
},

// "main" navigation widget = top menu + horizontal menu
// =====================================================
main: {
	properties: {
		version:"1.3",
		top_menu:'none',
		zone_nav:'branch|leaf',
		one_branch_only:'tree'
	},

	//  Topmenu bar
	// ==============
	top_menu: {
		bar : function(aLinks) {
			return aLinks.join(" ");
		},

		// displays a link in topmenu nav
		link : function(label,url,index,is_current,last,current)
		{
			return '<span class="is_page has_menu"><a href="'+url+'">'+label+'</a></span> ';
		}
	},

	/* Vertical (left) menu 
	   =====================
	*/
	vertical_menu: {
		init: function() {
			this.zone_index=0;
			this.branch_index=0;
		},

		/*
			zone_mode: tells the CMS engine if this design displays all navigation zones in the left panel
			as a tree, or only current zone. The latter case is to be used when no top menu navigation is
			implemented.
		*/
		zone_mode : function(nb_zones,current_zone) {
			return this._zone_mode='all_zones';
			// we want all zones displayed in horizontal menu
		},

		/* displays the navigation tree: tree root
			- zone: zone id
			- content: content created by following callbacks
			- widget: "zone"
		*/
		disp_tree : function(content,widget)
		{
			return content;
		},

		/* displays the navigation in the left panel.
			- zone: zone id
			- content: content created by following callbacks
			- widget: "zone"
		*/
		disp_zone : function(zone,content,widget,branch)
		{
			// this.branch_index=0;
			return '<span class="titre">'+branch.name+'</span>\n'+content;
		},
		/* displays link branches
			- zone: zone id
			- branch.name: short name to be used in links.
			- branch.fullName: longer name to be used in tooltips.
			- url: zone url
			- branch.id: branch path id
			- branch.level: nested level (1,2,3, etc.)
			- is_current: true if branch is currently selected.
			- content: content created from children nodes
			- aChildren: content as an array
			- widget: zone|header|footer| etc.
		*/
		disp_branch : function(branch,zone, url, is_current,content,aChildren,last)
		{
			// need separator for last link in branch if 
			// + not first zone and is 1rst branch 
			// + is not the last branch
			var bindex=this.branch_index++;
			var display=is_current?'block':'none';

			// display branch as submenu if nested and if has more than one link, else displays its content only
			if (branch.level>1 && aChildren.length>1)
				if (content!='')
				{
					return '<span class="rub_2niveau"><a onClick="HideAndShow(\'Tab_'+bindex+'\')" href="#">'+branch.name+'</a></span>'+
							'\n<span class="ssmenu" id="Tab_'+bindex+'" style="display:'+display+';">'+
								aChildren.join("<br />\n")+
							'</span>\n';
				}

			return content;
		},

		/* displays a navigation link
			- zone: zone id
			- label: short name to be used in links.
			- url: zone url
			- index: branch index
			- is_current: true if branch is currently selected.
			- widget: "zone"
			- last: index of last link in collection
			- current: index of current link
		*/
		disp_leaf : function(zone,link,url,index,is_current,last,current)
		{
			var label=link.name;
			//NxTrace("link:"+label+" index="+index+"/"+last+"<br/>");

			if (link.branch.level>1 && last>0)
				return '<a href="'+url+'">'+link.name+'</a>';

			return '<span class="rub_1niveau"><a href="'+url+'">'+link.name+'</a></span>\n';
		}
	}
},

//  Footer widget
// ===============
footer: {
	/* display the content of the footer */
	disp_zone : function(zone,content) {
		return content;
	},

	/*
		called for each branch in footer navigation. Most of the time there will only one branch having a set of links, 
		but soem sites might have two or more lines with links.
	*/
	disp_branch : function(branch,zone, url, is_current,s,aChildren,last)
	{
		return aChildren.join(" ");
	},

	/*
		called for each link in footer (see zoen callbacks for description of parameters)
	*/
	disp_leaf : function(zone,link,url,index,is_current,last,current)
	{
		return '<a class="is_page" href="'+url+'">'+link.name+'</a>';
	}
},


// display of header menu (similar to footer)
// =======================
header: {
	disp_zone : function(zone,content) {
		return content;
	},

	disp_branch : function(branch,zone, url, is_current,content,aChildren,last)
	{
		return aChildren.join(" ");
	},

	disp_leaf : function(zone,link,url,index,is_current,last,current)
	{
			return '<span class="is_page has_menu" '+link.cms_menu_params+'><a href="'+url+'">'+link.name+'</a></span> ';
	}
}

} // end of class

// instanciate the widget/nav object
var nav_handler=new navHandler_class();

// load the navigation engine if needed
if (typeof(nav_engine)!="undefined" && nav_engine)
{
	window.document.write('<'+'script src="'+nx_skin_path+'js/nav_engine2.4.js"><'+'\/script>');
}
