/**
 * @author Ruda
 */

jQuery.horizontalMenu = {
	
	settings:  {
		version: "0.0.1"   
	},
	
	initialize: function(elMenu, options){
		jQuery.extend(this.settings, options);
					 	
		//1 compare menu on the center
		this.compareMenu(elMenu);
		
		//2 eject submenu
		this.ejectSubMenu(elMenu);	
	},

	/**
	* Metoda zarovna dlouhy text v menu
	* co se lame na dva radky na stred.
	* @param {Object} elMenu
	*/
	compareMenu: function(elMenu) {

	    $(elMenu + ' > ul > li > a').each(function(index) {
	        var textSize = $(this).text().length;
	        if (parseInt(textSize) > parseInt($.horizontalMenu.settings.maxLenghtByLink))
	            $(this).css({
	                'display': 'block',
	                'padding': '9px 0 5px 2px'
	            }).parent().css({
	                'word-spacing': '5px'
	            });
	    });
	},
	
	/**
	 * Metoda vysune submenu
	 * @param {Object} elMenu
	 */
	ejectSubMenu: function(elMenu) {
		$(elMenu + ' ul > li ').hover(function(){
			var liId = $(this).attr("id").split('-')[1]; 
			var menuWidth = parseInt((149+3) * liId);
			var subMenuHeight = parseInt($(this).children().next().height()); 
									
			$(this)			
			.children()
			.next()
			.css({'margin-left': 
				menuWidth + 'px',
				'height': '0px'})
			.stop(true, true)					
			.animate({ height: "+=" + subMenuHeight+"px", opacity: 1 }, {
						queue: true,
						duration: 1200
					});
			
					
		}, function(){
									
			$(this)
			.children()
			.next()		
			.stop(true, true)
			.fadeOut()			
		});
	},
	
	getNumberParentTag: function(tagLi) {
		 
		 $(tagLi).each(function(){
		 	var tag = $(this).prevAll();
			$.log.debug(tag);
		 });
	}
}


$(document).ready(function() {
    
    // Horizonal menu
    $.horizontalMenu.initialize("div#navigation",
	{ maxLenghtByLink: 19 });
});

