<%
  import org.exoplatform.web.application.JavascriptManager;
  import java.util.HashMap;
  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet;  
  def rcontext = _ctx.getRequestContext() ;
  def uiPortlet = uicomponent.getAncestorOfType(UIJCRExplorerPortlet.class);
  JavascriptManager jsmanager = rcontext.getJavascriptManager();
  
  jsmanager.addJavascript('eXo.ecm.ECMUtils.onKeyAddressBarPress();') ;
  jsmanager.addJavascript('eXo.ecm.ECMUtils.onKeySimpleSearchPress();') ;
%>
<% uiform.begin() %>
<div class="UIAddressBar">
<% if (uiPortlet.isShowTopBar()) { %>
	<table class="TblAddressBar">
		<tr class="Block">
		<%
			int viewCount = 0;
			def extendMap = new HashMap<String, String>();
			if(uicomponent.getViewList().size() > 1) {
				for(viewStyle in uicomponent.getViewList()) { 
					def label = _ctx.appRes("Views.label." + viewStyle);
					def viewIcon = viewStyle;
					def defaultView = "DefaultView";
					if(uicomponent.isSelectedView(viewStyle)) {
						viewIcon = viewStyle + "-selected";
						defaultView = "DefaultViewSelected";
					}
					viewCount++;
					if(viewCount < 8) {
			%>
				<td class="IconFileExplorer">
						<a href="<%=uicomponent.event("ChangeView", viewStyle)%>" class="$defaultView $viewIcon ViewIcon" title="$label"><span></span></a>
				</td>
			<%  } else {
						extendMap.put(viewStyle, label + ";" + viewIcon);
					}
				}
			} else {
				viewCount++;
			}
		 %>
		<%
			if(!extendMap.isEmpty()) {
		%>
			<td class="DetailMoreViewIcon">
				<div class="MoreViewIcon" onclick="javascript: eXo.ecm.ECMUtils.showHideExtendedView(event);"><span></span></div>
				<div class="ListExtendedView" id="ListExtendedView" style="display: none;">
				<%
					for(key in extendMap.keySet()) {
						def viewInfor = extendMap.get(key);
						def label = viewInfor.split(";")[0];
						def viewIcon = viewInfor.split(";")[1];
						def defaultView = "DefaultView";
						if(uicomponent.isSelectedView(key)) {
							viewIcon = key + "-selected";
							defaultView = "DefaultViewSelected";
						}
				%>
						
						<a href="<%=uicomponent.event("ChangeView", key)%>" class="$defaultView $viewIcon ViewIcon" title="$label"><span></span></a>
					<%}%>
				</div>
				<%}%>
			</td>
  			<td class="BackAndRefreshBlock" style="width: 55px;">
  				<a class="BackBtn FloatLeft" href="<%=uicomponent.event("Back")%>" title="<%=_ctx.appRes("UIAddressBar.title.backButton")%>"><span></span></a>	
  				<a class="RefreshSessionButton FloatLeft" href="<%=uicomponent.event("RefreshSession")%>" title="<%=_ctx.appRes("UIViewBar.label.refesh")%>"><span></span></a>
  			</td>	
  			<%
  				 def viewSize = "";
  				 if(viewCount < 5 && viewCount > 0) viewSize = Integer.toString(viewCount);
  			%>
  			<td id="UIAddressBarAction">
  				<div class="BgLeftAddressBar">
  					<div class="BgRightAddressBar">
  						<div class="BgCenterAddressBar">
  							<div class="BlockMiddle${viewSize} UIPopupSelector ClearFix">
  								<div style="position: relative;">
  									<div class="UISelectContent">
  										<%
  										for(entry in uicomponent.getFullHistory()) {
  											String actionLink = uicomponent.event("History", entry.workspace + ":" + entry.path);
  											println "<div class=\"AddressItem\" onmouseout=\"this.className = 'AddressItem'\" onmouseover=\"this.className = 'SelectedAddressItem'\" onblur=\"this.className = 'AddressItem'\" onfocus=\"this.className = 'SelectedAddressItem'\" onclick=\"$actionLink\">$entry.path</div>" ;
  										}
  										%>
  									</div>
  								</div>
  								<div class="DropDownButtonBox" onmousedown="eXo.ecm.ECMUtils.clickLeftMouse(event,this,2,1)" onkeydown="eXo.ecm.ECMUtils.clickLeftMouse(event,this,2,1)">
  									<div class="DropDownButton Style1DownArrow16x16Icon" title="<%=_ctx.appRes("UIAddressBar.title.showHistory")%>"><span></span></div>
  								</div>
  								<div class="InputContainer"  id="AddressBarControl">
  									<a href="<%=uicomponent.event("ChangeNode")%>" id="GotoLocation" title="<%=_ctx.appRes("UIAddressBar.title.changeNode")%>"></a>
  									<% uicomponent.renderChild(0); %>
  									<% uicomponent.renderChild(2); %>
  								</div>
  								
  							 </div>
  						</div>
  					</div>
  				</div>
  			</td>
  			<td class="Right">
  				<div class="BgLeftAddressBar">
  					<div class="BgRightAddressBar">
  						<div class="BgCenterAddressBar">
  							<div class="Advance" id="SimpleSearchControl">
  								<a href="<%=uicomponent.event("SimpleSearch")%>" title="<%=_ctx.appRes("UIActionBar.title.SimpleSearch")%>" class="SearchBtn" id="SimpleSearch"><span></span></a>
  								<% uicomponent.renderChild(1); %>
  							</div>
  						</div>
  					</div>
  				</div>	
  			</td>
		</tr>
	</table>
  <% } %>
</div>

<% uiform.end() %>