function mainMenuHover(){
	$('#elmenu h2 a.agencia').css({backgroundPosition:"0px 0px"}).hover(function(){$(this).stop().animate({backgroundPosition:"(0px -47px)"},{duration:150})},function(){$(this).stop().animate({backgroundPosition:"(0px 0px)"},{duration:150})});
	
	$('#elmenu h2 a.areas').css({backgroundPosition:"-500px 0px"}).hover(function(){$(this).stop().animate({backgroundPosition:"(-500px -47px)"},{duration:150})},function(){$(this).stop().animate({backgroundPosition:"(-500px 0px)"},{duration:150})});
	
	$('#elmenu h2 a.portafolio').css({backgroundPosition:"-1000px 0px"}).hover(function(){$(this).stop().animate({backgroundPosition:"(-1000px -47px)"},{duration:150})},function(){$(this).stop().animate({backgroundPosition:"(-1000px 0px)"},{duration:150})});
	
	$('#elmenu h2 a.clientes').css({backgroundPosition:"-1500px 0px"}).hover(function(){$(this).stop().animate({backgroundPosition:"(-1500px -47px)"},{duration:150})},function(){$(this).stop().animate({backgroundPosition:"(-1500px 0px)"},{duration:150})});
	
	$('#elmenu h2 a.grupo').css({backgroundPosition:"-2000px 0px"}).hover(function(){$(this).stop().animate({backgroundPosition:"(-2000px -47px)"},{duration:150})},function(){$(this).stop().animate({backgroundPosition:"(-2000px 0px)"},{duration:150})});
	
	$('#elmenu h2 a.contacto').css({backgroundPosition:"-2500px 0px"}).hover(function(){$(this).stop().animate({backgroundPosition:"(-2500px -47px)"},{duration:150})},function(){$(this).stop().animate({backgroundPosition:"(-2500px 0px)"},{duration:150})});

}
mainMenuHover();


