$(document).ready(function(){
  //borderBottom: "8px solid #8b0000"
  
  $('#main ul#sitios li').hover(
    function(){
      $(this).animate({backgroundColor:"#EBEBEB"}, 500);
      }, 
    function(){
      $(this).animate({backgroundColor:"white"}, 400);
      }
  );
  


$('.contenido').capty({
  opacity:  .8,
height: 79
});


$('.pigs').capty({
height: 92
});

$('.torqlite').capty({
height: 95
});

$('.xli').capty({
height: 100
});

 // $('ul#nav li a').hover(
 //   function(){
 //     $(this).animate({backgroundColor:"#e3e3e3"}, 600);
 //     }, 
 //   function(){
 //     $(this).animate({backgroundColor:"white"}, 600);
  //    }
//  );




var lastULPosX = 0;
var ulWidth = 0;
var ulMovesRight = true;
var ulMouseMoving = false;

  $(function(){
      //Get our elements for faster access and set overlay width
      var div = $('div.sc_menu'),
                   ul = $('ul.sc_menu'),
                   // unordered list's left margin
                   ulPadding = 30;
	 
      //Get menu width
      var divWidth = div.width();
      
      //Remove scrollbars
      div.css({overflow: 'hidden'});

      //Find last image container
      var lastLi = ul.find('li:last-child');

	 //As images are loaded ul width increases,
     //so we recalculate it each time
     ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

	window.setInterval(function() {
		
		if(ulMouseMoving)
		{	return;}
			
		var moveOffSet;
		
		if(lastULPosX >= (ulWidth-900))
			ulMovesRight = false;
		else if(lastULPosX <=0) 
			ulMovesRight = true;
			
		if(ulMovesRight)
		{
			moveOffSet = 1;
		}
		else
		{
			moveOffSet = -1;
		}
			
		//lets save the last position on x axis
		lastULPosX = lastULPosX + moveOffSet ;
		ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
	    //var left = (lastULPosX - div.offset().left) * (ulWidth-divWidth) / divWidth;
	    div.scrollLeft(lastULPosX);

	}, 16);












//      $(lastLi).animate({backgroundColor:"#E8E8E8"},500);


      //When user move mouse over menu
      div.mousemove(function(e){

        ulMouseMoving = true;

		//lets save the last position on x axis

        var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
        lastULPosX = left;
		div.scrollLeft(left);
		
		
      });
	
	div.mouseleave(function(e){
		ulMouseMoving = false;
      });
  });
  
 


  
  $('#main ul#secciones_unico li.11').hover(
    function(){

      $('#main #imagen img').attr('src', 'img/new1.jpg')
      $(this).animate({backgroundColor:"#E8E8E8"},500);
      $('#main ul#secciones_unico li.11 a').animate({color:"#8b0000"},500);
      $('#main ul#secciones_unico li.11').prepend('<span class="flecha">&#171; </span>');
      }, 
    function(){
      $('#main #imagen img').attr('src', 'img/news2.jpg');
      $(this).animate({backgroundColor:"#8b0000"},500);
      $('#main ul#secciones_unico li.11 a').animate({color:"white"},500);
      $('span.flecha').remove();
      }
  );



    $('#main ul#secciones_right li.11').hover(
    function(){

      $('#main #imagen img').attr('src', 'img/main_img_11.jpg')
      $(this).animate({backgroundColor:"#E8E8E8"},500);
      $('#main ul#secciones_right li.11 a').animate({color:"#8b0000"},500);
      $('#main ul#secciones_right li.11').prepend('<span class="flecha">&#171; </span>');
      }, 
    function(){
      $('#main #imagen img').attr('src', 'img/main_img.jpg');
      $(this).animate({backgroundColor:"#8b0000"},500);
      $('#main ul#secciones_right li.11 a').animate({color:"white"},500);
      $('span.flecha').remove();
      }
  );






  $('#footer ul li a').hover(
  	function(){
  		$(this).animate({paddingLeft:"5px"}, 500);
  	}, 
  	function(){
  		$(this).animate({paddingLeft:"0px"}, 500);
  	}
  )
  
 
  
  
   // Change the image of hoverable images
   $(".hover").hover( function() {
       var hoverImg = HoverImgOf($(this).attr("src"));
       $(this).attr("src", hoverImg);
     }, function() {
       var normalImg = NormalImgOf($(this).attr("src"));
       $(this).attr("src", normalImg);
     }
   );
});

function HoverImgOf(filename)
{
   var re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1_hover.$2");
}
function NormalImgOf(filename)
{
   var re = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1.$2");
}



