var jq = $;
SLIDE_SPEED = 400;



App = {

  init: function() {
    $("#tabs").tabs({selected: 0});
    jq('#location_selector').unbind('change').bind('change', function(e) {
      var location_id = jq(this).val();
      window.location.href = edit_location_path(location_id, '');
    });
    jq('#reservation_selector').unbind('change').bind('change', function(e) {
      var location_id = jq(this).val();
      window.location.href = location_reservations_path(location_id, '');
    });
    App.initialize_people_assignment();
  },

  initialize_people_assignment: function() {
    jq('.location_assignment').unbind('change').bind('change', function() {
      var location_id = jq(this).val();
      var toggle = jq(this).attr('checked');
      var person_id = jq(this).attr('rel');
      location_assignment_ajax(person_id, 'get', {update: toggle, location_id: location_id});
      //location_assignment_ajax(person,  

    });
  }

}



//tog
function tog(clicker, toggler, callback, speed){
  if (speed == undefined) {speed = SLIDE_SPEED;}
  if (callback) {jq(clicker).click(function(){jq(toggler).slideToggle(speed, callback); return false;});}
  else {jq(clicker).click(function(){jq(toggler).slideToggle(speed); return false;});}

}
function togger(j, callback, speed){
  if (speed == undefined) {speed = SLIDE_SPEED}
  if(callback) {jq(j).slideToggle(speed, callback); }
  else {jq(j).slideToggle(speed); }
}
//tog














//message
function async_message(m, d){message(m, d);}
function msg(m, d){message(m, d);}
function messages(m, d){message(m, d);}
function message(message, duration){
    if (duration == undefined){ duration = 3000;}
    if (jq.browser.msie) { jq("#message").css({position: 'absolute'}); }
    jq("#message").text(message).fadeIn(1000);
    setTimeout('jq("#message").fadeOut(2000)',duration);
    return false;
}
//message


function debug(m){if (typeof console != 'undefined'){console.log(m);}}
function puts(m){debug(m);}















//startup
jq(function(){
  App.init();
  //$("select, :checkbox, :radio, :file").uniform();
	jQuery("#waiter").ajaxStart(function(){jq(this).show();}).ajaxStop(function(){jq(this).hide();}).ajaxError(function(){jq(this).hide();});
	$(".thickbox").colorbox();
})
//startup








