(function($){
	var menu = {
		init : function(){
			//Hover titles in navigation
			$('#navigation .menu-item a').hover(			
				//Mouse In
				function(){
					var par = $(this).parent();				
					var desc = $('.desc', par);
					
					desc.stop().animate({
			      right: '-250px'
			    }, 'slow');
				},
				//Mouse Out
				function(){
					var par = $(this).parent();	
					var desc = $('.desc', par);
					desc.stop().animate({
					  right: '+250px'
					});
				}
			);
			
			//Scrolling in menu!
			//get basic info
			menu.height = ($(window).height())-(16*2);//window-h - height of navigation controls;
			menu.item_h = 55;
			menu.items_count = $('#navigation .item-container ul li').size();
			menu.items_height = menu.items_count*menu.item_h;
			menu.step = 5;
			
			//check if all items are already shown
			if(menu.items_height > menu.height)
			{
				//add listeners to buttons
				$('#navigation .next').click(function(){
					menu.move('n');
					
					return false;
				});
				
				$('#navigation .prev').click(function(){
					menu.move('p');
					
					return false;
				});
			}
			else
			{
				$('#navigation .next, #navigation .prev').addClass('disabled').click(function(){ return false; });
			}
			
			//window resize - reset menu
			$(window).resize(function() {
			  //console.log('window was resized!');
			  
			  menu.height = ($(window).height())-(16*2);
			  
			  if(menu.items_height > menu.height)
			  {
			  	$('#navigation .next, #navigation .prev').removeClass('disabled');
			  
			  	//add listeners to buttons
			  	$('#navigation .next').unbind().click(function(){
			  		menu.move('n');
			  		
			  		return false;
			  	});
			  	
			  	$('#navigation .prev').unbind().click(function(){
			  		menu.move('p');
			  		
			  		return false;
			  	});
			  }
			  else
			  {
			  	$('#navigation .next, #navigation .prev').unbind().addClass('disabled').click(function(){ return false; });
			  }
			});
		},
		
		move : function(dir){
			var step = menu.step;
								
			if(dir == 'p')
			{				
				var items_to_add = 5;
				
				for(var i=1; i<=items_to_add; i++)
				{
					console.log($('#navigation .item-container ul li:nth-child(1)'));
					$('#navigation .item-container ul li:nth-child('+menu.items_count+')').insertBefore('#navigation .item-container ul li:nth-child(1)');
				}
			}
			else
			{				
				var items_to_add = 5;
				
				for(var i=1; i<=items_to_add; i++)
				{
					$('#navigation .item-container ul li:nth-child(1)').appendTo('#navigation .item-container ul');
				}
			}
		}
	};
	
	menu.init();
})(this.jQuery);

/*
 * BOILERPLATE CODE
 * ########################################################
 */
window.log = function(){
  log.history = log.history || [];   
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};
(function(doc){
  var write = doc.write;
  doc.write = function(q){ 
    log('document.write(): ',arguments); 
    if (/docwriteregexwhitelist/.test(q)) write.apply(doc,arguments);  
  };
})(document);



