window.addEvent('domready',function(){
	//sIFR
	/**/new sIFR('#cont2 h2','/css/sifr.swf',{fontSize:18,
			paddingtop: 50,
			paddingright: 0,
			paddingbottom: 0,
			paddingleft: 0});


	//Activar hojas de Estilos
		function setActiveStyleSheet(title) {
		   var i, a, main;
		   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		     if(a.getAttribute("rel").indexOf("style") != -1
		        && a.getAttribute("title")) {
		       a.disabled = true;
		       if(a.getAttribute("title") == title) a.disabled = false;
		     }
		   }
		}	
	
	/**/
		
	$$('a.imprimir').addEvent('click', function(ev)
	{
		var event = new Event(ev);
		event.stop();
		setActiveStyleSheet('alterno');
		if (confirm("Esta es una vista de impresión \n ¿Desea imprimir?"))
		{
			window.print()
		}
		setActiveStyleSheet('default');
		//setActiveStyleSheet('default');
		//window.open(window.location);
	})
	
	// enviar email
	$$('#botones .enviar').each(function(el){
			var contenido = $E('#sendemail');
			var toggler = el;
			var block = new Element('div',{'class':'popup hidden'}).injectAfter($('cont1'));
			var titles = '<h6>'+toggler.innerHTML+'</h6><h5>'+'</h5>';
			new Element('div',{'class':'pbody'}).setHTML('<div class="pcontent">'+contenido.innerHTML+'</div>').inject(block);
			new Element('div',{'class':'pfoot','title':'haga click para cerrar'}).addEvent('click',function(){block.addClass('hidden')}).inject(block);
			contenido.remove();
			//
			toggler.addEvent('click',function(ev){
				var event = new Event(ev);
				event.stop();
				if(!block.hasClass('hidden')){block.addClass('hidden');return}
				//
				block.setStyles({
					'opacity':window.ie7?1:0,
					'top':'250px'
				}).removeClass('hidden');
				//
				new Fx.Styles(block, {duration:1000,transition:Fx.Transitions.Back.easeOut}).start({
					'opacity':1,
					'top':320
				});
			});
			
		});
		
	$$('#detalleproducto ul li').each(function (elemento, indice)
	{
				elemento.addEvent('click', function(ev){
					var color
					color=elemento.getProperty('title').toUpperCase();
					$E('#color').empty();
					$E('#color').appendText(color);
					$$('#detalleproducto ul li').removeClass('opcion');
					this.addClass('opcion');
						$E('input.opcion', elemento).setProperty('checked','checked');
			})
	})
	
	// funciones activas
	$$('#productos p').each(function (elemento, indice)
	{
	/**/
		elemento.addEvent('click', function(ev){
		
				$$('#productos p').each(function(elemento, indice)
						{
							elemento.removeClass('checked');
						});
				elemento.addClass('checked');
				$$('input.elegido')[indice].setProperty('checked','checked');
		})
	})
	
	
	$$('#cont3 a img').each(function(elemento, indice)
    {
			var imagen = indice + 1;
			var id = $('tip_id').getProperty('value');
			ruta=$$('#cont3 img.imgproducto').getProperty('src');
			elemento.addEvents({
				'click': function(ev) { // do this 
					var event = new Event(ev);
						elemento.addClass('imgactiva');
						event.preventDefault();
						$$('#cont3 a img').each(function(elemento, indice)
						{
							elemento.removeClass('imgactiva');
						});
						elemento.addClass('imgactiva');
					ruta="/images/productos/large_prod_"+id+"_"+imagen+".jpg"
					$$('#cont3 img.imgproducto').setProperty('src', ruta);
				},
				'mouseenter': function() { // and this 
					$$('#cont3 img.imgproducto').setProperty('src', "/images/productos/large_prod_"+id+"_"+imagen+".jpg");
					//alert(imagen+" Prueba");
				},
				'mouseleave': function() { // and this 
					$$('#cont3 img.imgproducto').setProperty('src',ruta);
				}
			});
	    } 
	);
	
	//busqueda
	
	//ENVIO DE EMAIL
	//var base = $E('base').getProperty('href');
		//validador de campos del formulario
	var base = $E('base').getProperty('href');
	
	var contactForm = $('contactform');
	var errortext ="Debe corregir los datos de los campos color rojo.";
	var errorsend="Problemas con el servidor.";
	var checkForm = new inputsValidator($$('#contactform input[class]'));

	var forminfo = new Element('div');
	forminfo.setProperty('id', 'forminfo');
	forminfo.injectInside(contactForm);
	contactForm.addEvent('submit',function(e){
	
		var event = new Event(e);
		event.stop();
		if(this.disabled) return;
			
		if(!checkForm.test()){
			alert('Error!!!!!!');
			checkForm.focusInvalid();
			/**/
			
			forminfo.setHTML(errortext).addClass('error');
			new Event(e).stop();
			}
			else{
				forminfo.setHTML('enviando...').addClass('sending');
				this.setProperty('action',base+'sendmail.ajax');
				this.send({
					onComplete: function(){
					alert(this.response.text); return;
						forminfo.removeClass('error').removeClass('sending').removeClass('ok');
						if(this.response.text==''){
							forminfo.setHTML(errorsend).addClass('error');
						}else if(this.response.text=='false'){
							forminfo.setHTML(errorsend).addClass('error');
						}else{
							forminfo.setHTML(this.response.text).addClass('ok');
							window.location = redirect;
						}
						//contactForm.disabled=false;
					}
				});
				//contactForm.disabled=true;
			}
		});

	
	
});