window.addEvent('domready', function() {


	if ($('kwick-box')) {
		
		$('kwick').addClass('kwicks');

		var kwicks = $$('#kwick-box .block');
		
		var kwidth = $('kwick-box').getStyle('width').toInt();
		var count = kwicks.length;
		var before_w = kwidth/count;
		var ke_w = kwidth/2;
		var after_w = (kwidth-ke_w)/(count-1);
		var max_height = 0;

		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		kwicks.each(function(kwick, i){
			var inner = new Element('div', { 'class' : 'inner', styles: {
						width: (ke_w-40)+'px'}
					});
			max_height = kwick.getStyle('height').toInt() > max_height ?  kwick.getStyle('height').toInt() : max_height;

			inner.innerHTML = kwick.innerHTML;
			kwick.innerHTML = '';
			inner.inject(kwick);
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), ke_w]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != after_w) obj[j] = {'width': [w, after_w]};
					}
				});
				fx.start(obj);
			}).addClass('el'+(i+1)).setStyle('width', before_w+'px');
		});
		
		kwicks.each(function(kwick, i){
			kwick.setStyle('height', max_height+'px');
		});

		$('kwick').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), before_w]};
			});
			fx.start(obj);
		});
	}
});
