var bonvivir = new Class({	
	base:'/',
	fn_display_login:null,
  initialize: function(){
  	// heatmap
  	document.addEvent('click', function(event){
  		new Request({
   			url			  : window.bonvivir.base + 'heatmap.cms',
   			method	  : 'post',   			
   			data		  : {'x':event.page.x, 'y':event.page.y, 'ancho':window.getWidth()}
   		}).send(); 
  	});  	
  },	
	load:function()
	{			
		// Over text
		$$('input').each(function(o){
			new BetterOverText(o);
		});
		
		// acciones para desplegar linea de productos
		if( $$('.contenido_detalle .productos .ver-mas') ){
			$$('.contenido_detalle .productos .ver-mas').each(function(el){
				el.addEvent('click', function(){
					if( $(this.get('rel')).getHeight() == 0){
						$(this.get('rel')).setStyle('height','auto');
						this.removeClass('ver-mas-open');
						this.addClass('ver-mas-close');
					}else{
						$(this.get('rel')).setStyle('height',0);
						this.removeClass('ver-mas-close');
						this.addClass('ver-mas-open');						
					}
				})
			})
		}
		
		// menu		
		if( $$('.cabezal .contenido .menu li.current') ){
			try{
				var p = $$('.cabezal .contenido .menu li.current').getPosition($$('.cabezal .selected')[0])[0];
				var s = $$('.cabezal .contenido .menu li.current').getSize($$('.cabezal .selected')[0])[0];
				var ws = $(window).getSize();				
				var x = (Number(p.x+(985*-1))+Math.ceil(Number(s.x/2)-14));
				$$('.cabezal .selected')[0].setStyle('background-position',x+'px 0px');
			}catch(e){}
		}
		
		// banner chat
		var box = new CeraBox();
		$$('.cerabox').each(function(el){			
			box.addItems(el,{group: false, animation: 'fade', displayTitle: false});		
		});		
		
		if($$('.bonvivir .banner_chat')){			
			box.addItems('.bonvivir .banner_chat a', {
				group: 				false,
				animation: 		'fade',
				displayTitle: false
			});		
		}
	
		// Suscripcion	300 
		if( $$('.bonvivir .suscripcion_300') ){
			$$('.suscripcion_300 .banner').addEvent('click', function(){				
				if($$('.suscripcion_300 .formulario')[0].getSize().y == 0){				
					new Fx.Morph($$('.suscripcion_300 .formulario')[0], {duration: 1000}).start({'height':[0,632]});				
				}else{
					new Fx.Morph($$('.suscripcion_300 .formulario')[0], {duration: 1000}).start({'height':[632,0]});				
				}
			});
			// Suscripcion form validate
			if( $('frmSuscripcion') ){
				var fc_frmSuscripcion = new FormCheck('frmSuscripcion');
				$('frmSuscripcion').addEvent('submit', function(event){
					event.stop();
					if( fc_frmSuscripcion.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'formulario'}).inject($('frmSuscripcion'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'suscripcion'}).inject($('frmSuscripcion'));
						$('frmSuscripcion').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      	
      					new Fx.Reveal($$('.suscripcion_300 .formulario')[0], {duration:250, mode:'vertical'}).dissolve();  
      					new Fx.Reveal($$('.suscripcion_300 .ok')[0], {duration:250, mode:'vertical'}).reveal();  
      				}
						});
						$('frmSuscripcion').send();
						return false;
					}
				});			
			}
		}
		
		// Suscripcion landing
		if( $$('.bonvivir .suscripcion .landing').length  ){
			$$('.suscripcion .landing .campo input').each(function(o){
				o.addEvent('focus', function(){ 
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).reveal();   
				});
				o.addEvent('blur', function(){  
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).dissolve(); 
				});
			});
			// Suscripcion form validate
			if( $('frmSuscripcionLanding') ){
				var fc_frmSuscripcionLanding = new FormCheck('frmSuscripcionLanding');
				$('frmSuscripcionLanding').addEvent('submit', function(event){
					event.stop();
					if( fc_frmSuscripcionLanding.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'formulario'}).inject($('frmSuscripcionLanding'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'suscripcion'}).inject($('frmSuscripcionLanding'));
						$('frmSuscripcionLanding').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      	
      					new Fx.Reveal($$('.suscripcion .formulario')[0], {duration:250, mode:'vertical'}).dissolve();  
      					new Fx.Reveal($$('.suscripcion .ok')[0], {duration:250, mode:'vertical'}).reveal();  
      					
      					//GOOGLE track      					
								var google_conversion_id 				= 1006831490;
								var google_conversion_language 	= "es";
								var google_conversion_format 		= "2";
								var google_conversion_color 		= "ffffff";
								var google_conversion_label 		= "o13WCM6IlQIQgo-M4AM";
								var google_conversion_value 		= 0;
								if (197.1) { google_conversion_value = 197.1; }
										
								Asset.javascript('http://www.googleadservices.com/pagead/conversion.js', {
    							id: 'myScript',
    							google_conversion_id				: google_conversion_id,
    							google_conversion_language	: google_conversion_language,
    							google_conversion_format		: google_conversion_format,
    							google_conversion_color			: google_conversion_color,
    							google_conversion_label			: google_conversion_label,
    							google_conversion_value			: google_conversion_value,
    							onLoad: function(){}
								});										
								new Element('img',{'width':'1','height':'1','src':'http://www.googleadservices.com/pagead/conversion/1006831490/?value=197.1&label=o13WCM6IlQIQgo-M4AM&guid=ON&amp;script=0'}).inject( $$('.bonvivir .suscripcion .landing')[0] );
										
      					
      					//MSN Track		
      					new Element('img',{'width':'1','height':'1','src':'http://view.atdmt.com/action/drvsar_StarphoneGraciasporsuscribirse_1'}).inject( $$('.bonvivir .suscripcion .landing')[0] );
      				}
						});
						$('frmSuscripcionLanding').send();
						return false;
					}
				});			
			}
		}
		
		// Suscripcion asociate
		if( $$('.bonvivir .suscripcion .asociate').length  ){
			$$('.suscripcion .asociate .campo input').each(function(o){
				o.addEvent('focus', function(){ 
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).reveal();   
				});
				o.addEvent('blur', function(){  
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).dissolve(); 
				});
			});
			// Suscripcion form validate
			if( $('frmSuscripcionAsociate') ){
				var fc_frmSuscripcionAsociate = new FormCheck('frmSuscripcionAsociate');
				$('frmSuscripcionAsociate').addEvent('submit', function(event){
					event.stop();
					if( fc_frmSuscripcionAsociate.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'formulario'}).inject($('frmSuscripcionAsociate'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'suscripcion'}).inject($('frmSuscripcionAsociate'));
						$('frmSuscripcionAsociate').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      	
      					new Fx.Reveal($$('.suscripcion .formulario')[0], {duration:250, mode:'vertical'}).dissolve();  
      					new Fx.Reveal($$('.suscripcion .ok')[0], {duration:250, mode:'vertical'}).reveal();  
      					
      					//alert("* asociate *")
      					
      				}
						});
						$('frmSuscripcionAsociate').send();
						return false;
					}
				});			
			}
		}
		
		// Member get member
		if( $$('.bonvivir .suscripcion') ){
			// Member get member  form validate
			if( $('frmMemberGetMember') ){
				
				$$('.bonvivir .suscripcion .agregar a').addEvent('click', function(event){
					event.stop();
					if( $$('.bonvivir .suscripcion .datos .dato').length < 5){						
						var n = $$('.bonvivir .suscripcion .datos .dato')[0].clone();
						n.getChildren().each(function(el){ el.getChildren('.campo .input .c input')[0].value = ''; });
						n.inject($$('.bonvivir .suscripcion .datos .dato')[$$('.bonvivir .suscripcion .datos .dato').length-1],'after');												
					}
				})
				
				var fc_frmMemberGetMember = new FormCheck('frmMemberGetMember');
				$('frmMemberGetMember').addEvent('submit', function(event){
					event.stop();
					if( fc_frmMemberGetMember.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'formulario'}).inject($('frmMemberGetMember'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'memberGetMember'}).inject($('frmMemberGetMember'));
						$('frmMemberGetMember').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      	
      					//pr(r)
      					new Fx.Reveal($$('.suscripcion .formulario')[0], {duration:250, mode:'vertical'}).dissolve();  
      					new Fx.Reveal($$('.suscripcion .ok')[0], {duration:250, mode:'vertical'}).reveal();  
      				}
						});
						$('frmMemberGetMember').send();
						return false;
					}
				});			
			}
		}
		
		//Contactos
		if( $$('.bonvivir .contactos') ){
			
			$$('.contactos .campo input', '.contactos .campo textarea').each(function(o){
				o.addEvent('focus', function(){ 
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).reveal();   
				});
				o.addEvent('blur', function(){  
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).dissolve(); 
				});
			});
			
			// Contactos form validate
			if( $('frmContactos') ){
				var fc_frmContactos = new FormCheck('frmContactos');
				$('frmContactos').addEvent('submit', function(event){
					event.stop();
					if( fc_frmContactos.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'formulario'}).inject($('frmContactos'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'contactos'}).inject($('frmContactos'));
						$('frmContactos').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      	
      					new Fx.Reveal($$('.contactos .formulario')[0], {duration:250, mode:'vertical'}).dissolve();  
      					new Fx.Reveal($$('.contactos .ok')[0], {duration:250, mode:'vertical'}).reveal();  
      				}
						});
						$('frmContactos').send();
						return false;
					}
				});			
			}
		}
		
		// Login
		if( $$('.bonvivir .cabezal .login') ){
		  
		  this.fn_display_login = function(ev){ 
		    try{
  		    if( $(ev.target).getParent('form').get('id') != 'frmLogin' && $(ev.target).getParent('form').get('id') != 'frmRecordar'){
  		      new Fx.Reveal($$('.cabezal .login .panel')[0], {duration:750, mode:'vertical'}).dissolve();	
  		      new Fx.Reveal($$('.cabezal .login .recordar')[0], {duration:750, mode:'vertical'}).dissolve();	
  		      $(document).removeEvents('click');
  		    }
  		  }	catch(e){
  		    new Fx.Reveal($$('.cabezal .login .panel')[0], {duration:750, mode:'vertical'}).dissolve();	
  		    new Fx.Reveal($$('.cabezal .login .recordar')[0], {duration:750, mode:'vertical'}).dissolve();	
  		    $(document).removeEvents('click');
  		  }
		  }
		  
			$$('.cabezal .login .ingresar').addEvent('click', function(){
				var fx = new Fx.Reveal($$('.cabezal .login .panel')[0], {duration:500, mode:'vertical'}).toggle();				
				fx.addEvent('show', function(){
					$$('.cabezal .login .overTxtLabel').each(function(o){
						o.setStyle('display','block');
						o.setStyle('padding-top','5px');
					});				
					$(document).addEvent('click', window.bonvivir.fn_display_login);
				});								
			});
/*			
			$$('.cabezal .login .panel').addEvent('mouseleave', function(){
				new Fx.Reveal($$('.cabezal .login .panel')[0], {duration:750, mode:'vertical'}).dissolve();	
				new Fx.Reveal($$('.cabezal .login .email')[0], {duration:500, mode:'horizontal'}).dissolve();
				new Fx.Reveal($$('.cabezal .login .clave')[0], {duration:500, mode:'horizontal'}).dissolve();			
			});
			
			$$('.cabezal .login .recordar').addEvent('mouseleave', function(){
				new Fx.Reveal($$('.cabezal .login .recordar')[0], {duration:750, mode:'vertical'}).dissolve();	
				new Fx.Reveal($$('.cabezal .login .email')[0], {duration:500, mode:'horizontal'}).dissolve();
			});
*/			
			
			$$('.cabezal .login .olvido').addEvent('click', function(){
				$$('.cabezal .login .panel').setStyle('display', 'none');
				$$('.cabezal .login .recordar').setStyle('display', 'block');
			});
			// login form validate
			if( $('frmLogin') ){
				var fc_frmLogin = new FormCheck('frmLogin');
				$('frmLogin').addEvent('submit', function(event){
					new Fx.Reveal($$('.cabezal .login .email')[0], {duration:250, mode:'horizontal'}).dissolve();
					new Fx.Reveal($$('.cabezal .login .clave')[0], {duration:250, mode:'horizontal'}).dissolve();
										
					event.stop();
					if( fc_frmLogin.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'usuarios'}).inject($('frmLogin'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'acceso'}).inject($('frmLogin'));
						$('frmLogin').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){
      					if(r){
	    						var r = JSON.decode(r);
	    						if(r.ERROR){
		    						if(r.FIELD == 'email'){
		    							$$('.cabezal .login .email .texto')[0].set('html', r.ERROR);
		    							new Fx.Reveal($$('.cabezal .login .email')[0], {duration:250, mode:'horizontal'}).reveal();	    							
		    						}
		    						if(r.FIELD == 'clave'){
		    							$$('.cabezal .login .clave .texto')[0].set('html', r.ERROR);
		    							new Fx.Reveal($$('.cabezal .login .clave')[0], {duration:250, mode:'horizontal'}).reveal();	    							
		    						}
		    					}else{
		    						$$('.cabezal .login')[0].setStyle('display','none');
		    						$$('.cabezal .registro')[0].setStyle('display','none');
		    						$$('.cabezal .usuario')[0].setStyle('display','block');
		    						$$('.cabezal .usuario .nombre')[0].set('html', 'Bienvenido/a: ' + r.nombre);		    						
		    					}
	    					}
      				}
						});
						$('frmLogin').send();
						return false;
					}
				});
			}					
		}
		
		// Recuperar clave
		if( $$('.bonvivir .cabezal .recordar') ){
			// login form validate
			if( $('frmRecordar') ){
				var fc_frmRecordar = new FormCheck('frmRecordar');
				$('frmRecordar').addEvent('submit', function(event){
					new Fx.Reveal($$('.cabezal .login .email')[0], {duration:250, mode:'horizontal'}).dissolve();										
					event.stop();
					if( fc_frmRecordar.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'usuarios'}).inject($('frmRecordar'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'recordar_clave'}).inject($('frmRecordar'));
						$('frmRecordar').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){
      					if(r){
	    						var r = JSON.decode(r);
	    						if(r.ERROR){
		    						if(r.FIELD == 'email'){
		    							$$('.cabezal .login .recordar .email .texto')[0].set('html', r.ERROR);
		    							new Fx.Reveal($$('.cabezal .login .recordar .email')[0], {duration:250, mode:'horizontal'}).reveal();	    							
		    						}
		    					}
		    				}else{
		    					$$('.cabezal .login .recordar')[0].setStyle('display','none');
		    				}	    					
      				}
						});
						$('frmRecordar').send();
						return false;
					}
				});
			}
		}		
		
		// Login comentarios
		if( $$('.bonvivir .comentarios .login') ){
			// login form validate
			if( $('frmComentarioLogin') ){				
				var fc_frmComentarioLogin = new FormCheck('frmComentarioLogin');
				$('frmComentarioLogin').addEvent('submit', function(event){
					new Fx.Reveal($$('.comentarios .login .email')[0], {duration:250, mode:'horizontal'}).dissolve();
					new Fx.Reveal($$('.comentarios .login .clave')[0], {duration:250, mode:'horizontal'}).dissolve();
					
					event.stop();
					if( fc_frmComentarioLogin.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'usuarios'}).inject($('frmComentarioLogin'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'acceso'}).inject($('frmComentarioLogin'));
						$('frmComentarioLogin').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){
      					if(r){
	    						var r = JSON.decode(r);
	    						if(r.ERROR){
		    						if(r.FIELD == 'email'){
		    							$$('.comentarios .login .email .texto')[0].set('html', r.ERROR);
		    							new Fx.Reveal($$('.comentarios .login .email')[0], {duration:250, mode:'horizontal'}).reveal();	    							
		    						}
		    						if(r.FIELD == 'clave'){
		    							$$('.comentarios .login .clave .texto')[0].set('html', r.ERROR);
		    							new Fx.Reveal($$('.comentarios .login .clave')[0], {duration:250, mode:'horizontal'}).reveal();	    							
		    						}
		    					}else{		    						
		    						$$('.comentarios .formulario')[0].setStyle('display','block');
		    						$$('.comentarios .login')[0].setStyle('display','none');		    						
		    						document.forms['frmComentario'].nombre.value = r.nombre;
		    						document.forms['frmComentario'].email.value = r.email;
		    					}
	    					}
      				}
						});
						$('frmComentarioLogin').send();
						return false;
					}
				});				
			}
		}
		
		// Logout
		if( $$('.bonvivir .cabezal .logout') ){
			$$('.cabezal .logout').addEvent('click', function(){
				new Request({
			  	url: window.bonvivir.base + 'ajax.cms',
			    method: 'post',
			    onSuccess : function(r){
		    		window.location.reload();		    		     
			    }
				}).send('module=usuarios&execute=desconectar');
			});
		}
		
		// Registracion
		if( $$('.bonvivir .registracion') ){
			$$('.registracion .campo input').each(function(o){
				o.addEvent('focus', function(){ 
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).reveal();   
					if($$('.registracion .campo .globo_error')[0])    new Fx.Reveal($$('.registracion .campo .globo_error')[0], {duration:250, mode:'horizontal'}).dissolve();  
				});
				o.addEvent('blur', function(){  
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).dissolve(); 
					if($$('.registracion .campo .globo_error')[0])    new Fx.Reveal($$('.registracion .campo .globo_error')[0], {duration:250, mode:'horizontal'}).dissolve();  
				});
			});
			// registracion form validate
			if( $('frmRegistracion') ){
				var fc_frmRegistracion = new FormCheck('frmRegistracion');
				$('frmRegistracion').addEvent('submit', function(event){
					event.stop();
					if( fc_frmRegistracion.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'usuarios'}).inject($('frmRegistracion'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'registracion'}).inject($('frmRegistracion'));
						$('frmRegistracion').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){
      					if(r){
      						var r = JSON.decode(r);
	      					if(r.ERROR){
	      						new Fx.Reveal($$('.registracion .campo .globo_error')[0], {duration:250, mode:'horizontal'}).reveal();  
	      					}
      					}else{
      						new Fx.Reveal($$('.registracion .formulario')[0], {duration:250, mode:'vertical'}).dissolve();  
      						new Fx.Reveal($$('.registracion .ok')[0], {duration:250, mode:'vertical'}).reveal();  
      					}
      				}
						});
						$('frmRegistracion').send();
						return false;
					}
				});
			}		
		}		
		
		// Seleccion mes
		if( $$('.bonvivir .seleccion_mes') ){
			window.bonvivir.seleccion_mes_count = 0;
			window.bonvivir.seleccion_mes_total = $$('.seleccion_mes .contenido .items .item').length;
			window.bonvivir.seleccion_mes_timer =  (function(){
				try{				
					window.bonvivir.seleccion_mes_count++;
					$$('.seleccion_mes .contenido .items .item')[window.bonvivir.seleccion_mes_count].fireEvent('click');
					if(window.bonvivir.seleccion_mes_count > window.bonvivir.seleccion_mes_total) window.bonvivir.seleccion_mes_count = -1;
				}catch(e){
					clearInterval(window.bonvivir.seleccion_mes_timer);
				}				
			}).periodical(5000);
			$$('.seleccion_mes .contenido .items .item').each(function(o, index){
				o.addEvent('click', function(event){
					if(event){
						clearInterval(window.bonvivir.seleccion_mes_timer);					
					}
					$$('.seleccion_mes .contenido .cinta .item').each(function(o2, index2){
						if(index != index2) new Fx.Reveal(o2, {duration:250, mode:'vertical'}).dissolve(); 
					});
					new Fx.Reveal($$('.seleccion_mes .contenido .cinta .item')[index], {duration:500, mode:'vertical'}).reveal();  
					$$('.seleccion_mes .contenido .items .item').each(function(o2){
						o2.removeClass('active');
						/*o2.setOpacity(0.7);*/
					});
					this.addClass('active');
					/*this.setOpacity(1);*/
					
					$$('.seleccion_mes .contenido .items .item .ver_producto').each(function(o2, index2){
						if(index != index2) o2.setStyle('display','none');
					});
					this.getChildren('.ver_producto').setStyle('display','block');
				});
			});			
		}
		
		// Seleccion
		if( $$('.bonvivir .seleccion') ){
			$$('.seleccion').each(function(seleccion){
				seleccion.getElements('.contenido .items .item').each(function(o, index){
					o.addEvent('click', function(){						
						seleccion.getElements('.contenido .datos .productos .producto').each(function(o2, index2){
							if(index != index2) new Fx.Reveal(o2, {duration:250, mode:'vertical'}).dissolve(); 
						});
						new Fx.Reveal(seleccion.getElements('.contenido .datos .productos .producto')[index], {duration:500, mode:'vertical'}).reveal();  
						seleccion.getElements('.contenido .items .item').each(function(o2){
							o2.removeClass('active');
						});
						this.addClass('active');	
					});
				});
			});						
		}
		
		// Newsletter
		if( $$('.bonvivir .newsletter') ){
			// newsletter form validate
			if( $('frmNewsletter') ){
				var fc_frmNewsletter = new FormCheck('frmNewsletter');
				$('frmNewsletter').addEvent('submit', function(event){
					event.stop();
					if( fc_frmNewsletter.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'envioslistas'}).inject($('frmNewsletter'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'add_destinatario'}).inject($('frmNewsletter'));
						$('frmNewsletter').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      					
      					new Fx.Reveal($$('.newsletter .formulario')[0], {duration:250, mode:'vertical'}).dissolve();  
      					new Fx.Reveal($$('.newsletter .ok')[0], {duration:250, mode:'vertical'}).reveal();  
      				}
						});
						$('frmNewsletter').send();
						return false;
					}
				});
			}		
		
		}
		
		// Comentario
		if( $$('.bonvivir .comentarios') ){			
			if( $('frmComentario') ){
				var fc_frmComentario = new FormCheck('frmComentario');
				$('frmComentario').addEvent('submit', function(event){
					event.stop();
					if( fc_frmComentario.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'comentarios'}).inject($('frmComentario'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'add_comentario'}).inject($('frmComentario'));
						$('frmComentario').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){
      					$$('.comentarios .formulario')[0].setStyle('display','none');
		    				$$('.comentarios .ok')[0].setStyle('display','block');
      				}
						});
						$('frmComentario').send();
						return false;
					}
				});				
			}
		}
		
		// Destacado
		if( $$('.bonvivir .destacado') ){			
			window.bonvivir.destacado_count = 0;
			window.bonvivir.destacado_total = $$('.destacado .buttons .button').length;
			window.bonvivir.destacado_timer =  (function(){
				try{	
					window.bonvivir.destacado_count++;
					$$('.bonvivir .destacado .buttons .button')[window.bonvivir.destacado_count].fireEvent('click');
					if(window.bonvivir.destacado_count >= window.bonvivir.destacado_total-1) window.bonvivir.destacado_count = -1;
				}catch(e){
					clearInterval(window.bonvivir.destacado_timer);					
				}
			}).periodical(15000);
			$$('.bonvivir .destacado .buttons .button').each(function(el, index){
				el.addEvent('click', function(event){
					if(event){
						clearInterval(window.bonvivir.destacado_timer);					
					}
					$$('.bonvivir .destacado .buttons .button').each(function(el2){ el2.removeClass('active'); });
					this.addClass('active');										
					var items    = $$('.bonvivir .destacado .items')[0];
					var actual_x = items.getStyle('margin-left');
					var x 			 = (index*960)*-1;
					new Fx.Morph($$('.bonvivir .destacado .items')[0],{duration: 1000}).start({'margin-left':[actual_x,x]});
				});
			});
			$$('.bonvivir .destacado .izq').addEvent('click',function(){
				clearInterval(window.bonvivir.destacado_timer);					
				if(window.bonvivir.destacado_count-1 >= 0){
					window.bonvivir.destacado_count--;
					$$('.bonvivir .destacado .buttons .button')[window.bonvivir.destacado_count].fireEvent('click');				
				}
			})
			$$('.bonvivir .destacado .der').addEvent('click',function(){
				clearInterval(window.bonvivir.destacado_timer);					
				if(window.bonvivir.destacado_count+1 < window.bonvivir.destacado_total){
					window.bonvivir.destacado_count++;
					$$('.bonvivir .destacado .buttons .button')[window.bonvivir.destacado_count].fireEvent('click');				
				}
			})
		}				
		
		// Buscador formulario
		if($$('.bonvivir .buscador')){
			// Buscador form validate
			if( $('frmBuscador') ){
				var fc_frmBuscador = new FormCheck('frmBuscador');
				$('frmBuscador').addEvent('submit', function(event){
					event.stop();
					if( fc_frmBuscador.isFormValid() ){				
						var s = $('frmBuscador').texto.value.toString();
								s = s.clean();
								s = s.standardize();
								s = s.toLowerCase();
								s = s.replace(/ /g,'-');
								
						$('frmBuscador').action += '0/' + s;
						$('frmBuscador').submit();
					}
				});			
			}
		}

		// Buscador resultado
		if($$('.bonvivir .buscador_resultado')){
			$$('.buscador_resultado .solapas .solapa').each(function(o){
				o.addEvent('click', function(event){
					// solapa
					$$('.buscador_resultado .solapas .solapa').each(function(o2){
						o2.removeClass('solapa_active');
						o2.addClass('solapa_inactive');
						o2.getElement('.bubble').setStyle('display','block')
					});
					// texto
					$$('.buscador_resultado .descripcion_resultado span').each(function(o2){
						o2.setStyle('display','none')
					});					
					// resultados
					$$('.buscador_resultado .resultados .results').each(function(o2){
						o2.setStyle('display','none')
					});					
										
					var cat = o.get('class').toString().match(/categoria_(.*\d)/gi)
					
					var txt = '.buscador_resultado .descripcion_resultado .'+cat;
					$$(txt).setStyle('display','block');
					
					var res = '.buscador_resultado .resultados .'+cat;
					$$(res).setStyle('display','block');
										
					o.removeClass('solapa_inactive');
					o.addClass('solapa_active');
					o.getElement('.bubble').setStyle('display','none')
				})
			})			
		}
		
		// solapas detalle producto
		if($$('.bonvivir .producto_detalle')){
			$$('.bonvivir .producto_detalle .solapas .solapa').each(function(o, index){
				o.addEvent('click', function(){
					$$('.bonvivir .producto_detalle .solapas .solapa').each(function(o2){
						o2.removeClass('active');
					});
					this.addClass('active');				
					$$('.bonvivir .producto_detalle .textos .texto').each(function(o2){
						o2.removeClass('active');
					});
					$$('.bonvivir .producto_detalle .textos .texto')[index].addClass('active');										
				})				
			});
		}		
		
		// Chat
		if($$('.bonvivir .chat')){
			if( $('frmChatAcceso') ){
				var fc_frmChatAcceso = new FormCheck('frmChatAcceso');
				$('frmChatAcceso').addEvent('submit', function(event){
					event.stop();
					if( fc_frmChatAcceso.isFormValid() )
					{	
						window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set._.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute('charset','utf-8');$.src='//cdn.zopim.com/?w5RATQgbPwNAKqVwLXxFqEX3kF7hFnPl';z.t=+new Date;$.type='text/javascript';e.parentNode.insertBefore($,e)})(document,'script');
						$zopim(function() {
							$zopim.livechat.set({
								language	: 'es',
								name			: $('frmChatAcceso').nombre.value,
								email			: $('frmChatAcceso').email.value,
								onStatus	: function(s) {
									$$('.bonvivir .chat .acceso').setStyle('display','none');
									switch(s)
									{
										case 'offline':
											$$('.bonvivir .chat .offline').setStyle('display','block');										
											$zopim.livechat.window.hide();
											break;
										default:
											$$('.bonvivir .chat .offline').setStyle('display','none');
											$zopim.livechat.window.show();
											break;	
									}
									$('__cwindow__').setStyle('bottom', '0');
									$('__cwindow__').setStyle('left',   '0');
									$('__cwindow__').setStyle('right',  '0');
									$('__cwindow__').setStyle('width',  '540px');
									$('__cwindow__').setStyle('height', '280px');
									
									var el = window.bonvivir.getElementsByAttribute($$('#__cwindow__ iframe')[0].contentDocument.body, 'div', '__jx__id','___$_21__titlebar');
									if(el[0]) el[0].style.display = 'none';
																		
								}
							});
						});
						return false;
					}
				});				
			}			
			/*
			if( $('frmChatMensaje') ){
				var fc_frmChatMensaje = new FormCheck('frmChatMensaje');
				$('frmChatMensaje').addEvent('submit', function(event){
					event.stop();
					if( fc_frmChatMensaje.isFormValid() ){
						$zopim(function(){
							$zopim.livechat.say($('frmChatMensaje').texto.value);
						});																		
						$('frmChatMensaje').texto.value = '';
					}
				});			
			}
			*/
		}
		
		// ws-registracion
		if( $$('.bonvivir .ws-registracion') ){
			$$('.ws-registracion .campo input', '.ws-registracion .campo select').each(function(o){
				o.addEvent('focus', function(){ 
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).reveal();   
					if($$('.ws-registracion .campo .globo_error')[0])    new Fx.Reveal($$('.ws-registracion .campo .globo_error')[0], {duration:250, mode:'horizontal'}).dissolve();  
				});
				o.addEvent('blur', function(){  
					if(this.getParent('.campo').getElement('.globo')) new Fx.Reveal(this.getParent('.campo').getElement('.globo'), {duration:250, mode:'horizontal'}).dissolve(); 
					if($$('.ws-registracion .campo .globo_error')[0])    new Fx.Reveal($$('.ws-registracion .campo .globo_error')[0], {duration:250, mode:'horizontal'}).dissolve();  
				});
			});
			// registracion form validate
			if( $('frmWsRegistracion') ){
				var fc_frmWsRegistracion = new FormCheck('frmWsRegistracion');
				$('frmWsRegistracion').addEvent('submit', function(event){
					event.stop();
					if( fc_frmWsRegistracion.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'usuarios'}).inject($('frmWsRegistracion'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'ws_registracion'}).inject($('frmWsRegistracion'));
						$('frmWsRegistracion').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      					
      					pr(r);
      					if(r){
      						var r = JSON.decode(r);
	      					if(r.ERROR){	      						
	      						new Fx.Reveal($$('.registracion .campo .globo_error')[0], {duration:250, mode:'horizontal'}).reveal();  
	      					}      						
      					}else{
      						new Fx.Reveal($$('.registracion .formulario')[0], {duration:250, mode:'vertical'}).dissolve();  
      						new Fx.Reveal($$('.registracion .ok')[0], {duration:250, mode:'vertical'}).reveal();  
      					}      					
      				}
						});
						$('frmWsRegistracion').send();
						return false;
					}
				});
			}		
		}
		
		// ws-suscripcion
		if( $$('.bonvivir .ws-suscripcion') )
		{
			// registracion form validate
			if( $('frmWsSuscripcion') )
			{
				var fc_frmWsSuscripcion = new FormCheck('frmWsSuscripcion');
				$('frmWsSuscripcion').addEvent('submit', function(event){
					event.stop();
					if( fc_frmWsSuscripcion.isFormValid() )
					{
						new Element('input',{'type':'hidden','name':'module',  'value':'usuarios'}).inject($('frmWsSuscripcion'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'ws_suscripcion'}).inject($('frmWsSuscripcion'));
						$('frmWsSuscripcion').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      					
      					
      					//pr(r)
      					
      					
      					
      				}
						});
						$('frmWsSuscripcion').send();
						return false;
					}
				});
			}		
		}
				
		// ws-stock
		if( $$('.bonvivir .ws-stock') ){			
			
			if( $('frmWsGetStock') ){
				var fc_frmWsGetStock = new FormCheck('frmWsGetStock');
				$('frmWsGetStock').addEvent('submit', function(event){
					event.stop();
					if( fc_frmWsGetStock.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'productos'}).inject($('frmWsGetStock'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'ws_getstock'}).inject($('frmWsGetStock'));
						$('frmWsGetStock').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      					      					
      					//pr(r)      					      					
      				}
						});
						$('frmWsGetStock').send();
						return false;
					}
				});
			}		
			
			if( $('frmWsOnlineReserve') ){
				var fc_frmWsOnlineReserve = new FormCheck('frmWsOnlineReserve');
				$('frmWsOnlineReserve').addEvent('submit', function(event){
					event.stop();
					if( fc_frmWsOnlineReserve.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'productos'}).inject($('frmWsOnlineReserve'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'ws_onlinereserve'}).inject($('frmWsOnlineReserve'));
						$('frmWsOnlineReserve').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){
      					//pr(r)      					      					
      				}
						});
						$('frmWsOnlineReserve').send();
						return false;
					}
				});
			}		
		}
		
		// ws-compra
		if( $$('.bonvivir .ws-compra') ){
			// registracion form validate
			if( $('frmWsCompra') ){
				var fc_frmWsCompra = new FormCheck('frmWsCompra');
				$('frmWsCompra').addEvent('submit', function(event){
					event.stop();
					if( fc_frmWsCompra.isFormValid() ){
						new Element('input',{'type':'hidden','name':'module',  'value':'productos'}).inject($('frmWsCompra'));
						new Element('input',{'type':'hidden','name':'execute', 'value':'ws_compra'}).inject($('frmWsCompra'));
						$('frmWsCompra').set('send',{
							url		 : window.bonvivir.base + 'ajax.cms',
      				method : 'post',
      				onSuccess: function(r){      					
      					//pr(r)      					      					
      				}
						});
						$('frmWsCompra').send();
						return false;
					}
				});
			}
		}
		
	},
	sizeMore:function(o){
  	var size  = Number($$('.'+o).getStyle('font-size').toString().replace('px', ''))+2;
  	var lsize = Number($$('.'+o).getStyle('line-height').toString().replace('px', ''))+2;
  	if( size <= 26){
    	$$('.'+o).setStyle('font-size',  size+'px');
    	$$('.'+o).setStyle('line-height', lsize+'px');
  	}
	},
	sizeLess:function(o){
  	var size = Number($$('.'+o).getStyle('font-size').toString().replace('px', ''))-2;
  	var lsize = Number($$('.'+o).getStyle('line-height').toString().replace('px', ''))-2;
  	if( size >= 8){
    	$$('.'+o).setStyle('font-size', size+'px');
    	$$('.'+o).setStyle('line-height', lsize+'px');
  	}
	},
	getElementsByAttribute:function(oElm, strTagName, strAttributeName, strAttributeValue){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("/" + strAttributeValue + "/") : null;
    var oCurrent;
    var oAttribute;
    for(var i=0; i<arrElements.length; i++){
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute(strAttributeName);
        if(typeof oAttribute == "string" && oAttribute.length > 0){            
            if( typeof strAttributeValue == "undefined" || strAttributeValue == oAttribute ){
            /*if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){*/
                arrReturnElements.push(oCurrent);
            }
        }
    }
		return arrReturnElements;
	}	
});
document.addEvent('domready', function(){
	window.bonvivir = new bonvivir();	
	window.bonvivir.load();
})

window.addEvent('beforeunload', function(){
	/*pr(window);
	alert(00)*/
	window.bonvivir = null;
});

