//***********Con Thumb y sin Flash***********//
(function($) {
	$.fn.ClaveSliderConThumb = function(param){
		
		var obj = $(this);
		var margen_temp=0;
		var cant_img=param.cant;
		var pos_actual=0;
		var width=parseInt(param.width)+parseInt(param.margen); //Width de la imagen
		var width_lista=width*cant_img;
		var pos_der_max=0;
		var pos_izq_max=cant_img-1;
		var timer_on=true;

		
			this.each(function() { 
				$(obj).css('width', (width_lista)+"px");

				
				//IZQUIERDA
				$("#mover_izq").click(function(){
					moverIzquierda();		
					clearInterval(timer);
					timer_on=false;
				});
			
				//DERECHA
				$("#mover_der").click(function(){
					moverDerecha();
					clearInterval(timer);
					timer_on=false;
				});
				
				function moverDerecha(){
					if(timer_on){
						clearInterval(timer);
                    	timer=0;
					}
					pos_actual-=parseInt(1);
					if((pos_actual<0)&&(pos_actual<=pos_der_max)){
						if(((pos_actual*-1)%cant_img)==0){
							$newCloneDer = $(('.imgDiv_0')+":first",obj).clone(true);
						}else{
							$newCloneDer = $('.imgDiv_'+(cant_img-(pos_actual*-1)%cant_img)+":first",obj).clone(true);
						}
						$(obj).prepend($newCloneDer.css("margin-left","-"+ width*((pos_actual*-1)) +"px"));
						pos_der_max--;
						width_lista+=parseInt(width);
						$(obj).css('width', (width_lista)+"px");
					}
					margen_temp+=parseInt(width);
					$(obj).animate({marginLeft: margen_temp}, "slow");
					if(timer_on){ timer = setInterval(moverIzquierda,8000);}
					
				};
				
				function moverIzquierda(){
					if(timer_on){
						clearInterval(timer);
						timer=0;
					}
					pos_actual+=parseInt(1);
					if(((cant_img-pos_actual)<4)&&(pos_actual>(pos_izq_max-3))){
						pos_izq_max=pos_actual+parseInt(3);
						$newCloneIzq = $(".imgDiv_"+((pos_actual+3)%cant_img)+":first",obj).clone(true);
						$(obj).append($newCloneIzq);
						width_lista+=parseInt(width);
						$(obj).css('width', (width_lista)+"px");
						
						if(((pos_izq_max/8)==cant_img)&& timer_on){
							for(w=0;w<7;w++){
								for(i=0; i<cant_img; i++){
									$(".imgDiv_"+i+":first",obj).remove();
								}
								pos_izq_max-=parseInt(cant_img);
								pos_actual-=parseInt(cant_img);
								margen_temp+=parseInt(width*cant_img);
								$(obj).css('marginLeft', margen_temp+"px");
							}
							clearInterval(timer);
							timer_on=false;
						}
					}	
					margen_temp-=parseInt(width);
					$(obj).animate({marginLeft: margen_temp}, "slow");
					if(timer_on){timer = setInterval(moverIzquierda,8000);}
				};
				$(".imgDiv2").hover(
						  function () {
							  if(timer_on){
								  clearInterval(timer);
								  timer=0;	  
							  }
						  }, 
						  function () {
							  if(timer_on){
								  timer = setInterval(moverIzquierda,8000);
							  }
						  }
				);
				
				$(".imgDiv").hover(
						  function () {
							  if(timer_on){
								  clearInterval(timer);
								  timer=0;	  
							  }
						  }, 
						  function () {
							  if(timer_on){
								  timer = setInterval(moverIzquierda,8000);
							  }
						  }
				);
				
				var timer = setInterval(moverIzquierda,8000);	
			});
	};
 })(jQuery);


//***********Con Flash y sin Thumb***********//
 (function($) {
    $.fn.ClaveSliderConFlash = function(param){
        
        var obj = $(this);
        var margen_temp=0;
        var cant_img=param.cant;
        var id_slider=param.id;
        var pos_actual=0;
        var width=parseInt(param.width)+parseInt(param.margen); //Width de la imagen
        var width_lista=width*cant_img;
        var pos_der_max=0;
        var pos_izq_max=cant_img-1;
        var timer_on=true;
        var timer = 0;
        
            this.each(function() { 
                $(obj).css('width', (width_lista)+"px");
                
                //IZQUIERDA
                $("#mover_izq").click(function(){
                    moverIzquierda();        
                });
            
                //DERECHA
                $("#mover_der").click(function(){
                    moverDerecha();
                });
                
                function todasacero(control){
                    if(control==-1){
                        for(a=0;a<cant_img;a++){
                            objeto = eval("window.document.imgDiv_" + a);
                            if(objeto!=undefined){
                                objeto.TGotoFrame("/animacion", 0);
                            }
                        }
                    }else{
                        for(a=0;a<cant_img;a++){
                            if(a!=control){
                                objeto = eval("window.document.imgDiv_" + a);
                                if(objeto!=undefined){
                                    objeto.TGotoFrame("/animacion", 0);
                                }
                            }
                        }
                    }
                };
                
                function ejecutarflash(pa){
                    timer = setInterval(moverIzquierda,8000);
                    objeto = eval("window.document.imgDiv_" + pa);
                    if(objeto!=undefined){
                        objeto.TGotoFrame("/animacion", 0);
                        objeto.TPlay("/animacion");
                    }
                };
                
                
                function moverDerecha(){
                    todasacero(pos_actual)
                    clearInterval(timer);
                    timer=0;    
                    pos_actual-=parseInt(1);
                    if(pos_actual<0){
                    	margen_temp-=parseInt(width_lista)-parseInt(width);
                    	$(obj).animate({marginLeft: margen_temp}, "slow",function(){ 
                            ejecutarflash(pos_actual);                      
                        });
                        pos_actual=parseInt(cant_img)-1;
                    }else{
                        margen_temp+=parseInt(width);
                        $(obj).animate({marginLeft: margen_temp}, "slow",function(){
                            ejecutarflash(pos_actual);  
                        });
                    }
                };
                
                function moverIzquierda(){
                    todasacero(pos_actual)
                    clearInterval(timer);
                    timer=0;    
                    pos_actual+=parseInt(1);
                    
                    if(pos_actual>=cant_img){
                        margen_temp+=parseInt(width_lista)-parseInt(width);
                        $(obj).animate({marginLeft: margen_temp}, "slow",function(){
                            ejecutarflash(pos_actual);  
                        });
                        pos_actual=0;
                    }else{
                        margen_temp-=parseInt(width);
                        $(obj).animate({marginLeft: margen_temp}, "slow",function(){
                            ejecutarflash(pos_actual);  
                        });
                    }   
                };
       
                ejecutarflash(0);

            });
    };
 })(jQuery);

