jQuery.fn.customFadeTo = function(speed,to,callback) {
    return this.animate({opacity: to}, speed, function() {
        if (to == 100 && jQuery.browser.msie)
            this.style.removeAttribute('filter');

        if (jQuery.isFunction(callback))
            callback();
    });
};

$(document).ready(function(){
    var settings = {maxWidth : 130, minWidth : 46, duration : 200};
	var currentBlock;

	function to_width(object, width) {
		object.stop().animate({width : width + 'px'}, {duration:settings.duration});
	}

	function to_vertical(object)
	{
		to_width(object, settings.minWidth);
		object.children('.title').addClass('vertical').siblings('.desc').stop().customFadeTo(settings.duration, 0);
	}

	function to_horizontal(object)
	{
		to_width(object, settings.maxWidth);
	    object.children('.title').removeClass('vertical').siblings('.desc').stop().customFadeTo(settings.duration, 100);
	}

    var lastBlock = $('ul.accordion li:last-child');
    $(lastBlock).css({width: settings.maxWidth + 'px'});

	currentBlock = lastBlock;

    $("ul.accordion li").not(lastBlock).each(function() {
        to_vertical($(this));
    });

    $('ul.accordion li').hover(function(){
        // All other blocks, except the last
        to_vertical(lastBlock);
		
        // Current Block
        lastBlock = $(this);
		to_horizontal(lastBlock);
    });
});

