/*!
 * jQuery Ramdom Pets v1
 * http://ideasdigitally.com/
 * Autor: Victor Chavarro
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *
 * Date: Mon Feb 24 11:08:29 2011 -0500
 */
(function($){
	
	$.fn.extend({
		random_pet: function(opciones){
			var defecto = {
					tiempo_duran: 2000, //tiempo que duran visible las imagenes
					tiempo_desvanecido: 800, //tiempo en aparecer y desvanecer las imagenes
					imagen1: 'image/oferta/02.png',
			  		imagen2: 'image/oferta/04.png',
			  		imagen3: 'image/oferta/02.png',
			  		imagen4: 'image/oferta/04.png',
			  		animacion: 'fade',
					url:'http://www.monsterhigh.com/'
			};
			var opciones = $.extend(defecto, opciones);
			
			return this.each(function(){
				var opcion = opciones;
				var objeto = $(this);
				
				
				objeto.html(
						"<a href='secciones/noticiasMas.php?not=10&id=239' target='_self'><img src='"+opcion.imagen1+"' alt='imagen1' class='pet_hidden' id='img1' /></a>" +
						"<a href='secciones/noticiasMas.php?not=10&id=250' target='_self'><img src='"+opcion.imagen2+"' alt='imagen2' class='pet_hidden' id='img2'/></a>" + 
						"<a href='secciones/noticiasMas.php?not=10&id=239' target='_self'><img src='"+opcion.imagen3+"' alt='imagen3' class='pet_hidden' id='img3'/></a>" + 
						"<a href='secciones/noticiasMas.php?not=10&id=250' target='_self'><img src='"+opcion.imagen4+"' alt='imagen4' class='pet_hidden' id='img4'/></a>");
				
				var tiempo_retardo = 0;
				var numero_imagen = 1;
				var tiempo_reinicio = (opcion.tiempo_duran+opcion.tiempo_desvanecido+1000)*6;
				
				switch(opcion.animacion)
				{
				case 'fade':
					
							for(i=1;i<=4;i++){
								
								$("#img"+i).delay(tiempo_retardo).fadeIn(opcion.tiempo_desvanecido);
								$("#img"+i).delay(opcion.tiempo_duran).fadeOut(opcion.tiempo_desvanecido);	
								tiempo_retardo = ((2*opcion.tiempo_desvanecido)+opcion.tiempo_duran+200)*i;
								
								
				
							}

							$("#img6").delay(((2*opcion.tiempo_desvanecido)+opcion.tiempo_duran+200)*5).animate({top: "0"}, opcion.tiempo_desvanecido);
							$("#img6").delay(opcion.tiempo_duran).animate({top: "-213"}, opcion.tiempo_desvanecido);
							var t=setInterval(function(){
								var tiempo_retardo = 0;
								var numero_imagen = 1;
								
								for(i=1;i<=4;i++){
									
									$("#img"+i).delay(tiempo_retardo).fadeIn(opcion.tiempo_desvanecido);
									$("#img"+i).delay(opcion.tiempo_duran).fadeOut(opcion.tiempo_desvanecido);	
									tiempo_retardo = ((2*opcion.tiempo_desvanecido)+opcion.tiempo_duran+200)*i;
									
					
								}
								$("#img6").delay(((2*opcion.tiempo_desvanecido)+opcion.tiempo_duran+200)*5).animate({top: "0"}, opcion.tiempo_desvanecido);
								$("#img6").delay(opcion.tiempo_duran).animate({top: "-213"}, opcion.tiempo_desvanecido);
							},tiempo_reinicio);
				  break;
				case 'slide':
					
					
							for(i=1;i<=4;i++){
								
								$("#img"+i).delay(tiempo_retardo).fadeIn(opcion.tiempo_desvanecido);
								$("#img"+i).delay(opcion.tiempo_duran).fadeOut(opcion.tiempo_desvanecido);	
								tiempo_retardo = ((2*opcion.tiempo_desvanecido)+opcion.tiempo_duran+200)*i;
								
								
				
							}

							$("#img6").delay(((2*opcion.tiempo_desvanecido)+opcion.tiempo_duran+200)*5).animate({top: "0"}, opcion.tiempo_desvanecido);
							$("#img6").delay(opcion.tiempo_duran).animate({top: "-213"}, opcion.tiempo_desvanecido);
							var t=setInterval(function(){
								var tiempo_retardo = 0;
								var numero_imagen = 1;
								
								for(i=1;i<=4;i++){
									
									$("#img"+i).delay(tiempo_retardo).fadeIn(opcion.tiempo_desvanecido);
									$("#img"+i).delay(opcion.tiempo_duran).fadeOut(opcion.tiempo_desvanecido);	
									tiempo_retardo = ((2*opcion.tiempo_desvanecido)+opcion.tiempo_duran+200)*i;
									
					
								}
								$("#img6").delay(((2*opcion.tiempo_desvanecido)+opcion.tiempo_duran+200)*5).animate({top: "0"}, opcion.tiempo_desvanecido);
								$("#img6").delay(opcion.tiempo_duran).animate({top: "-213"}, opcion.tiempo_desvanecido);
							},tiempo_reinicio);
					
					
				  break;
				/*default:
				  code to be executed if n is different from case 1 and 2*/
				}
				
					
			});
			
		}
	
	});
	
})(jQuery);


