// Copyright 2009 Foursquare Labs Inc. All Rights Reserved.

function approve(message, func) {
  if (confirm(message)) {
    func();
  }
}

function show(id, func) {
  $("#"+id).show();
  func();
}

function spinner(id, func) {
  $("#"+id).html("<img src='/img/ajax_spinner.gif' height='32' width='32' alt='wait'/>");
  func();
}

function submitForm(obj) {
  while(obj.nodeName.toLowerCase() != 'form') {
    obj = obj.parentNode;
  }
  obj.submit();
}

function makeImgRollover(id) {
  $(id).hover(
    function() {
      this.src = this.src.replace('_off', '_on');
    },
    function() {
      this.src = this.src.replace('_on', '_off');
    }
  );
}

function showTab(tab) {
  $('.tabContainer').hide()
  $('#standardTabs a').removeClass('active')
  
  $('#' + tab).show()
  $('#' + tab + 'Trigger').addClass('active')
  
  return false;
}

function expandSection(element, max, min) {
  var target = $(element)
  var maxHeightVal = target.css('max-height')
  
  if(maxHeightVal.substring(0, maxHeightVal.length - 2) > min)
    target.animate({maxHeight: min}, 700)
  else 
    target.animate({maxHeight: max}, 1000)

  return false
}

// User Page
var UserPage = {
  showTodos: function(todos) {
    var carrot = $("<img class='carrot' src='/img/tipsCarrot.png' />")
    
    if(todos === undefined) {
      $('#tipsList .tips').hide()
      $('#tipsList .todos').show()
      $('#tipsNav #todosTrigger').append(carrot)
      $('#tipsNav #tipsTrigger .carrot').remove()
    } else {
      $('#tipsList .tips').show()
      $('#tipsList .todos').hide()
      $('#tipsNav #todosTrigger .carrot').remove()
      $('#tipsNav #tipsTrigger').append(carrot)
    }
    
    return false
  },
  
  showTips: function() { return this.showTodos(false) }
}
