var Contador=Class.create({
	cont:2,	
	periodicidad:1,
	target:"",
	initialize:function(){
		//alert('contador');
		//this.periodico();
		this.adition();
		this.ajax();
	},
	periodico:function(){
		var c=Math.ceil(this.cont);
		if(c>2){this.periodicidad=16};
		new PeriodicalExecuter(function(){
			
			if($('cont_0')){$('cont_0').hide();}
			c++;
			new Ajax.Request("gestion/galeria/galeria.php", {
						method: "get",
			            parameters: '?random='+c,
			            evalScripts:true,
						onSuccess: function(transport){
							$('cont_0').update(transport.responseText);
							new Effect.Appear('cont_0',{duration:2});
							var e=$('infoGaleriaABS');
							if(e){
								//e.update('asfd');
							}
							
						}
				
				
				
			});
		

		}, 6);
		
	},
	adition:function(){
		var r=new Element('div');
		//this.ajax();
		r.setStyle({position:'absolute',top:'0px',left:'0px',display:'none'});
		//r.update("");
		r.id="cont_"+this.cont;
		this.target="cont_"+this.cont;
		//r.update("cont_"+this.cont);
		$('cont_0').appendChild(r);
	},
	ajax:function(){
		var c=this.cont;
		var a=this;
		$(a.target).absolutize();$(a.target).hide();
		
					new Ajax.Request("gestion/galeria/galeria.php", {
						method: "get",
			            parameters: '?random='+c,
			            evalScripts:true,
						onSuccess: function(transport){					
							
							
							$(a.target).update(transport.responseText);
							new Effect.Appear(a.target,{duration:1.7,afterFinish:function(){
								
								window.setTimeout(function() {
									
									a.cont++;
									a.target="cont_"+a.cont;
									a.adition();
									a.ajax();
								}, 6000);
								
							}});
							var e=$('infoGaleriaABS');
							if(e){
								//e.update('asfd');
							}
							
						}
				
				
				
			});
	}
	
});

