eXo.require("eXo.wcm.backoffice.private.WCMUtils", "/eXoWCMResources/javascript/");
eXo.require("eXo.wcm.frontoffice.public.Breadcrumb", "/eXoWCMResources/javascript/");

function renderNavigations() {
  var navigations = eXo.env.portal.navigations;
  var html = 	'<div class="UIWCMNavigationPortlet"><div class="UINavigationBar">';
  var date = (new Date()).getTime();
  for (var ownerType in navigations) {
    if (Array.prototype[ownerType]) continue;
    for (var i in navigations[ownerType].nodes) {
      var navigation = navigations[ownerType].nodes[i];
      if (Array.prototype[i]) continue;
      else{
		  var title = navigation.resolvedLabel;
	      if (navigation.resolvedLabel.length > 30)
	        navigation.resolvedLabel = navigation.resolvedLabel.substring(0,29) + "...";
	      var tabStyleNavigation = 'ControlButton';
	      var currentNodes = eXo.ecm.WCMBreadcrumbPortlet.getCurrentNodes(navigations, eXo.env.portal.selectedNodeUri);
	      if (currentNodes.length>0 && navigation.uri == currentNodes[currentNodes.length - 1].uri)	
	        tabStyleNavigation = 'ControlButton HoverButton';
	      var link = eXo.ecm.WCMUtils.getHostName() + eXo.env.portal.context + '/' + eXo.env.portal.accessMode + '/' + eXo.env.portal.portalName + '/' +  navigation.uri;
	      var arrowIcon = '';
	      if (ownerType==0) {
	        html +=  '<div class="'+tabStyleNavigation+'">'+
	                   '<div class="Button">';
	        if (navigation.uri)
	          html +=    '<a title="' + title + '" href="' + link + '">' + navigation.resolvedLabel + '</a>';
	        else 
	          html +=    '<a class="TabLabel ' + navigation.icon + '" title="' + title + '">' + navigation.resolvedLabel + '</a>';
	        html +=    '</div>'+
	                 '</div>';
	      }
	  }
    }
  }
  html += '<div style="clear: left;"><span></span></div></div></div></div>';
  document.getElementById('navigation-generator').innerHTML = html;
}