// remap jQuery to $
(function($){
  
  var doc_height = $(document).height() - $(window).height();
  var current_opac;
  var hover;
  var current_opac_limit;

  $(window).bind('scroll', function() {
      
    offset = $(document).scrollTop() / doc_height;
    current_opac = Math.round((1-offset)*100)/100;
    
    if ( hover != true ) {
      current_opac_limit = (current_opac < 0.6) ? 0.6 : current_opac;
      $('#headerWrapper').css('opacity', current_opac_limit);
    }
  }); // /scroll
  		
  $("#headerWrapper").hover(
    function () {
      $('#headerWrapper').stop().fadeTo('slow', 1);
      hover = true;
    },
    function () {
      $('#headerWrapper').stop().fadeTo('slow', current_opac_limit);
      hover = false;
    }
  );
//  console.log(my_cookie);
  if ( my_cookie != true ) {
    $('#facebox').stop(true, true).fadeIn();
    var t = setTimeout(function() {
    $('#facebox').stop(true, true).fadeOut();
    clearInterval(t);
    }, 4000);
  }
  
  
  var max_scroll = $('.slider').length;
  var scroll_amount = 0;
  $('#slider').height($(".slider:lt(1)").height());
  
  
  $('.next').click(function(e) {

    if ( scroll_amount < 0 ) scroll_amount = 0;

      var sc_offset = scroll_amount+2;
      scroll_amount += 1;
    
      if ( scroll_amount < max_scroll )  {
        
      $('#slider').stop(true,true).animate({
        height: $(".slider:nth-child("+sc_offset+")").height()
      }, 500);
    
      $('.slider-inner').stop(true,true).animate({
        left: -scroll_amount*460
      }, 500, function() {

      });
      
    }// if    
    e.preventDefault();
  });
  
  
  
  $('.prev').click(function(e) {
   
    if ( scroll_amount >= max_scroll ) scroll_amount = max_scroll-1;

    var sc_offset = scroll_amount;
    scroll_amount -= 1;

    if ( scroll_amount > -1 )  {
      
      $('#slider').stop(true,true).animate({
        height: $(".slider:nth-child("+sc_offset+")").height()
      }, 500);
    
      $('.slider-inner').stop(true,true).animate({
        left: -scroll_amount*460
      }, 500, function() {

      });
      
    }// if    
    e.preventDefault();
  });
  
  
  
  $(".fb").hover(
    function () {
      $('#facebox').stop(true, true).fadeIn();
      clearInterval(t);
    }, 
    function () {
      $('#facebox').stop(true, true).fadeOut();
    }
  );
       
  
  $('a[href*=#]').click(function() {    
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {       
            var $target = $(this.hash);            
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');            
            if ($target.length) {            
                var targetOffset = $target.offset().top;                
                $('html,body').animate({scrollTop: targetOffset-60}, 1000);                   
                return false;                
            }            
        }        
    });
   

})(window.jQuery);