var $preroll = $('#preroll'),
    $win = $(window),
    $a = $('a.next'),
    $body = $('body'),
    $navigation = $('nav#main'),
    $utility = $('#navigation-utility'),
    $wrapper = $('#wrapper').css({position: 'fixed', top: $win.height()}),
    $entry = $('#entry'),
    $enterButton = $('#enter-button'),
    $big_img = $('#preroll>img'),
    $big_img_w = $big_img.attr('width'),
    $big_img_h = $big_img.attr('height'),
    $stripes = $('#stripes'),
	$pattern = $('#pattern'),
    $overlay = $('#overlay'),
    $enter_site = $('#enter-site'),
	$scroll = $body,
    $cta = $('#cta'),
    _ctaHeight = $cta.height(),
    /*$backButton = $('<div id="back-button"/>').appendTo($wrapper);
    $backLink = $('<a href="#back" id="back-to-feature">Volver</a>').appendTo($backButton),*/
    _scrollPoints = [200,2600],
    _offsetTop = 175,
    _entered = false,
    $pane1 = $('<div class="intro-pane"/>').css({backgroundColor: '#000000'}), // Black
    $pane2 = $('<div class="intro-pane"/>').html('<div class="pattern"><div class="texto">ESPINACA</div></div>'), // Stripes
	//$pane2 = $('<div class="intro-pane"/>').html('<div class="pattern"></div>'), // Stripes
    $pane3 = $('<div class="intro-pane"/>').css({backgroundColor: '#282727'});// Dark grey 
      
    $wrapper.css({overflow: 'hidden'});
    /*on_resize();*/
    init();
              
    function init(){
        $pane3.prependTo($entry);
        $pane2.prependTo($entry);
        $pane1.prependTo($entry);
		
		
        $a.click(function(e){
			e.preventDefault();
			//Construye seccion
			/*alert($('#menu-'+$(this).attr('href')+'-0'));*/
			
					$pane1.clearQueue();
			$pane2.clearQueue();
			$pane3.clearQueue();
			$preroll.clearQueue();
			$entry.clearQueue();
			
			$pane1.stop();
			$pane2.stop();
			$pane3.stop();
			$preroll.stop();
			$entry.stop();
			
 			/*animatedcollapse.show($(this).attr('href'));*/
		 /*$carga.load($(this).attr('href'));*/

           $.address.value($(this).attr('href')); 
		  /* var current = $('a[href=#' + e.value + ']:first');
		   $.address.title($.address.title().split(' | ')[0] + ' | ' + current.text());*/
          
          //var inc = 300,
              //dur = 800,
		  var inc = 650,
              dur = 2200,
              delay = 0,
              winH = $win.height(),
              ease = 'easeInExpo',
              finalEase = 'easeInOutExpo';
          
          $preroll.animate({top: -$win.height()}, dur, ease);
          
          /*$.doTimeout(200, function(){
            $a.animate({bottom: -$a.height()}, 600, 'easeInOutExpo');
          });*/
          
          delay += inc;
          $.doTimeout('lanza3', delay, function(){ $pane3.animate({top: -winH}, dur, ease); });
          
          delay += inc;
          $.doTimeout('lanza2', delay, function(){ $pane2.animate({top: -winH}, dur, ease); });
          
          delay += inc*2;
          $.doTimeout('lanza1', delay, function(){
            $pane1.animate({top: -winH}, dur, finalEase, function(){ 
			$entry.detach();
				/*$entry.css({display: 'none'});*/
			/*cuando completa la animacion, saca submenu y ajusta indicador*/
			 /* if(document.getElementById('submenu1')){
			  	$("#submenu1").css({display:'none'});
			  }
			  if(document.getElementById('submenu2')){
			  	$("#submenu2").css({display:'none'});
			  }
			  $('.indicador').css({top:'145px', display:'inherit'});*/
			});
            
            
              /*$.doTimeout(dur * .5, revealBackButton);*/
            
          });
		  
		  seccionactual = $(this).attr('href');
		  
          $wrapper.css({top: winH}).animate({top: 0}, dur*2.5, finalEase, function(){
             
			   
              $wrapper.css({overflow: 'hidden', position: 'static'});
    		  cambiaseccion(seccionactual,1);
           });
			
			
	      
          /*$a.unbind('click');*/
          
        }); // End click() bind
        
      } // End init()
      
      function revealBackButton(){
        $backButton.css({display: 'block'});
        
			  $backLink
				.css({bottom: -$backLink.height()})
				.animate({bottom:0}, 600, 'easeInOutExpo', function(){
				  $backLink.click(onBackLinkClick);
				});
      };
      
      function onBackLinkClick(e) {
			$pane1.clearQueue();
			$pane2.clearQueue();
			$pane3.clearQueue();
			$preroll.clearQueue();
			$entry.clearQueue();
			
			$pane1.stop();
			$pane2.stop();
			$pane3.stop();
			$preroll.stop();
			$entry.stop();
			
		
			
          var inc = 600,
              dur = 1800,
              delay = 0,
              winH = $win.height(),
              ease = 'easeInExpo',
              finalEase = 'easeInOutExpo';
          /*_entered = false;*/

          // Get the panels and the preroll off-screen.
          $pane1.css({top: winH});
          $pane2.css({top: winH});
          $pane3.css({top: winH});
          $preroll.css({top: winH});

          /*on_resize();*/
		  /*$entry.css({display: 'inherit'});*/

          $entry.prependTo($body);

          /*if(!GLOBAL_IS_MOBILE) {*/
            /*$.doTimeout(200, function(){
              $backLink.animate({bottom: -$backLink.height()}, 600, 'easeInOutExpo');
            });*/
          /*}*/

          $pane1.animate({top: 0}, dur, ease);

          delay += inc;
          $.doTimeout('lanza1', delay, function(){ $pane2.animate({top: 0}, dur, ease); });

          delay += inc;
          $.doTimeout('lanza2', delay, function(){ $pane3.animate({top: 0}, dur, ease); });

          delay += inc * 2;
          $.doTimeout('lanza3', delay, function(){
            $preroll.animate({top: 0}, dur, finalEase);
            $wrapper.css({overflow: 'hidden', height: '100%', position: 'fixed', top: 0});
            $.doTimeout(dur * .5, function(){
              $a.animate({bottom: 0}, 600, 'easeInOutExpo', function(){
                $scroll.scrollTop(0);
                init();
              });
            });
          });

          /*e.preventDefault();
          $backLink.unbind('click');*/
          
      }; // End onBackLinkClick()

/*SECCIONES PRINCIPALES*/
/*animatedcollapse.addDiv('agencia', 'speed=1,group=contenidos,fade=0')
animatedcollapse.addDiv('areas', 'speed=1,group=contenidos,fade=0')
animatedcollapse.addDiv('portafolio', 'speed=1,group=contenidos,fade=0')
animatedcollapse.addDiv('clientes', 'speed=1,group=contenidos,fade=0')
animatedcollapse.addDiv('grupo_espinaca', 'speed=1,group=contenidos,fade=0')
animatedcollapse.addDiv('contacto', 'speed=1,group=contenidos,fade=0')*/

/*animatedcollapse.init()*/
	  
