document.addEvent('domready', function() {
	var formcont = $('form-contacto');
	
	if($chk(formcont))
	{
		formcont.addEvent('submit', function(e) {
			e.stop();
			$('form-submit').set('value', 'Enviando...');
		
	
			var requ = new Request.JSON({
				url : baseUrl + 'index.php/page/contdo',
				onSuccess : function(response){
				
					if(response.envio == 1)
					{
						alert ("Mensaje Enviado; Gracias nos pondremos en contacto contigo a la brevedad posible");
						inputs.each(function(input){
							if(input.get('type') != 'submit')
							{
								input.set('value', '');
								input.set('text', '');
								
							}
						
						});
					}
					else
					{
						alert ("Oops! Ha ocurrido un error en el Servidor, intenta mas tarde");
					}
				},
				onFailure : function (){
					alert ("Oops! Ha ocurrido un error en el Servidor, intenta mas tarde");
				}
			}).get(formcont);
			requ.send();
	
		});
	}
	
	var roller = $$('#roller li');
	
	if(roller.length > 1)
	{
		var Rox = new Roller(roller);
	}
	
	var menuitems = $$('#navig li a');
	menuitems.each(function(menuitem) {
		menuitem.setStyle('background-position', '0px 0px');
		menuitem.addEvent('mouseover', function(){
			menuitem.set('tween', {'duration':'short'});
			menuitem.tween('background-position', '0px -40px');
		});
		menuitem.addEvent('mouseout', function(){
			menuitem.set('tween', {'duration':'short'});
			menuitem.tween('background-position', '0px 0px');
		});
	});
	
	//var myTips = new Tips('#navig li a');
	
	var tabs = $$('.tabs li');
	var tabbers = $$('#tabselect .tab');
	
	tabbers.each(function(tabber) {
		tabber.setStyle('display', 'none'); 
	});
	
	tabs.each(function(tab, i) {
		tab.setStyle('cursor' ,'pointer');
		tab.addEvent('click', function() {
			tab.addClass('selected');
			tabs.each(function(t, y) {
				if(i == y) {
					t.addClass('selected');
				}else{
					t.removeClass('selected');
				}
			});
			
			tabbers.each(function(tabber, j) {
				if(i == j) {
					tabber.setStyle('display', 'block');
				}else{
					tabber.setStyle('display', 'none');
				}
			});
		});
	});
	if(tabs[0] != undefined) 
	{
		tabs[0].fireEvent('click');
	}
	
	
	var myTips = new Tips('.naviggy li a');
	imgas  =  $$('.product-list li a');
	var fondocambia = $('fondocambia');
	
	imgas.each(function(imga) {
		imga.addEvent('mouseenter', function() {
			fondocambia.setStyle('background-image', 'url(' + imga.get('rel') + ')');
		});
	});
	
	var fijo = $('menu-si');
	if($chk(fijo))
	{
		var up = $('subir');
		var dn = $('bajar')
		var movil = fijo.getElements('.naviggy');
		movil.setStyle('top', '0');
		movil.set('tween', {'duration' : 400});
		
		
		up.addEvent('click', function(){
			var top = parseInt(movil.getStyle('top'));
			movil.tween('top', top +120);
			
		});
		
		dn.addEvent('click', function(){
			var top = parseInt(movil.getStyle('top'));
			movil.tween('top', top -120);
		})
		
	}
	
	var rolis = $$('ul#roller2 li');
	var rol2 = $('roller2');
	
	
	if($chk(rolis))
	{
		if($chk(rol2))rol2.set('tween', {'duration' : 400});
		myTips = new Tips('ul#roller2 li');
		
		var rolws = $('roller-sw');
		
		rolis.each(function(roli, i) {
			//alert(roli);
			var el = new Element('span', {'text' : i+1});
			el.addEvent('click', function() {
				var x = -400*i;
				rol2.tween('top', x);
				$$('.selected').each(function(sel)
				{
					sel.removeClass('selected');
				});
				el.addClass('selected');
			});
			if(i == 0)
			{
				el.addClass('selected');
			}
			rolws.adopt(el);
		});
	}
	
});


Roller = new Class({
	initialize : function(elements) {
		this.roller = elements;
		this.actual = 0;
		
		this.roller.each(function(item, i) {
			item.setStyles({'top': 0, 'z-index' : 1});
		});
		
		this.roller[0].setStyle('z-index', 3);
		this.trance.periodical('5000', this);
	},
	
	
	
	
	
	fotoHeight : 266,
	border : 10,
	
	goN : function () {
		var length = this.roller.length;	
		var actual = this.actual;
		if(++actual ==  length) return 0;
		else return actual;	
	},
	
	trance : function () {
		//se pone el siguiente atras
		this.roller[this.goN()].setStyle('z-index', 2);
		
		var fXX = new Fx.Tween(this.roller[this.actual], {
				duration: 800, 
				transition: Fx.Transitions.Quad.easeIn,
				onComplete: function() {
					//se va hasta el fondo y se acomoda
					this.roller[this.actual].setStyles({'z-index' : 1, 'top' : 0 });
					//actual es ahora el siguiente
					this.actual = this.goN();
					//se va al frente
					this.roller[this.actual].setStyle('z-index', 3);
				}.bind(this)
		});
		fXX.start('top', this.fotoHeight + this.border);
	}
});





