// Form.Validator.installForAllValidatedForms();

jQuery.fn.refreshingDiv = function() {
	
	return this.each(function() {
		
		var obj = this;
		
		var updateFn = function() {
			var div = jQuery(obj);
									
			var fn = function(data, status) {
				if (data.length) { clearInterval(obj.timer); div.replaceWith(data); }
			}
			
			jQuery.post(div.attr('href'), { ts : div.attr('last_refresh_time'), st : div.attr('start_date'), et : div.attr('end_date')  }, fn, "html")
		}
		
		this.timer = setInterval(updateFn, jQuery(this).attr("refresh_rate")*1000);
	});
}

jQuery.fn.ajaxLink = function(targets) {
	var callback = function(data, status) { 
		for (t in targets) { 
			jQuery(targets[t]).replaceWith(data[t]); 
		} 
	};
	return this.each(function() {
		jQuery(this).click(function() { 
			var div = jQuery('#reservations');
                        var goAhead = true;
                        if ($(this).attr('href').indexOf("noshow") != -1) {
                          goAhead = confirm("Are you sure? This will send the patron an email notifying them the reservation has been marked no show.");
                        } else if ($(this).attr('href').indexOf("cancel") != -1) {
                          goAhead = confirm("Are you sure? This will send the patron an email notifying them the reservation has been cancelled. If you wish to edit your party size, time or date, please simply edit the reservation using the edit icon.");
                        } else if ($(this).attr('href').indexOf("deny") != -1) {
                          goAhead = confirm("Are you sure that you want to deny this reservation?");
                        }

                        if (goAhead) {
                          jQuery.getJSON(jQuery(this).attr('href'), { st : div.attr('start_date'), et : div.attr('end_date') }, callback);
                        }
                        return false;
		});
	});
}

jQuery('a[rel*=facebox]').livequery(function() { jQuery(this).facebox(); });
// jQuery('.highlight').livequery(function() { jQuery(this).show('highlight'); });

jQuery.ajaxSetup({ 'beforeSend': function(xhr) { xhr.setRequestHeader("Accept", "text/javascript"); } });

// This allows logging lines such as
// # $(root).find('li.source> input:checkbox').log("sources to uncheck").removeAttr("checked");
// to the Firebug console http://getfirebug.com/console.html
jQuery.fn.log = function(msg) {
  console.log("%s: %o", msg, this);
  return this;
};
