
/**
 * Navigation Slider
 * 
 */
var nav = {
        
  busy:    		false,
  count:   		0,
  ul:   		  null,
	items:   		new Array(),
	current: 		0,
	selected:   0,
   
  
  init: function ()
  {  
    nav.ul    =  $('navUl');
    nav.items =  $$('.navItem');
    nav.count =  nav.items.length;
    
		nav.activate();
  },
  
	
	
	getSelected: function()
	{
		if( nav.count )
		{
			return nav.items[nav.current].childNodes[0].name;
		}
		return false;
	},
	
	
	
	activate: function ()
	{
		nav.current = 0;
		nav.highlight();
		
		for( var x=0; x<nav.count; x++)
		{
      Event.observe( nav.items[x].childNodes[0], 'click', nav.click, false );
		}
	},
	
	
	
	click: function(event)
	{
    event.stop();
    
	  var element = $(Event.element(event));
    
		if( !nav.busy )
		{
			nav.busy=true;
			for( var x=0; x<nav.count; x++)
			{
				if( element == nav.items[x].childNodes[0] )
				{
          nav.selected = x;          
				  nav.update();			
          $('contentInner').setStyle({ display:'none' });
          $('menuInner').setStyle({ display:'none' });
	        //new Effect.Fade( 'contentInner', { duration:0.7 } );
          //new Effect.Fade( 'menuInner',    { duration:0.7 } );
				}
			}
		}
		
	},
	
	
	
	highlight: function()
	{
	  for( var x=0; x<nav.items.length; x++ )
	  {
	    if( x==nav.current )
	    {
	      nav.items[x].childNodes[0].className = 'high';
	    }
	    else
	    {
	      nav.items[x].childNodes[0].className = '';
	    }
	  }
	},
	
	
	
	update: function(from)
	{	
	  
	  nav.current = nav.selected;
		nav.highlight();

		var item, newI;
		for( var x=0; x<nav.selected; x++ )
		{				
		  item = nav.items[x].childNodes[0];
		  
		  if( BrowserDetect.browser == 'Explorer' && BrowserDetect.version==6 )
		  {
		    newI = '<li class="navItem"><a href="#" onclick="return false;" name="'+item.name+'">'+item.innerHTML+'</a></li>';
		  }
		  else
		  {
		    newI = '<li class="navItem"><a onclick="return false;" name="'+item.name+'">'+item.innerHTML+'</a></li>'; 
		  } 
			$('navUl').insert ({ 'bottom' : newI } );
		}

		// animate the navigation items
		var distance = 23*(x);		
		var duration = 0.2*(x);
    var timeout = duration*1000;


    new Effect.Move( nav.ul, { x:0, y:-distance, duration:duration, mode:'relative' });//, afterFinish:menu.load } );
    
    // Load the menu item
    if( typeof( from ) != 'string')
    {
      setTimeout( menu.load, timeout );
    }
    else
    {
      setTimeout( menu.jump, timeout );
    }
    
    setTimeout( "nav.restore()", timeout+1000);

	},
	
	
	loadNewMenu: function()
	{
	  menu.load();
	  nav.restore();
	},
	
	
	
	restore: function()
	{
		for( var x=0; x<nav.current; x++ )
		{
			nav.items[x].remove();
		}
	  nav.ul.setStyle({ top:'0', left:'0' });
			
		nav.init();
		
		nav.busy=false;
	},
	
	
	getPositionByName: function(name)
	{
    for( var x=0; x<nav.count; x++ )
    {
      if( nav.items[x].childNodes[0].name == name )
      {
        return x; 
      }
           
    }
    return false; 
	}
	
}
  
document.observe("dom:loaded", nav.init );
