/*******************************************************************************
 *
 * class UI.Toggle
 *
 ******************************************************************************/


Toggle.prototype = new Control();
Toggle.prototype.constructor = Toggle;

function Toggle( jquery_element ) {
  Control.call( this, jquery_element );
}

UI.Toggle = Toggle;

Toggle.add = function( properties ) {
  // Build DOM objects.
  var $control = $('<label/>');
  $control.addClass('control control-toggle');
  var $label = $('<span/>');
  var $type = $('<div/>');
  var $checkbox = $('<input type="checkbox" checked/>');
  $checkbox.appendTo( $control );
  
  $type.addClass('slider_toggle round');
  $type.appendTo( $control );
  
  $label.addClass('label_tonge');
  $label.appendTo( $control );
  // Initialize wrapper.
  var control = new Toggle( $control );
  control.update( properties );
  // Set up events.
  UI.add_event( 'change', $control, $checkbox );
  // Attach to document.
  control.attach();
  return control;
}

Toggle.prototype.set_checked = function( value ) {
  $checkbox = this.control.children('input');
  $checkbox.prop( 'checked', value );
  return value;
};

Toggle.prototype.set_label = function( value ) {
  $label = this.control.children('span');
  $label.text( value );
  return value;
};

Toggle.prototype.set_tab_index = function( value ) {
  $checkbox = this.control.children('input');
  $checkbox.attr( 'tabIndex', value );
  return value;
};
