	/**
	 * @author garry.yao
	 */
	
	/**
	 * Retrieve the current "channel" path from window url e.g. '政府频道'- '/zhenfupindao'
	 * @return {String} The current channel path
	 */
	function currentChannel()
	{
		
		var currentPagePath = window.location.pathname;	
		var candidateRootPath = ['/eco-city/portal','/eco-city/export/sites/default','/eco','/opencms/export/sites/default','/opencms/opencms'];
		
		var rootPath;
		$.each(candidateRootPath, function(){
			
			if(currentPagePath.indexOf(this) !== -1)
				{
					rootPath = this;
					return false;	
				}
		});
		
		
		var path, channelName ;
		path = currentPagePath.split(rootPath)[1];
		path = path.substr(1, path.length);
		
		if(path.indexOf('/') == -1)	//Match "/channel"
		{
			channelName = path;
		}
		else //Match "/channel/subpage.html"
		{
			channelName = path.split('/')[0];
		}
		
		//alert("Resolved Channel Name: "+channelName);
		return channelName;
	}
	
	
	/**
	 * Initialize the <table> element as a navigation menu 
	 */
	function navigatorMenu()
	{
		var currChannelHTMLLink;
		var currChannelPath  = currentChannel();
		
		
		//Keep sync with current channel, by highlighting the current html <a> element
		var initState = function(){
			
			this.onmouseover();
			
		};
		
		$(this).find('td a').each(function(){
			
			
			if(this.href.indexOf(currChannelPath) !== -1)
			{
				//alert(this.href+'\n'+currChannelPath);
				currChannelHTMLLink = this;
				
				initState.call(this);
				
				//stop iteration
				return false;
			}
			
		});
		
		$(this).find('td a').each(function(){
			
			var mouseoOverHandler  = this.onmouseover;
				this.onmouseover = function()
				{
					//Clear defaut channel state while other selection is hovered
					currChannelHTMLLink.onmouseout();
					mouseoOverHandler.call(this);
				}
		});
		
		$(this).bind('mouseout', function(){
			
			//Restore default channel selection
			initState.call(currChannelHTMLLink);
		});
		
			
	}
	
	(function(){
		
			navigatorMenu.call($('table.main-navigator').get(0));
		
	})();

// Alan: Search
var frm = window.document.getElementById('frmSearch');
if (frm)
{
	var chn = currentChannel();
	frm.action = "/eco-city/portal/" + chn + "/result.jsp";
}