var mwslider = {
	w:907,
	h:360,
	timer:null,
	interval:5,
	animate_time:2,
	total:0,
	current:0,
	next:0,
	prev:0,
	max:0,
	min:0,
	running:false,
	elems: null,
	start:function() {
		var numtotal = jQuery(".slider_img_list li").length - 1;
		jQuery(".slider_img_list").append(jQuery(".slider_img_list li").eq(0).clone());
		jQuery(".slider_img_list").prepend(jQuery(".slider_img_list li").eq(numtotal).clone());
		this.elems = jQuery(".slider_img_list li");
		this.total = this.elems.size();
		this.current = 1;
		this.next = 2;
		this.prev = 0;
		this.max = this.total - 1;
		jQuery(".slider_img_list").css({width:((mwslider.w * this.total) + mwslider.w + 5) + "px",left:((mwslider.w * -1))});
	},
	doSlide:function(direction) {
		if(this.running) {
			return false;
		}
		if(this.timer!=null) {
			clearInterval(this.timer);
			this.timer = setInterval("mwslider.doSlide(" + direction + ")",(this.interval + this.animate_time) * 1000);
		}
		this.running = true;
		direction = (direction=='fwd' || direction==1 || direction=='+' || direction=='next') ? 1 : -1;
		this.changeSlide(direction);
		var c = this.current + 0;
		var n = this.next + 0;
		var p = this.prev + 0;
		var x = (direction==1) ? n : p;
		var t = this.animate_time;
		jQuery('.slider_img_list').animate({left:((c*mwslider.w) * -1)},t * 1000,function(){ 
			if(mwslider.current == mwslider.max) {
				mwslider.current = 1;
				jQuery(".slider_img_list").css({left:((mwslider.w * mwslider.current) * -1)});
			} else {
				if(mwslider.current == 0) {
					mwslider.current = mwslider.max - 1;
					jQuery(".slider_img_list").css({left:((mwslider.w * mwslider.current) * -1)});
				} else {
					
				}
			}
			mwslider.running=false;
		});
	},
	changeSlide:function(direction) {
		this.current = (this.current + direction < 0) ? this.max : ((this.current + direction > (this.max)) ? 0 : this.current + direction);
		this.prev = (this.current == 0) ? this.max : this.current - 1 ;
		this.next = (this.current == this.max) ? 0 : this.current + 1 ;
	},
	play:function(direction) {
		direction = (direction=='fwd' || direction==1 || direction=='+' || direction=='next') ? 1 : -1;
		this.timer = setInterval("mwslider.doSlide(" + direction + ")",this.interval * 1000);
	}
};

jQuery(function() {
    
	mwslider.start();
	mwslider.play('fwd');
	jQuery(".sc_bak").click(function() {
		mwslider.doSlide(-1);
		return false;
	});
	jQuery(".sc_fwd").click(function() {
		mwslider.doSlide(1);
		return false;
	});
    
    //para el slider
    jQuery(".pdet_title").click(function(){
        jQuery(".pdet_title").removeClass("pdet_active");
        var id = jQuery(this).addClass("pdet_active").attr("id").replace("pdet_t","");
        jQuery(".pdn_cont").removeClass("pdn_cont_active");
        jQuery("#pdet_c"+id).addClass("pdn_cont_active");
    });
    
    slide_control();
});
var slide_timer = null;
var slide_images = 0;
var slide_control = function(){
    jQuery(".slide_subhead > img").animate({opacity: 0},1).each(function(i){
		slide_images++;
	});
    var this_id = '';
    jQuery(".slide_subhead > .head_img").animate({opacity: 0},1)
    jQuery("#img_1").animate({opacity: 1},0);
    slide_timer = setTimeout('slide_animations(0)',4000);
}
var cur_img = 1;
var slide_animations = function(img_id) {
	if(slide_timer) {
		clearTimeout(slide_timer);
	}
	if(img_id==0) {
		img_id = (cur_img==slide_images) ? 1 : ((cur_img*1)+1);
	}
	cur_img=img_id;
	jQuery(".slide_subhead > .head_img:visible").animate({opacity: 0},800);
	jQuery("#img_"+img_id).animate({opacity: 1},800);
	slide_timer = setTimeout('slide_animations(0)',6000);
}