$(document).ready(function(){
  
  $("#navigation div").hover(function(){
    $(this).addClass("hover");
  },function(){
    $(this).removeClass("hover");
  });
  
  $("#navigation div").click(function(){
    if( ($(this).attr("link") != null) && ($(this).attr("link") != "") ){
      document.location = $(this).attr("link");
    }
  });
  
  /// datepicker
  $(".datepicker").datepicker({ 
    dateFormat: 'M d, yy',
    maxDate: '0d',
    minDate: new Date(2008, 10, 1),
    numberOfMonths: 2,
    showButtonPanel: true,
    selectOtherMonths: true,
    showOtherMonths: true
  });
  
  rebind();
  
});


function loadPage(pageVars,pageDiv){
  
  $.ajax({
    url: "ajaxPages.php",
    cache: false,
    data: pageVars,
    dataType: "html",
    success: function(data){
      $("#"+pageDiv).html(data);
      rebind();
    },
    error: function(XMLHttpRequest, textStatus, errorThrown){
      alert("An Ajax Error Has Occurred: "+errorThrown);
    }
  });
  
}//end loadPage
function popupWindow(x){
  
  window.open('popup.php?msg='+x, 'popup_explanation', 'width=400,height=300,scrollbars=yes,resizeable=yes');
  
}//end function popupWindow

function toggle_chart_data(x, the_data){
	if(x.checked==true){
		chart.showDataColumns(the_data);
	}
	else{
		chart.hideDataColumns(the_data);
	}
}


function rebind(){
  
  /// timer div
  $(".loadPageTimer").each(function(i){
    if( ($(this).attr("timer") != null) && ($(this).attr("timer") != "") ){
      setTimeout("loadPage('"+$(this).attr("vars")+"','"+$(this).attr("divName")+"');", $(this).attr("timer"));
      $(this).remove();
    }
  });
  
  /// flicker div
  $(".redFlicker").animate({opacity: 1},2000,function(){
    $(this).removeClass("redFlicker");
  });
  $(".greenFlicker").animate({opacity: 1},2000,function(){
    $(this).removeClass("greenFlicker");
  });
  
}//end rebind
