$(document).ready(function(){

		// =====================================================================================
		// App wide
		// =====================================================================================
		// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	  // Rollovers
	  $("a.rollover").hover(
	    function() {
	      curr = $(this).find("img").attr("src");
	      overlen = curr.length;
	      over = curr.substr(0, overlen-4);
	      over = over+'_on.jpg';
	      $(this).find("img").attr({ src: over});
	    },
	    function() {
	      $(this).find("img").attr({ src: curr});
	    }
	  )
		// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	  // Rollovers - Preload images
	  $("a.rollover").find("img").each(function(i){
	    temp = this.src;
	    prelen = temp.length;
	    pre = temp.substr(0, prelen-4);
	    pre = pre+'_on.jpg';
	    preload_image_object = new Image();
	    preload_image_object.src = pre;
	  });


		// =====================================================================================
		// Temp Upstate code
		// =====================================================================================
		// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    $("div div.section").hide();
    $("div div#section_about").show();
		$("a.upstate_nav").click(
			function() {
	    	$("div div.section").hide();
				$("div div#"+this.id).fadeIn();
	  	}
		);
		// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::









    // #############################################
    // Newsticker
    var options = {
       newsList: "div#newsticker ul",
       startDelay: 5,
       tickerRate: 80,
       placeHolder1: " |"
     }
     $().newsTicker(options);
    // #############################################
    // Cycle for sposors in sidebar
  	$('ul#sidebar_sponsors').cycle({
  		fx:     'fade',
  		speed:   500,
      pause:  .5,
			height: "150px" 
  	});
    // #############################################
    // Cycle general fade class
  	$('.fade').cycle({
  		fx:     'fade',
  		speed:  300,
      pause:  1,
      cssBefore: { zIndex: 0 },
      cssAfter: { zIndex: 0 }
  	});
    // #############################################
    // Event Switcher
    $('div.event_banner').hide(); // Hide the event banners used for hover states
    $("div#event_container").hover( // Pause and resume the slideshow when hovering the event list
      function () { // Over - Pause slideshow
        $('div#slideshow').cycle('pause');
      },
      function () { // Out - Resume slideshow
        $('div#slideshow').cycle('resume');
      }
  	);
    $("ul#upcomingevents li a").hover( // Animate event banners into slideshow area
      function () { // Over - Fade it in
        $('div#event_banner_'+this.id).fadeIn();
      },
      function () { // Out - Fade it out
        $('div#event_banner_'+this.id).fadeOut();
      }
  	);
    // #############################################
    // Tablesorter
    $(".sortable").tablesorter();
    // #############################################
    // Program Filter
    $("select#age_group_filter").change(function () { 
      $('table.program_schedules tbody tr').hide(); 
      $("select option:selected").each(function () {
        switch ($(this).val()){
          case 'age_View_All':
            $('table.program_schedules tbody tr').fadeIn();
            break;
          default:
            $('table.program_schedules tbody tr.'+this.value).fadeIn();
        }
      });
    });


		// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// Date Picker
		$('.datePicker input').datepicker({ dateFormat: 'yy-mm-dd' });

    // #############################################
    // Calendar for Datepicker
    // $('#start_date').calendar({autoPopUp: 'focus', yearRange: '-5:+5', dateFormat: 'YMD-'});
    // $('#end_date').calendar({autoPopUp: 'focus', yearRange: '-5:+5', dateFormat: 'YMD-'});
    // #############################################
    // Flash Messages
  	$("#flash_message").slideDown('fast').fadeOut(3500);
    // #############################################

});
