$(document).ready(function() {
  //inject the modal dialog waiting animation (spinner)
  /*$('#dialog').html('<img src="/img/accents/busy.gif" alt="loading" />');
  
  //modal dialog for video
  $('.jqmWindow').css({
    'border-radius':'12px',
    '-moz-border-radius':'12px',
    '-webkit-border-radius':'12px'
  });*/
  
  /**
   * change the CSS based on day/nite
   */
  the_date = new Date();//date object
  the_time = the_date.getTime();//time object
  the_date.setTime(the_time);//set the time
  the_hour = the_date.getHours();//get the current hour
  
  //if the time is 8:00pm or later
  if (the_hour >= 20) {
    //add the nite-time class to the body
    $('body').addClass('nite-time');
  }
  
  /**
   * show/hide the sections
   */
  //first we need to hide the sponsors section
  $('#section-sponsors').hide();
  //set global animation speeds
  $animSpeed = 'slow';
  $animSpeedScroll = 777;
  
  //now set up the toggles on each main nav link
  $('#nav a').each(function() {
    //onClick
    $(this).click(function() {
      //if this is the Home link
      if($(this).attr('href') == '#section-home') {
        //if the home section is hidden
        if($('#section-home').is(':hidden') && $('#section-sponsors').is(':visible')) {
          $('#section-sponsors').fadeOut($animSpeed);
          $('#section-home').fadeIn($animSpeed);
        }
      //or if this is the Sponsors link
      } else if($(this).attr('href') == '#section-sponsors') {
        //if the sponsors section is hidden
        if($('#section-sponsors').is(':hidden') && $('#section-home').is(':visible')) {
          $('#section-home').fadeOut($animSpeed);
          $('#section-sponsors').fadeIn($animSpeed);
        }
      }      
      
      //scroll to the section
      $('html').animate({scrollTop:384}, $animSpeedScroll, 'easeInOutSine');
      return false;
    });//end this.click
  });//end nav.each
  
  //sponsors target links scrolls to their destinations smoothly
  $('ul#sponsors-menu a').each(function() {
    
    //target
    //var targetID = ;
        
    //click event
    $(this).click(function() {
  		var target = $(this).attr('href');
  		var offset = $(target).offset();
  		$('html').animate({scrollTop:offset.top}, $animSpeedScroll);
  		return false;
  	});
	});
  
  //top of page link scrolls to top smoothly
  $('a.top-page').each(function() {
    $(this).click(function(){
  		$('html').animate({scrollTop:0}, $animSpeedScroll);
  		return false;
  	});
	});
});
