// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
// 
jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

$(document).ajaxSend(function(event, request, settings) {
  if (typeof(AUTH_TOKEN) == "undefined") return;
  // settings.data is a serialized string like "foo=bar&baz=boink" (or null)
  settings.data = settings.data || "";
  settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});



$('document').ready(function(){
	$('#imageCycle').cycle('fade');
	
	//events page admin hours assist	
	function hideHours(){
		var x = ("div#" + this.className)
		if(this.checked){
			$(x + ":hidden").show("drop")
		}
		else{
			$(x + ":visible").hide("drop")
			$(x + " .textInput").val("Closed")
		}
	}
	
	$('.day :checkbox').click(hideHours);
	$(".day :checkbox").each(hideHours);
	
	//location page
	$('.locationSelect').change(function(){
		$(".locationSelect option:selected").each(function(){
			if($(this).attr("value") != ""){
				$.get("/locations/show", "location=" + $(this).attr("value"),function(data){
					$("#locationData").html(data);
				});
				return false;	
			}						
		 })		
	})
	
	//events page
	$('.eventLocationSelect').change(function(){
		$(".eventLocationSelect option:selected").each(function(){
			if($(this).attr("value") != ""){
				$.get("/events/view/", "id=" + $(this).attr("value"),function(data){
					$("#eventData").html(data);
				});
				return false;
			}			
		 })		
	})
	
	//autocomplete
	  $('input.autocomplete').each(function(){
	    var $input = $(this);
	    $input.autocomplete($input.attr('autocomplete_url'));
	  });
	
		
})


