/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function makeScrollable(wrapper, scrollable){
// Get jQuery elements
  var wrapper = $(wrapper), scrollable = $(scrollable);

  // Hide images until they are not loaded
  scrollable.hide();
  var loading = $('<div class="loading" > &nbsp; <img src="images/loader.gif"</div>').appendTo(wrapper);

  // Set function that will check if all images are loaded
  var interval = setInterval(function(){
    var images = scrollable.find('img');
    var completed = 0;

    // Counts number of images that are succesfully loaded
    images.each(function(){
      if (this.complete) completed++;
    });

    if (completed == images.length){
      clearInterval(interval);
      // Timeout added to fix problem with Chrome
      setTimeout(function(){

        loading.hide();
        // Remove scrollbars
        wrapper.css({overflow: 'hidden'});

        scrollable.slideDown('slow', function(){
          enable();
        });
      }, 1000);
    }
  }, 100);
function enable(){
// height of area at the top at bottom, that don't respond to mousemove
  var inactiveMargin = 100;
  // Cache for performance
  var wrapperWidth = wrapper.width();
  var wrapperHeight = wrapper.height();
  // Using outer height to include padding too
  var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
  // Do not cache wrapperOffset, because it can change when user resizes window
  // We could use onresize event, but it's just not worth doing that
  // var wrapperOffset = wrapper.offset();

  //When user move mouse over menu
  wrapper.mousemove(function(e){
    var wrapperOffset = wrapper.offset();
    // Scroll menu

    var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight  - inactiveMargin;

    if (top < 0){
      top = 0;
    }

    wrapper.scrollTop(top);
  });

  }
}
$(function(){
  makeScrollable("div.sc_menu_wrapper", "div.sc_menu");
});


var nav4 = window.Event ? true : false;
function acceptNum(evt){
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
var key = nav4 ? evt.which : evt.keyCode;
return (key <= 13 || (key >= 48 && key <= 57));
}

//$(document).ready(function(){
//
//  /* $("#img_tabla").css({backgroundPosition: '-60px 0'}).animate({backgroundPosition: '(-20px 250px)'},1000);*/
// $("#contenido").css({ opacity: 1.0,backgroundPosition: '0px 0'});
// $("#titulo").css({ opacity: 0.0});
//  $("#contenido").animate({
//        opacity: 1.0,
//        backgroundPosition: '(-100px 0px)'
//      }, 7000,function(){
//          $("#titulo").animate({
//               opacity: 1.0,
//        width: '250px'
//      }, 5000);
//      } );
///*$("#contenido").fadeOut(100).fadeIn(200);*/
//});
//
//$(document).ready(function(){
//
//  // $("#img_tabla").css({backgroundPosition: '-60px 0'}).animate({backgroundPosition: '(-20px 250px)'},1000);
//
// $("#img_tabla").css({ opacity: 0.0,backgroundPosition: '0px 0'});
//  $("#img_tabla").animate({
//        opacity: 1.0,
//        backgroundPosition: '(-100px 0px)'
//      }, 7000);
///*$("#img_tabla").fadeOut(100).fadeIn(200);*/
//});
//
//$(document).ready(function(){
//$('#animacion').css( {backgroundPosition: "0 0"} )
//	.mouseover(function(){
//		$(this).stop().animate(
//			{backgroundPosition:"(0 -250px)"},
//			{duration:500})
//		})
//	.mouseout(function(){
//		$(this).stop().animate(
//			{backgroundPosition:"(0 0)"},
//			{duration:500})
//		})
// });


/*
$buildingup = false;

$("#sliders>*").show();

//Blurs all links when clicked
$("a").click(function(){
      $(this).blur();
});

$(this).delay(2000,function(){
      $("#titlebar").fadeOut(1000);
});

$(this).delay(3500,function(){

      //Show the elements
      $(".village").stop().animate({top:'30px'}, {queue:false, duration:2000, easing: 'easeInOutBack'});
      $(".cloudbar").stop().animate({top:'0px'}, {queue:false, duration:2000, easing: 'easeInOutBack'});
      $buildingup = true;

});

$("a.toggle").click(function(){

      if ($buildingup == false){

      $("#titlebar").fadeOut(1000);
      $(this).delay(1000,function(){
            $(".village").stop().animate({top:'30px'}, {queue:false, duration:2000, easing: 'easeInOutBack'});
            $(".cloudbar").stop().animate({top:'0px'}, {queue:false, duration:2000, easing: 'easeInOutBack'});
            $buildingup = true;
      });

}else{

      $(".village").stop().animate({top:'366px'}, {queue:false, duration:2000, easing: 'easeInOutBack'});
      $(".cloudbar").stop().animate({top:'-465px'}, {queue:false, duration:2000, easing: 'easeInOutBack'});
      $buildingup = false;

      $(this).delay(2000,function(){
            $("#titlebar").fadeIn(1000);
      });

}

});

});
*/