           li.append a
           ul.append li
   
-  popup.click (e) -> e.stopPropagation()
+  popup.click (e) ->
+    e.stopPropagation()
   
-  style = if offset.left < $(window).width() - 150
+  style = if (offset.left < $(window).width() - 150) && !options.right
     "left: #{Math.round offset.left}px"
   else
     "right: #{Math.round($(window).width() - offset.left - element.outerWidth())}px"

# items   Items for menu, see #popup
# open    Callback function to execute before opening the popup menu
# close   Callback function to execute after the popup menu is closed
jQuery.fn.popup = (items, open, close) ->
  id = popupIDs++
  @click (e) ->
    e.stopPropagation()
    element = this
    options = {}
    options.close = -> close.call element if close
    if popupID == id
      closePopup()

  if ST.View && (display instanceof ST.View)
    display.load()
    popup.append display.element()
  else if display instanceof jQuery
    popup.append display
  else
    ul = $ "<ul class=\"popupMenu\"></ul>"
    popup.append ul
