   
   # Pixels that must be dragged for a click to be ignored
   dragThreshold:     5                          
-}+}

    $(el).attr("unselectable", "on")

# Automatically resize the handle or container
$.iphoneStyle::optionallyResize: (mode) -> 
  onLabelWidth:  @onLabel.width()
  offLabelWidth: @offLabel.width()
  newWidth:      if (onLabelWidth < offLabelWidth) then onLabelWidth else offLabelWidth

  if mode is "container"
    newWidth += @handle.width() + 15 
    @container.css({ width: newWidth })
  else
    @handle.css({ width: newWidth })

$.iphoneStyle::attachEvents: ->
  # A mousedown anywhere in the control will start tracking for dragging
  @container.bind 'mousedown touchstart', (event) =>
    event.preventDefault()

  
  @initialPosition()

$.iphoneStyle::isDisabled = ->
  return @elem.filter(':disabled').length

# Wrap the existing input[type=checkbox] with divs for styling and grab DOM references to the created nodes
$.iphoneStyle::wrapCheckboxWithDivs = ->
  @elem.wrap("<div class='$@containerClass' />");
  
  @container = @elem.parent()
  
  @offLabel  = $("<label class='$@labelOffClass'>" +
                   "<span>$@uncheckedLabel</span>" +
                 "</label>").appendTo(@container)
                     
  @offSpan   = @offLabel.children('span')
  
  @onLabel   = $("<label class='$@labelOnClass'>" +
                  "<span>$@checkedLabel</span>" +
                "</label>").appendTo(@container)
                     
  @onSpan    = @onLabel.children('span')
  
  @handle    = $("<div class='$@handleClass'>" +
                   "<div class='$@handleRightClass'>" +
                     "<div class='$@handleCenterClass' />" +
                   "</div>" +
                 "</div>").appendTo(this.container)
  
# Disable IE text selection, other browsers are handled in CSS
$.iphoneStyle::disableTextSelection = ->
  return if not $.browser.msie

  # Elements containing text should be unselectable
