/*
Leonardo Service Provider S.p.A.
Tutti i diritti registrati e riservati,(R)(C) 2009.
La riproduzione parziale o totale del presente software
delle pagine generate nonchè della strutturazione dei dati,
delle tabelle e di quant'altro è ad esso inerente  è illegale 
ed è punibile secondo tutte le Leggi vigenti sulla violazione del Diritto D'Autore.
L'utilizzo del presente software senza regolare licenza d'uso
è illegale e sarà perseguito secondo tutte le Leggi vigenti applicabili
*/

(function($){
	$.fn.kwicks = function(options){
		var defaults = {
			minimo:17,
			massimo:62,
			tempo:200
		}
		var o = $.extend(defaults, options);
		//this.children('li').addClass('inactive')
		
		
		/// Stili di base ///
		this.css('display', 'block');
		this.css('margin', '0');
		this.css('padding', '0');
		this.css('width', '212px');
		this.css('height', '24px');
		this.css('overflow', 'hidden');
		this.children('li').css('display', 'block');
		this.children('li').css('list-style', 'none');
		this.children('li').css('margin', '0');
		this.children('li').css('padding', '0');
		this.children('li').css('overflow', 'hidden');
		this.children('li').css('float', 'left');
		this.children('li').css('border', '0');
		//this.children('li').css('border', '1px solid #069');
		this.children('li').css('width', o.minimo+'px');
			
		return this.each(function() { /// Tutti gli UL
			/// Calcolo la dimensione iniziale ///
			var contenitore = $(this);
			var kwicks = contenitore.children('li');
			//contenitore.css('width', o.minimo*kwicks.length+'px');
			if (kwicks.length > 8) {
				o.massimo -= o.minimo;
			}
			kwicks.each(function(i) {
				var kwick = $(this);
				kwick.bind('mouseover', function(){
					kwick.addClass('kwickactive');
					kwick.removeClass('kwickinactive');
					//$(contenitore).animate({width:(o.minimo*(kwicks.length-1))+ o.massimo+'px'},o.tempo)
					//kwick.animate({width:o.massimo+'px'},o.tempo)
					moveAll();
				})
				kwick.bind('mouseout', function(){
					kwick.addClass('kwickinactive');
					kwick.removeClass('kwickactive');
					//$(contenitore).animate({width:(o.minimo*kwicks.length)+'px'},o.tempo)
					//kwick.animate({width:o.minimo+'px'},o.tempo*1.5)
					moveAll();
				})
			})
			function moveAll() {
				$('.kwickactive').stop();
				$('.kwickinactive').stop();
				$('.kwickactive').animate({width:o.massimo+'px'}, o.tempo)
				$('.kwickinactive').each(function(){
					if ($(this).width() <= o.minimo) {
						$(this).removeClass('kwickinactive')
						$(this).css('width', o.minimo+'px')
					}
				})
				$('.kwickinactive').animate({width:o.minimo+'px'}, o.tempo)
			}
		})
	}
})($);