var tiempo=10000;

jQuery.fn.rotar = function() {
	//calcular total_entries
	var currentImage = 0, oldImage = 0; 
	var pause='';
	//alert('rotar');
	var $container = $(this); 
	//alert('id animar '+$container.attr('id'));
	var total_entries=$container.find('div[id*=zlideshow]').length;
	//alert($container.attr('id')+' imagenes '+total_entries);
	var imageRotate = function() { 
		//alert ('oldimage '+oldImage+' current '+currentImage);
		if (total_entries > 1) {
			currentImage = oldImage + 1;;
		  
		if (oldImage >= (total_entries-1)) {
			currentImage=0;
		} 
		//alert ('oldimage '+oldImage+' current '+currentImage); 
	   
		var divcurrent=$container.find('div[id*=zlideshow]').eq(currentImage);
		var texto_im=divcurrent.html(); 
		//alert(texto_im);
		$container.find('#div_imagen_ppal').html();
		$container.find('#div_imagen_ppal').html(texto_im);
	   
	    $container.find('div[id*=ss_texto_]').eq(currentImage).animate({'width':'toggle','opacity':'1.0'},500);  $container.find('div[id*=ss_texto_]').eq(oldImage).animate({'width':'toggle','opacity':'1.0'},500);//500 es el tiempo que tarda en hacer el animate
	
		
		
		
		oldImage = currentImage;
		pause = setTimeout(imageRotate, tiempo);
		//alert(oldHeadline+'.. old (abajo) current (arriba)  '+currentHeadline); 
		}
	}
	pause = setTimeout(imageRotate, tiempo);
	
	$container.find('a.ssImagen').click( function() {
		clearTimeout(pause);
		
		var currentSlide=$(this).attr('id');
		  currentSlide=currentSlide.substr(currentSlide.indexOf('_')+1,currentSlide.length);
		
		if (currentImage == ((currentSlide*1)-1)) {
			//no hace nada
		} else {
			currentImage=(currentSlide*1)-1;
			divcurrent=$container.find('div[id*=zlideshow]').eq(currentImage);
			texto_im=divcurrent.html(); 
			$container.find('#div_imagen_ppal').html();
			$container.find('#div_imagen_ppal').html(texto_im);  
		    $container.find('div[id*=ss_texto_]').eq(currentImage).animate({'width':'toggle','opacity':'1.0'},500);  $container.find('div[id*=ss_texto_]').eq(oldImage).animate({'width':'toggle','opacity':'1.0'},500);
			oldImage = currentImage*1;
		}
		pause = setTimeout(imageRotate, tiempo);
		return false;
	})
	
}



