acordeon = {
	
	opened: null,
	$slices: null,
	n_slices: 0,
	i: 3,
	
	init: function(container){
		this.$slices = $(container).children();
		this.n_slices = this.$slices.length;
		this.opened = this.$slices.length - 1;
		for (var i = 0; i < this.n_slices; i++) {
			this.$slices[i].name = i;
			this.$slices[i].style.left = parseInt(i * 143) + 'px';
		}
		this.$slices.bind('click',acordeon.animate);
		$(this.$slices[0]).trigger('click');
		/*this.$slices.find('div').each(function(){
			//this.onselectstart = function () { return false; } // ie
			//this.onmousedown = function () { return false; } // mozilla
		});*/
		$(container).find('a').bind('click',function(e){
			e.stopPropagation();
		});
	},
	
	animate: function(e){
		if (acordeon.i == this.name) return false;
		acordeon.i = this.name;
		$(this).css({'backgroundPosition': '0 0', 'cursor':'default' });//animate({ backgroundPosition: "(0 0)" },200);
		var num = acordeon.opened - acordeon.i;
		
		var $toFade = $();
		acordeon.$slices.each(function(){
			if (this.name != acordeon.i) $toFade.push(this);
		});

		$toFade.css({'backgroundPosition': '0 130px', 'cursor': 'pointer' })/*animate({ backgroundPosition: "(0 130px)" },200)*/.find('div').animate({ opacity: 0.01 },50);//fadeOut(150);
		//$(acordeon.$slices[acordeon.i]).children().show();

		if (num < 0) {
			acordeon.roll_right(num);
		} else {
			acordeon.roll_left(num);
		}
	},
	
	roll_right: function(n){
		n *= -1;
		var $toRoll = $();
		for (var j = 1; j <= n; j++) {
			$toRoll.push(acordeon.$slices[acordeon.opened + j]);
		}
		$toRoll.animate({ left: "-=387px" },200,function(){
			$(acordeon.$slices[acordeon.i]).find('div').show().animate({ opacity: 1 },50);//.animate({'margin-left':'+=5px'},500);//fadeIn(150);
		});
		acordeon.opened = acordeon.i;
	},
	
	roll_left: function(n){
		var $toRoll = $();
		for (var j = 0; j < n; j++) {
			$toRoll.push(acordeon.$slices[acordeon.opened - j]);
		}
		$toRoll.animate({ left: "+=387px" },200,function(){
			$(acordeon.$slices[acordeon.i]).find('div').show().animate({ opacity: 1 },50);//.animate({'margin-left':'+=5px'},500);//fadeIn(150);
		});
		acordeon.opened = acordeon.i;
	}
	
};
$(function(){
	acordeon.init('#acordeon-processos ul');
});
