function marco_fotos(marco,fondo,ancho,alto,mostrar,color)
{
	if(!mostrar)
	{
		$(marco).destroy();
		return;
	}
	
	var dim = window.getCoordinates();
	var escrol=window.getScroll();

	var top=100+escrol.y;
	var left= (dim.width/2);
	
	new Element('div', {
	styles: {
		'z-index':101,
		'position':'absolute',
		'height':alto,
		'width':ancho,
		'top':top,
		'left':left,
		'margin-left':-(ancho/2),
		'opacity':1,		
		'background-color':color,
		'text-align':'left',
		'background-position': 'center center',
		'background-repeat':'no-repeat',
		'background-image':'url('+fondo+')'
	},
	id:marco
	}).injectTop(document.body);
	
	//$(marco).morph({'height':[alto_ventana],'opacity':[1]});
}

function correr_cortinilla(cosa,colores,poner)
{
	if(poner)
	{
		 $$('.text_area_desple').setStyle('opacity',0);
	}
	else
	{
		$$('.text_area_desple').setStyle('opacity',1);
		$(cosa).destroy();
		return;
	}	
	
	//leemos la altura del body
	//var escrol=window.getScroll();

	var altura=window.getScrollSize().y;
	new Element('div', {
	styles: {
		'z-index':100,
		'width':'100%',
		'position':'absolute',
		'top':0,
		'left':0,
		'height':altura,
		'background-color' : colores,
		'opacity':0.5
	},
	id:cosa
	}).injectTop(document.body);
	
}

function cerrar()
{
	correr_cortinilla('cortinilla','#000',false);
	marco_fotos('panel','/rsc/imagenes/web/biblia.gif',100,100,false,'#FFFFFF');
}

document.addEvent('domready',function(){
	$try(function(){
		$('plano').addEvent('click',function(){
			correr_cortinilla('cortinilla','#000',true);
			marco_fotos('panel','/rsc/imagenes/web/biblia.gif',100,100,true,'#FFFFFF');
			new Request.HTML({
				url:'/index.php?localizacion/flotante/', 
				method:'post',
				update: $('panel'),
				evalScripts: true,
				onComplete:function(){	
					
					//quitamos la ruedecica
					$('panel').setStyle('background-image',''); 
				
					$('flotante').setStyles({'opacity':0,'position':'absolute','z-index':'200'});
						
					//dimensiones
					var dim_tabla = $('flotante').getCoordinates();
					var dim_marco = $('panel').getCoordinates();
		
					var altura=dim_tabla.height;
					var anchura=dim_tabla.width;
					var top=dim_marco.top+2;
					var left=-anchura/2;
										
					//hacemos aparecer la ventanica
					var cambio=new Fx.Morph($('panel'));
					var aparece=new Fx.Morph($('flotante'));
					
					cambio.start({'margin-left':left,'width':anchura}).chain(
						function(){
							cambio.start({'height':altura})
						},
						function(){
							aparece.set({'position':'relative'}),
							aparece.start({'opacity':1})
						}
					
					);	

		
				}
			}).post();				
		});	
	});
	
	$try(function(){
		$$('.producto').addEvent('click',function(){
			var hijos=this.getChildren('.referencia');
			var id=new Object;
			id.referencia= hijos[0].get('text');
			correr_cortinilla('cortinilla','#000',true);
			marco_fotos('panel','/rsc/imagenes/web/biblia.gif',100,100,true,'#FFFFFF');
			new Request.HTML({
				url:'/index.php?catalogo/articulo/'+$time(), 
				method:'post',
				update: $('panel'),
				evalScripts: true,
				onComplete:function(){	
					
					//quitamos la ruedecica
					$('panel').setStyle('background-image',''); 
				
					$('flotante').setStyles({'opacity':0,'position':'absolute','z-index':'200'});
						
					//dimensiones
					var dim_tabla = $('flotante').getCoordinates();
					var dim_marco = $('panel').getCoordinates();
		
					var altura=dim_tabla.height;
					var anchura=dim_tabla.width;
					var top=dim_marco.top+2;
					var left=-anchura/2;
										
					//hacemos aparecer la ventanica
					var cambio=new Fx.Morph($('panel'));
					var aparece=new Fx.Morph($('flotante'));
					
					cambio.start({'margin-left':left,'width':anchura}).chain(
						function(){
							cambio.start({'height':altura})
						},
						function(){
							aparece.set({'position':'relative'}),
							aparece.start({'opacity':1})
						}
					
					);	
					new Asset.javascript('/rsc/js/articulo.js', {id: 'myScript'});

		
				}
			}).post(id);				
		});	
	});

	$try(function(){
		//el tip
		tip=new Tips('.imagenes',{
			className:'imagen_acabado'
		});
	
	
		$$('.imagenes').each(function(tip){
	
			var imgSrc = tip.retrieve('tip:text');
			tip.store('tip:text', new Element('img',{'src':imgSrc}));
			//tip.store('tip:title');
	
		});
	});

	
	$('carrito_principal').addEvent('click',function(){
		correr_cortinilla('cortinilla','#000',true);
		marco_fotos('panel','/rsc/imagenes/web/biblia.gif',100,100,true,'#FFFFFF');		
		new Request.HTML({
			url:'/index.php?catalogo/carrito/', 
			method:'post',
			update: $('panel'),
			evalScripts: true,
			onComplete:function(){
					//quitamos la ruedecica
					$('panel').setStyle('background-image',''); 
				
					$('flotante').setStyles({'opacity':0,'position':'absolute','z-index':'200'});
						
					//dimensiones
					var dim_tabla = $('flotante').getCoordinates();
					var dim_marco = $('panel').getCoordinates();
		
					var altura=dim_tabla.height;
					var anchura=dim_tabla.width;
					var top=dim_marco.top+2;
					var left=-anchura/2;
										
					//hacemos aparecer la ventanica
					var cambio=new Fx.Morph($('panel'));
					var aparece=new Fx.Morph($('flotante'));
					
					cambio.start({'margin-left':left,'width':anchura}).chain(
						function(){
							cambio.start({'height':altura})
						},
						function(){
							aparece.set({'position':'relative'}),
							aparece.start({'opacity':1})
						}
					
					);					
				new Asset.javascript('/rsc/js/carrito.js');
			}
		}).post();	
	});	
});