var PR = {
  animate: true,
  reset: true,
  update: function( data, animate ) {
    PR.animate = false;
    data.reset = PR.reset;
    $.post( '/controllers/update.php', data, this.replace, 'json' );
  },

  replace: function( response ) {
    $.each( response, function(key, value) {
	      el = $( '#' + key );
 	      if ( PR.animate ) {
		el.slideUp("slow", function() {
			     el.html( value ).slideDown("slow");
			   } );
	      }
	      else {
		el.html( value );
		PR.help_text();
	      }
	    });
  },

  submit: function( form, data, animate ) {
    var form_data = {};
    $.each( $(form).find(':input:not(button)') , function(i, el) {
	      if ( el.type == 'checkbox' ) {
		if ( el.checked && el.name ) {
		  form_data[el.name] ? true :  form_data[el.name] = new Array();
		  form_data[el.name].push( ( $(el).val() ) );
		}
	      }
	      else if ( el.type != 'radio' || el.checked ) {
		form_data[el.name] = $(el).val();
	      }
	    });
    PR.update($.extend(form_data, data), animate);
  },

  active: function( el ) {
    var li = $(el).parent('li');
    li.siblings(li).removeClass('active');
    li.addClass('active');
  },

  help_text: function() {
    // $.each( $(".help-text"), function() {
    // 	      var text = $(this).html();
    // 	      var button = $('<a href="javascript:"><img src="/images/icons/help.png" class="help-image" alt="help"/></a>');

    // 	      button.click( function() { window.alert( text ) } );

    // 	      var label = $(this).next('label');
    // 	      var label_text = label.html();
    // 	      var width = label.width();

    // 	      var div = $('<div></div>');
    // 	      div.css('width', width );
    // 	      div.css('float', 'left');
    // 	      div.append( "<label style=\"width: auto;\">" + label_text + "</label>", button );

    // 	      label.replaceWith( div );
    // 	    });

  }
}
