/*Funciones para el carrusel*/
function Carousel(s, d, a) {
	this.duration = (typeof(d)!="undefined" ? d : 6500);
	this.autoplay = (typeof(a)!="undefined" ? a : false);
	this.selectorStr = (typeof(s[0])!="undefined" ? s[0] : '');
	this.imgStr = (typeof(s[1])!="undefined" ? s[1] : '');
	this.nfoStr = (typeof(s[2])!="undefined" ? s[2] : '');
	this.currentItm = 0; this.numberItms = $(s[0]).length;
	$(s[0]+':eq(0)').addClass('SL_active'); $(s[1]).css("display","none"); 
	$(s[1]+':eq(0)').css("display","block"); $(s[2]+':eq(0)').css("display","block");
	$(s[0]).each(this.bind(function(n){
		$(s[0]+':eq('+n+')').bind("click", {index:n}, this.bind(function(e) { if (this.currentItm!=e.data.index){ this.setActive(e.data.index); } return false; }) );
	}));
}
Carousel.prototype = {
	next: function() {
		this.currentItm = (this.currentItm+1) == this.numberItms ? 0 : (this.currentItm+1);
		this.setActive(this.currentItm);
	},
	previous: function() {
		this.currentItm = (this.currentItm-1) == -1 ? (this.numberItms-1) : (this.currentItm-1);
		this.setActive(this.currentItm);
	},
	setActive: function(index){
		this.currentItm = index;
		$(this.selectorStr+'.SL_active').toggleClass('SL_active');
		$(this.selectorStr+':eq('+index+')').toggleClass('SL_active');
		$(this.imgStr).fadeOut(); $(this.imgStr+':eq('+index+')').fadeIn();
		if(this.nfoStr!=''){ $(this.nfoStr).fadeOut(); $(this.nfoStr+':eq('+index+')').fadeIn() }
	},
	start: function( b ) {
		(typeof(b)!='undefined') ? $(b[0]).bind("click", this.bind(function(e) { this.previous(); return false; }) ) : (n=0);
		(typeof(b)!='undefined') ? $(b[1]).bind("click", this.bind(function(e) { this.next(); return false; }) ) : (n=0);
		if (this.autoplay) {this.interval = window.setInterval(this.bind(this.next),this.duration)}
	},
	bind: function( m ){
		var _this = this; 
		return( function(){ return( m.apply( _this, arguments ) ) } );
    }
}