var galeriaABS=Class.create({
	maximoNumeroImg:20,
	numeroInicial:0,
	
	initialize:function(){
		var est=this;
		if($('btnVerTodas')){Event.observe($('btnVerTodas'),'click',function(){est.verTodas();})};
		$$('#imagenes_modelos_thumb div.modelo_peq').each(function(el){
			//alert(bot.id);
			Event.observe(el,'mouseover',function(){
				$$('#divCarga div.flotante').each(function(ely){
					ely.hide();
				
				});
			});
			Event.observe(el,'click',function(){
				/*var id=el.id.replace('flotante_','');
				$(id).setStyle({zIndex:1000});
				el.absolutize();
				new Effect.Morph(el,{
				  style:'background:#f00;width:300px;height:300px',
				  duration:0.8
				});*/
				$$('#divCarga div.flotante').each(function(ely){
					ely.hide();
				
				});	
				$('flotante_'+el.id).show();	
				$$('#imagenes_modelos_thumb a.imagenAsociada').each(function(ely){
					ely.hide();
				
				});				
				$$('#flotante_'+el.id+' a.imagenAsociada').each(function(ely){
					ely.show();
					ely.setStyle({zIndex:1000});
					var i=ely.href;
					i=i.replace("http://www.abs.es/","");
					i="thumbs/phpThumb.php?src=../"+i+"&w=120";
					i="<img src='"+i+"'>";
					//http://www.abs.es/imagenes/modelos_casas/jucar/modelo_jucar_exterior4_ElBoaloMadrid.jpg
					ely.update(i);
				
				});

			})
		
		});
		
		
	},
	verTodas:function(){
		var gal=$('container_galeria');
		if(gal){
						new Ajax.Request("gestion/galeria/galeria.php", {
							method: "get",
				            parameters: '?todas=0&n='+this.maximoNumeroImg+'&init='+this.numeroInicial,
				            evalScripts:true,
							onSuccess: function(transport){
								$('containerTodas').update(transport.responseText);
								new Effect.Appear('containerTodas');
								
								
							}			
						});
				/*new Effect.Parallel(
					[ new Effect.SlideDown( 'container_galeria', { sync: true, duration: resizeDuration, from: 0.0, to: 1.0 }),
					  new Effect.Appear('containerTodas', { sync: true, duration: resizeDuration }) ],
					{ duration: resizeDuration, afterFinish: function() {
						// update overlay size and update nav
						//var arrayPageSize = getPageSize();
						//Element.setHeight('overlay', arrayPageSize[1]);
						//myLightbox.updateNav();
						}
					}
				);*/
			
			
		}
		$$('#containerTodas div').each(function(img){});
	}
	
	
	
});
/*
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*/
var Slides=Class.create({
	prefijo:'slideshow',
	slide:new Object({		
		prefijo:'slideshow',
		inicio:function(prefijo,ini,fin,delay){

			var cont=0;
			start_slideshow(ini,fin,delay);
    
		    function start_slideshow(start_frame, end_frame, delay) {
		        setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
		    }
		                            
		    function switch_slides(frame, start_frame, end_frame, delay) {
		        return (function() {
			            Effect.Fade(prefijo + frame);
			            
			            
			            if (frame == end_frame) { 
			            	cont++;
			            	ajax(prefijo + frame,cont);
			            	ajax(prefijo + (frame-1),cont+1);
			            	ajax(prefijo + (frame-2),cont+2);
			            	ajax(prefijo + (frame-3),cont+3);
			            	frame = start_frame;
			            	
			            	
			            	
			            } 
			            else { frame = frame + 1; }
			            setTimeout("Effect.Appear('"+prefijo + frame + "');", 850);
			            setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);

		        })
		    }
		    function ajax(target,c){
		
				new Ajax.Updater(target, 'gestion/galeria/galeria2.php', {evalScripts:true,method:'get',
				  parameters: { random: c }
				});
				
				
			}			
		}//fin funcion inicio		
	}),
	
	
	initialize:function(){
		//this.slide.inicio('slideshow',1, 4, 5000);
		//$('listadoSlideShow').hide();

		
	},
	mueveADerecha:function(){
		var pos=$('cont_0').cumulativeOffset();
		new Effect.MoveBy('listadoSlideShow',pos[1],pos[0],{afterFinish:function(){Effect.Appear('listadoSlideShow')}});
	},
	mueveA:function(y,x){
		
	},
	ajax:function(target,c){
		
		new Ajax.Updater(target, 'gestion/galeria/galeria2.php', {evalScripts:true,
		  parameters: { random: c }
		});
		
		
	},
	creaCargador:function(){
		var a=this;
		var el=new Element('div');
		el.update("<div id='listadoSlideShow' style='text-align:left;position:relative;top:20px;left:50px'></div>");
		$('cuerpo_der_cabecera').appendChild(el);
		new Ajax.Updater(el, 'gestion/galeria/galeria2.php', {evalScripts:true,method:'get',
		  parameters: { inicio: 0 },onSuccess:function(){a.slide.inicio('slideshow',1, 4, 5000);}
		});
		
		/**/
		var el=new Element('div');
		el.update("<div id='infoSlideShow' style='text-align:left;position:absolute;top:0px;left:0px;z-index:1000;border:0px dotted white;width:200px;height:150px;cursor:pointer'></div>");
		var r=new Element('div');
		Event.observe(r,'click',function(){$('menuContextualSlideShow').toggle();})

		r.update("<div style='position:absolute;top:0px;left:210px'><a id='btnInfoSlideShow' href='#'></a><div id='menuContextualSlideShow' style='display:none'></div></div>");
		el.appendChild(r);
		$('cuerpo_der_cabecera').appendChild(el);
	},
	infoGaleria:function(texto){
		var el=$('menuContextualSlideShow');
		//if(el){new Insertion.Bottom(el,texto);};		

	}
	
});//fin de slides












