var Kwix = {
	initPage: function(){
		Kwix.parseacciaio();
		$$('.activerivagroupmenu').setStyle('width','80px');
		$$('.activerivagroupmenu').setStyle('background-position',(-idInitMenu*80)+'px bottom');
		
	},

	parseacciaio: function(){

		var squeeze_to = 66;
		var max_width = 80;

		//get original widths
		var start_widths = new Array();
		var acciaio = $$('#rivagroupmenu .rivagroupmenu');
		var fx = new Fx.Elements(acciaio, {wait: false, duration: 250, transition:Fx.Transitions.Cubic.easeOut});
		acciaio.each(function(rivagroupmenu, i){

			start_widths[i] = rivagroupmenu.getStyle('width').toInt();

			//mouse is in, squeeze and expand
			rivagroupmenu.addEvent('mouseenter', function(e){

				var obj = {};
				obj[i] = {
					'width': [rivagroupmenu.getStyle('width').toInt(), max_width]
				};
				
				var value=parseInt(this.getProperty("value"));
				this.setStyle('background-position',(-value*80)+"px bottom");
				
				var counter = 0;

				acciaio.each(function(other, j){
					if (other != rivagroupmenu){
						var w = other.getStyle('width').toInt();
						if (w != squeeze_to) obj[j] = {'width': [w,squeeze_to] };
					}
				});
				fx.start(obj);
			});
			
			//mouse is in, squeeze and expand
			rivagroupmenu.addEvent('mouseleave', function(e){
				if(!this.hasClass('activerivagroupmenu')){
					var value=parseInt(this.getProperty("value"));
					this.setStyle('background-position',(-value*80)+"px top");
				}
			});
		});

		//mouse is out, squeeze back
		$('rivagroupmenu').addEvent('mouseleave', function(e){
			var obj = {};

			acciaio.each(function(other, j){
				if(!other.hasClass('activerivagroupmenu'))
					obj[j] = {'width': [other.getStyle('width').toInt(), start_widths[j]]};
				else
					obj[j] = {'width': [66,80]};
			});
			fx.start(obj);
		});
		
		$$('.rivagroupmenu').addEvent('click', function(e){
			var oldAK=$$('.activerivagroupmenu');
			oldAK.removeClass("activerivagroupmenu");
			oldAK.setStyle("width","66px");
			var objValue=parseInt(oldAK.getProperty("value"));
			oldAK.setStyle("background-position",(-objValue*80)+"px top");

			this.addClass("activerivagroupmenu");	
			this.setStyle("width","80px");
			var value=parseInt(this.getProperty("value"));
			this.setStyle("background-position",(-value*80)+"px bottom");
		});
	}
};

//lock and load!
window.addEvent('domready',Kwix.initPage);



