YUI({combine: true, timeout: 10000}).use('io', 'history', function(Y)
{
	var html, elem, bookmarkedSection, querySection, initSection, navbar;
	
	function loadSection(section) 
	{
		jumpToFeature(section);
	}
	
	function initializeNavigationBar()
	{
		containerIdArray = Array;
    	containerIdArray[0] = 'nav';
    	containerIdArray[1] = 'stepper';
    	
    	for(var i=0; i<=containerIdArray.length; i++)
    	{
	    	Y.on('click', function (evt) {
	            var el = evt.target;
	            while (el.get('id') !== containerIdArray[i]) {
	                if (el.get('nodeName').toUpperCase() === 'A' && el.get('id') != 'site-chooser-link') {
	                    evt.preventDefault();
	                    section = Y.History.getQueryStringParameter('feature', el.get('href')) || '0';
	                    if (!Y.History.navigate('navbar', section)) {
	                        // Fallback...
	                        showFeature(section);
	                    }
	                    break;
	                } else {
	                    el = el.get('parentNode');
	                }
	            }
	        }, '#'+containerIdArray[i]);
    	}

        currentSection = Y.History.getCurrentState('navbar');
        showFeature(currentSection);
	}
	
	bookmarkedSection = Y.History.getBookmarkedState('navbar');
    querySection = Y.History.getQueryStringParameter('feature');
    initSection = bookmarkedSection || querySection || '0';

    Y.History.register('navbar', initSection).subscribe('history:moduleStateChange', loadSection);
	Y.History.subscribe('history:ready', initializeNavigationBar);
	
	if (!Y.History.initialize('#yui-history-field', '#yui-history-iframe'))	{
		// Fallback...
		showFeature(initSection);
	}
	
});

