﻿var AgregarFavoritos=function(l,t){			
	new Request.JSON({url: "/json-favoritos/", onComplete: function(c){
		AjaxAccion(1);
		alert('La seccion actual fue agregada satisfactoriamente a sus Favoritos');
		$('addfav').dispose();
	}}).get({'l':l,'t':t});
	AjaxAccion(0)
}
var EliminarFavorito=function(i){
	new Request.JSON({url: "/json-favoritos.eliminar/", onComplete: function(c){
		AjaxAccion(1);
		alert('El elemento fue eliminado satisfactoriamente de sus Favoritos');
		$('fav-'+i).dispose();
	}}).get({'i':i});
	AjaxAccion(0)
}
var Galeria={

	mostrando:false,
	
	init:function(){
		this.obj=$('lb');
		if(this.obj!=undefined){
			var tmp=this.obj;
			this.hoja=this.obj.getElement('.hoja');
			this.window={};
			this.window.height=window.getScrollHeight();
			this.window.width=window.getSize().x;
			this.window.top=window.getScrollTop();
			this.window.left=window.getScrollLeft();
			this.obj.setStyle('height',this.window.height+'px');
		}
	},
	
	mostrar: function(){
		this.mostrando=true;
		var caldir=$('caldir');
		if(caldir!=undefined){
			var r=[];
			caldir.getElements('div').each(function(g,i){
				r.push(g);
				g.els=r.slice(0,i+1);
				g.i=i+1;
				g.addEvent('mouseenter',function(e){
					this.els.each(function(a){
						a.setStyle('background-position','0 0');
					});
				});	
				g.addEvent('mouseleave',function(){
					this.els.each(function(a){
						a.setStyle('background-position','-18px 0');
					});
				});
				g.addEvent('click',function(e){
					var ct=document.getElement('.cual');
					e.stop();
					ct.setStyle('display','none');
					new Request.JSON({url: "/json-calificar/", onComplete: function(c){
						AjaxAccion(1);
						if(!c.resultado[0].res) alert('Ya realizaste tu voto');
						else{
							$('drating').set('html',c.resultado[0].total);
							$('dvotos').set('html',c.resultado[0].votos);
							alert('Calificacion Recibida');
						}
					}}).get({'c':this.i,'id':caldir.title,submenu:ct.title});
					AjaxAccion(0)
				});
			});
		}
		var tipz = new Tips('.tooltiip',{  
			className: 'tipz',  
      hideDelay: 50,  
      showDelay: 50  
    });  
		tipz.addEvents({  
			'show': function(tip) {  
				tip.fade('in');  
			},  
      'hide': function(tip) {  
				$$('.tipz').each(function(a){
						a.fade('out'); 
					});
			}  
		});
		
		$('tooltip').setStyle('display','none');
		
    var mmm=$$('div.arti');
    if(mmm!=undefined){
      mmm.getElement('.cc').getElements('img').each(function(g){
        g.addEvent('click',function(e){
          new Fx.Scroll(window).toElement('imagenes');
					e.stop();
				});
      });
    }
		if($('nzSlideGal')) $('nzSlideGal').setStyle('display','block');
		this.obj.setStyle('display','block');
		this.hoja.setStyle('opacity',1);
		this.hoja.setStyle('width','960px');
		this.obj.morph = new Fx.Morph(this.hoja,{duration:800});	
		this.obj.morph.start({
			opacity: [0,1],
			width: ['800px','960px']
		});
		PintarTitulos()
		if(!Browser.Engine.trident) new Accordion($('contdir'), 'h3.toggler', 'div.cntdir',{alwaysHide:true});
		this.obj.getElement('.fondo').setStyle('opacity',0.45).addEvent('click',function(){
			Galeria.ocultar();
		})
		$('cerrar').addEvent('click',function(){
			Galeria.ocultar();
		})
	},
	
	ocultar: function(){
		this.mostrando=false;
		var thes=this.obj;
		if($('nzSlideGal')) $('nzSlideGal').setStyle('display','none');
		this.obj.morph.cancel();
		this.obj.morph.start({width:'700px'}).chain(function(){
			var thess=thes;
			thes.morph.start({opacity:0}).chain(function(){
				thess.setStyle('display','none')
			});
		});
	}
	
}
			
window.addEvent('domready', function() {	
	
	if($('tcat')!=undefined){
		Galeria.mostrar();
	}
	
});

	
	/*if(m!=undefined) {
		new Element('script',{'src':'http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA2f8KCtX8izVe9Nv7saE60hTINbx4CITxEXVDWK65DQp2kshTTxT62VOu8HbEa3FvlDGrmr8kX-L8AA'}).inject(document.getElement('head'))		.chain(function(){
			Directorio.Mapear(m.title);
		});
	}*/