/*var album = { 
  startup: function() { 
  //alert('asfd');
    new PeriodicalExecuter(album.cycle, 5) // change image every 5 seconds 
  }, 
  cycle: function() { 
    new Effect.Fade('imagenAlbum', { // the id of the <DIV> containing the photos 
      duration: 1, 
      fps: 50, 
      afterFinish: function() { 
        new Ajax.Updater('imagenAlbum','/php/album.php?id=1', { // URL for next <IMG> tag 
          asynchronous: true, 
          onSuccess: function() { 
            new Effect.Appear('imagenAlbum', {
              duration: 1,
              fps: 50,
              queue:'end'
            })
          } 
        }) 
      } 
    }) 
  } 
}*/
var albumABS=Class.create({
  target:'',//es el container que va a englobar al carrusel
  lista:new Hash(),
  listadoBruto:"",
  slide:new Object({
	target:'',
	  startup: function() { 
	  //alert('asfd');
	  var target=this.target;
	    new PeriodicalExecuter(function() { 
		
		//alert(albumA.target);
	    new Effect.Fade(target, { // the id of the <DIV> containing the photos 
	      duration: 1, 
	      fps: 50, 
	      afterFinish: function() { 
	        new Ajax.Updater(target,'/php/album.php?id=1', { // URL for next <IMG> tag 
	          asynchronous: true, 
	          onSuccess: function() {
//alert(tg);			  
	            new Effect.Appear(target, {
				
	              duration: 1,
	              fps: 50,
	              queue:'end'
	            })
	          } 
	        }) 
	      } 
	    }) 
	  }, 5) // change image every 5 seconds 

	  }
  
  }),
  initialize:function(obj){
  
  this.target=obj.target;
  },
  inicio:function(){
  this.startup();
  },
  obtieneLista:function(){
    var album=this;
	new Ajax.Request('php/album.php',{method:'get',evalScripts:true,parameters:{lista:'todos'},
		onSuccess:function(transport){
			eval(transport.responseText);
			album.slide.target=album.target;
			if($(album.target)){album.slide.startup();}
			
									 }}
					);
  },
  
  creaContainerAlbum:function(){


  } ,
  alerta:function(){
  //alert(this.listadoBruto);
  }





});

//window.onload = album.startup

var SuperSlide=Class.create({
	divCarga:'cont_0',
	target:'slideModelo',
	init:1,
	fin:4,
	delayInicio:2000,
	obj:{},
		initialize:function(obj){
			this.obj=obj;
			this.target=obj.target;
			this.init=obj.init;
			this.fin=obj.fin;
			this.delayInicio=obj.delayInicio;
			/*this.obj.parameters.location=location;*/
		},
		inicio:function(){
			var d=this;			
			this.start_slideModelo(this.target,d,this.init, this.fin, this.delayInicio);
			
		},
		start_slideModelo:function(target,obj,start_frame, end_frame, delay) {
	        setTimeout(obj.switch_slides(target,obj,start_frame,start_frame,end_frame, delay), delay);
	    },	                            
	    switch_slides:function (target,obj,frame, start_frame, end_frame, delay) {
	        return (function() {
	            Effect.Fade(target + frame);
	            if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
	            setTimeout("Effect.Appear('"+target + frame + "');", 850);
	            setTimeout(obj.switch_slides(target,obj,frame, start_frame, end_frame, delay), delay + 5850);
	        })
	    },
	    carga:function(){
	    	var ob=this;
	    	new Ajax.Updater(this.divCarga,this.obj.url,{parameters:this.obj.parameters,method:'get',
	    					onSuccess:function(){
	    						ob.inicio();
	    						window.setTimeout(function()
	    											{
	    												ob.creaBotonera();
	    											},2000);
	    					}
	    	});//fin del ajax updater
	    },
	    creaBotonera:function(){
	    	var ob=this;
	    	var div=$(this.divCarga);
	    	Event.observe(div,'click',function(){
					/*ob.obj.parameters.ID=9;
					ob.carga();
					ob.inicio();*/
	    		
	    	});
	    	var r=new Element('div');
	    	r.update("----");
	    	r.absolutize();
	    	r.hide();
	    	r.setStyle({zIndex:1000});
	    	//div.appendChild(r);

	    	
	    }
});
var carruselFotos1=new SuperSlide({target:'slideModelo',init:1,fin:4,delayInicio:2000,url:'carrusel/php/scripts_carrusel.php',parameters:{ID:1,campo:'HTML'}});
function runCarrusel(){
	//start_slideModelo(1, 4, 2000);
	
	carruselFotos1.carga();
}




