window.addEvent('load', function(){

  var fx = new Fx.Styles('contenido', {duration:750, wait:false});		
  fx.start({
    'opacity' : 0.92,
    'width' : '740',
    'height' : '400'
  });
  
// 	var url = '_empresa.html';
// 	new Ajax(url, {
// 		method: 'get',
// 		update: $('contenido'),
// 		onComplete: function(){
//   		  var fx = new Fx.Styles('contenido', {duration:500, wait:false});		
//       	fx.start({
//       	  'opacity' : 0.92,
//       	  'width' : '740',
//       	  'height' : '400'
//       	});
//     	}
// 	}).request();  
	
	var list = $$('#opciones li');
	list.each(function(element) {
  	var fx = new Fx.Styles(element, {duration:400, wait:false});
  	
  	element.addEvent('mouseenter', function(){
  		fx.start({
  			'background-color' : '#444'
  		});
  	});
  	
  	element.addEvent('mouseleave', function(){
  		fx.start({
  			'background-color' : '#89a'
  		});
  	});
  	
  	element.addEvent('click', function(e) {
  	  e = new Event(e).stop();
  	  var fx = new Fx.Styles('contenido', {duration:750, wait:false});		
      fx.start({
        'opacity' : 0,
        'width' : '0',
        'height' : '0'
      }).chain(function() {
        this.start({
          'opacity' : 0.92,
          'width' : '740',
          'height' : '400'
        });
        $('main').style.background="transparent url(img/fondo_"+element.id+".jpg) no-repeat";
        var url = "_"+element.id+".html";
      	new Ajax(url, {
      		method: 'get',
      		update: $('contenido'),
      		onComplete: function (){
      		  actions_seccion(element.id);
          }
      	}).request();
    	});
    });			
	});	
});

// Acciones específicas para cada sección
function actions_seccion (seccion){

  if(seccion=='materiales'){
    var list = $$('#lista_mat li');
  	list.each(function(element) {
    	var fx = new Fx.Styles(element, {duration:400, wait:false});
    	
    	element.addEvent('mouseenter', function(){
    		fx.start({
    			'width' : '230',
    			'height' : '300'
    		});
    	});
    	
    	element.addEvent('mouseleave', function(){
    		fx.start({
    			'width' : '230',
    			'height' : '175'
    		});
    	});
    });	
  } else if(seccion=='construccion'){
    var list = $$('#lista_con li');
  	list.each(function(element) {
    	var fx = new Fx.Styles(element, {duration:400, wait:false});
    	
    	element.addEvent('mouseenter', function(){
    		fx.start({
    			'width' : '360',
    			'height' : '310'
    		});
    	});
    	
    	element.addEvent('mouseleave', function(){
    		fx.start({
    			'width' : '230',
    			'height' : '100'
    		});
    	});
    });	
  } else if(seccion=='complementos'){
    var list = $$('#lista_compl li');
  	list.each(function(element) {
    	var fx = new Fx.Styles(element, {wait:false, duration:500});
    	
    	element.addEvent('mouseenter', function(){
    		fx.start({
    			'width' : '400'
    		});
    	});
    	
    	element.addEvent('mouseleave', function(){
    		fx.start({
    			'width' : '60'
    		});
    	});
    });	
  } else if(seccion=='contacto'){
    var list = $$('a');
    list.each(function(element) {
      element.addEvent('click', function(e) {
    	  e = new Event(e).stop();
    	  var fx = new Fx.Styles('contenido', {duration:750, wait:false});		
        fx.start({
          'opacity' : 0,
          'width' : '0',
          'height' : '0'
        }).chain(function() {
          this.start({
            'opacity' : 0.92,
            'width' : '740',
            'height' : '400'
          });
          $('main').style.background="transparent url(img/fondo_"+element.id+".jpg) no-repeat";
          var url = "_"+element.id+".html";
        	new Ajax(url, {
        		method: 'get',
        		update: $('contenido'),
        		onComplete: function (){
        		  actions_seccion(element.id);
            }
        	}).request();
      	});
      });	
    });
    
  }
  
}

function cargar (pagina){
  var fx = new Fx.Styles('contenido', {duration:750, wait:false});		
  fx.start({
    'opacity' : 0,
    'width' : '0',
    'height' : '0'
  }).chain(function() {
    this.start({
      'opacity' : 0.92,
      'width' : '740',
      'height' : '400'
    });

    var url = "_"+pagina+".html";
  	new Ajax(url, {
  		method: 'get',
  		update: $('contenido')
  	}).request();
	});
}

function intro()
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="750" height="400" id="Uriel Romero Hermanos" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="allowFullScreen" value="false" />');
	document.write('<param name="movie" value="intro.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#f0f0fe" />	<embed src="intro.swf" quality="high" bgcolor="#f0f0fe" width="750" height="400" name="Intro" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
