// AMD wrapper
(function ( root, doc, factory ) {
  if ( typeof define === "function" && define.amd ) {
    // AMD. Register as an anonymous module.
    define( [ "jquery" ], function ( $ ) {
      factory( $, root, doc );
      return $.rjs;
    });
  } else {
    // Browser globals
    factory( root.jQuery, root, doc );
  }
}( this, document, function ( jQuery, window, document, undefined ) {

// container
(function( $ ) {
  $.rjs = {};
}( jQuery ));

(function( $, window, undefined ) {
  $.extend($.mobile, {

    // Version of the jQuery Mobile Framework
    version: "1.4.0pre",

    // Define the url parameter used for referencing widget-generated sub-pages.
    // Translates to to example.html&ui-page=subpageIdentifier
    // hash segment before &ui-page= is used to make Ajax request
    subPageUrlKey: "ui-page",

    // Class assigned to page currently in view, and during transitions
    activePageClass: "ui-page-active",

    // Class used for "active" button state, from CSS framework
    activeBtnClass: "ui-btn-active",

    // Class used for "focus" form element state, from CSS framework
    focusClass: "ui-focus",

    // Automatically handle clicks and form submissions through Ajax, when same-domain
    ajaxEnabled: true,

    // Automatically load and show pages based on location.hash
    hashListeningEnabled: true,

    // disable to prevent jquery from bothering with links
    linkBindingEnabled: true,

    // Set default page transition - 'none' for no transitions
    defaultPageTransition: "fade",

    // Set maximum window width for transitions to apply - 'false' for no limit
    maxTransitionWidth: false,

    // Minimum scroll distance that will be remembered when returning to a page
    minScrollBack: 250,

    // DEPRECATED: the following property is no longer in use, but defined until 2.0 to prevent conflicts
    touchOverflowEnabled: false,

    // Set default dialog transition - 'none' for no transitions
    defaultDialogTransition: "pop",

    // Error response message - appears when an Ajax page request fails
    pageLoadErrorMessage: "Error Loading Page",

    // For error messages, which theme does the box uses?
    pageLoadErrorMessageTheme: "e",

    // replace calls to window.history.back with phonegaps navigation helper
    // where it is provided on the window object
    phonegapNavigationEnabled: false,

    //automatically initialize the DOM when it's ready
    autoInitializePage: true,

    pushStateEnabled: true,

    // allows users to opt in to ignoring content by marking a parent element as
    // data-ignored
    ignoreContentEnabled: false,

    buttonMarkup: {
      hoverDelay: 200
    },

    // disable the alteration of the dynamic base tag or links in the case
    // that a dynamic base tag isn't supported
    dynamicBaseEnabled: true,

    // default the property to remove dependency on assignment in init module
    pageContainer: $()
  });
})( jQuery, this );

(function( $, window, undefined ) {
  var nsNormalizeDict = {},
    // Monkey-patching Sizzle to filter the :jqmData selector
    oldFind = $.find,
    rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
    jqmDataRE = /:jqmData\(([^)]*)\)/g;

  $.extend($.mobile, {

    // Namespace used framework-wide for data-attrs. Default is no namespace

    ns: "",

    // Retrieve an attribute from an element and perform some massaging of the value

    getAttribute: function( e, key, dns ) {
      var data;

      if ( dns ) {
        key = "data-" + $.mobile.ns + key;
      }

      data = e.getAttribute( key );

      // Copied from core's src/data.js:dataAttr()
      // Convert from a string to a proper data type
      try {
        data = data === "true" ? true :
          data === "false" ? false :
          data === "null" ? null :
          // Only convert to a number if it doesn't change the string
          +data + "" === data ? +data :
          rbrace.test( data ) ? JSON.parse( data ) :
          data;
      } catch( err ) {}

      return data;
    },

    // Expose our cache for testing purposes.
    nsNormalizeDict: nsNormalizeDict,

    // Take a data attribute property, prepend the namespace
    // and then camel case the attribute string. Add the result
    // to our nsNormalizeDict so we don't have to do this again.
    nsNormalize: function( prop ) {
      return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
    },

    // Find the closest javascript page element to gather settings data jsperf test
    // http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit
    // possibly naive, but it shows that the parsing overhead for *just* the page selector vs
    // the page and dialog selector is negligable. This could probably be speed up by
    // doing a similar parent node traversal to the one found in the inherited theme code above
    closestPageData: function( $target ) {
      return $target
        .closest( ":jqmData(role='page'), :jqmData(role='dialog')" )
        .data( "mobile-page" );
    }

  });
  // Mobile version of data and removeData and hasData methods
  // ensures all data is set and retrieved using jQuery Mobile's data namespace
  $.fn.jqmData = function( prop, value ) {
    var result;
    if ( typeof prop !== "undefined" ) {
      if ( prop ) {
        prop = $.mobile.nsNormalize( prop );
      }

      // undefined is permitted as an explicit input for the second param
      // in this case it returns the value and does not set it to undefined
      if( arguments.length < 2 || value === undefined ){
        result = this.data( prop );
      } else {
        result = this.data( prop, value );
      }
    }
    return result;
  };

  $.jqmData = function( elem, prop, value ) {
    var result;
    if ( typeof prop !== "undefined" ) {
      result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
    }
    return result;
  };

  $.fn.jqmRemoveData = function( prop ) {
    return this.removeData( $.mobile.nsNormalize( prop ) );
  };

  $.jqmRemoveData = function( elem, prop ) {
    return $.removeData( elem, $.mobile.nsNormalize( prop ) );
  };


  $.find = function( selector, context, ret, extra ) {
    selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );

    return oldFind.call( this, selector, context, ret, extra );
  };

  $.extend( $.find, oldFind );

})( jQuery, this );

/*!
 * jQuery UI Core @VERSION
 * http://jqueryui.com
 *
 * Copyright 2013 jQuery Foundation and other contributors
 * Released under the MIT license.
 * http://jquery.org/license
 *
 * http://api.jqueryui.com/category/ui-core/
 */
(function( $, undefined ) {

var uuid = 0,
  runiqueId = /^ui-id-\d+$/;

// $.ui might exist from components with no dependencies, e.g., $.ui.position
$.ui = $.ui || {};

$.extend( $.ui, {
  version: "@VERSION",

  keyCode: {
    BACKSPACE: 8,
    COMMA: 188,
    DELETE: 46,
    DOWN: 40,
    END: 35,
    ENTER: 13,
    ESCAPE: 27,
    HOME: 36,
    LEFT: 37,
    PAGE_DOWN: 34,
    PAGE_UP: 33,
    PERIOD: 190,
    RIGHT: 39,
    SPACE: 32,
    TAB: 9,
    UP: 38
  }
});

// plugins
$.fn.extend({
  focus: (function( orig ) {
    return function( delay, fn ) {
      return typeof delay === "number" ?
        this.each(function() {
          var elem = this;
          setTimeout(function() {
            $( elem ).focus();
            if ( fn ) {
              fn.call( elem );
            }
          }, delay );
        }) :
        orig.apply( this, arguments );
    };
  })( $.fn.focus ),

  scrollParent: function() {
    var scrollParent;
    if (($.ui.ie && (/(static|relative)/).test(this.css("position"))) || (/absolute/).test(this.css("position"))) {
      scrollParent = this.parents().filter(function() {
        return (/(relative|absolute|fixed)/).test($.css(this,"position")) && (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
      }).eq(0);
    } else {
      scrollParent = this.parents().filter(function() {
        return (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
      }).eq(0);
    }

    return ( /fixed/ ).test( this.css( "position") ) || !scrollParent.length ? $( this[ 0 ].ownerDocument || document ) : scrollParent;
  },

  uniqueId: function() {
    return this.each(function() {
      if ( !this.id ) {
        this.id = "ui-id-" + (++uuid);
      }
    });
  },

  removeUniqueId: function() {
    return this.each(function() {
      if ( runiqueId.test( this.id ) ) {
        $( this ).removeAttr( "id" );
      }
    });
  }
});

// selectors
function focusable( element, isTabIndexNotNaN ) {
  var map, mapName, img,
    nodeName = element.nodeName.toLowerCase();
  if ( "area" === nodeName ) {
    map = element.parentNode;
    mapName = map.name;
    if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
      return false;
    }
    img = $( "img[usemap=#" + mapName + "]" )[0];
    return !!img && visible( img );
  }
  return ( /input|select|textarea|button|object/.test( nodeName ) ?
    !element.disabled :
    "a" === nodeName ?
      element.href || isTabIndexNotNaN :
      isTabIndexNotNaN) &&
    // the element and all of its ancestors must be visible
    visible( element );
}

function visible( element ) {
  return $.expr.filters.visible( element ) &&
    !$( element ).parents().addBack().filter(function() {
      return $.css( this, "visibility" ) === "hidden";
    }).length;
}

$.extend( $.expr[ ":" ], {
  data: $.expr.createPseudo ?
    $.expr.createPseudo(function( dataName ) {
      return function( elem ) {
        return !!$.data( elem, dataName );
      };
    }) :
    // support: jQuery <1.8
    function( elem, i, match ) {
      return !!$.data( elem, match[ 3 ] );
    },

  focusable: function( element ) {
    return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  },

  tabbable: function( element ) {
    var tabIndex = $.attr( element, "tabindex" ),
      isTabIndexNaN = isNaN( tabIndex );
    return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  }
});

// support: jQuery <1.8
if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  $.each( [ "Width", "Height" ], function( i, name ) {
    var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
      type = name.toLowerCase(),
      orig = {
        innerWidth: $.fn.innerWidth,
        innerHeight: $.fn.innerHeight,
        outerWidth: $.fn.outerWidth,
        outerHeight: $.fn.outerHeight
      };

    function reduce( elem, size, border, margin ) {
      $.each( side, function() {
        size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
        if ( border ) {
          size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
        }
        if ( margin ) {
          size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
        }
      });
      return size;
    }

    $.fn[ "inner" + name ] = function( size ) {
      if ( size === undefined ) {
        return orig[ "inner" + name ].call( this );
      }

      return this.each(function() {
        $( this ).css( type, reduce( this, size ) + "px" );
      });
    };

    $.fn[ "outer" + name] = function( size, margin ) {
      if ( typeof size !== "number" ) {
        return orig[ "outer" + name ].call( this, size );
      }

      return this.each(function() {
        $( this).css( type, reduce( this, size, true, margin ) + "px" );
      });
    };
  });
}

// support: jQuery <1.8
if ( !$.fn.addBack ) {
  $.fn.addBack = function( selector ) {
    return this.add( selector == null ?
      this.prevObject : this.prevObject.filter( selector )
    );
  };
}

// support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
  $.fn.removeData = (function( removeData ) {
    return function( key ) {
      if ( arguments.length ) {
        return removeData.call( this, $.camelCase( key ) );
      } else {
        return removeData.call( this );
      }
    };
  })( $.fn.removeData );
}





// deprecated
$.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );

$.support.selectstart = "onselectstart" in document.createElement( "div" );
$.fn.extend({
  disableSelection: function() {
    return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
      ".ui-disableSelection", function( event ) {
        event.preventDefault();
      });
  },

  enableSelection: function() {
    return this.unbind( ".ui-disableSelection" );
  },

  zIndex: function( zIndex ) {
    if ( zIndex !== undefined ) {
      return this.css( "zIndex", zIndex );
    }

    if ( this.length ) {
      var elem = $( this[ 0 ] ), position, value;
      while ( elem.length && elem[ 0 ] !== document ) {
        // Ignore z-index if position is set to a value where z-index is ignored by the browser
        // This makes behavior of this function consistent across browsers
        // WebKit always returns auto if the element is positioned
        position = elem.css( "position" );
        if ( position === "absolute" || position === "relative" || position === "fixed" ) {
          // IE returns 0 when zIndex is not specified
          // other browsers return a string
          // we ignore the case of nested elements with an explicit value of 0
          // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
          value = parseInt( elem.css( "zIndex" ), 10 );
          if ( !isNaN( value ) && value !== 0 ) {
            return value;
          }
        }
        elem = elem.parent();
      }
    }

    return 0;
  }
});

// $.ui.plugin is deprecated. Use $.widget() extensions instead.
$.ui.plugin = {
  add: function( module, option, set ) {
    var i,
      proto = $.ui[ module ].prototype;
    for ( i in set ) {
      proto.plugins[ i ] = proto.plugins[ i ] || [];
      proto.plugins[ i ].push( [ option, set[ i ] ] );
    }
  },
  call: function( instance, name, args, allowDisconnected ) {
    var i,
      set = instance.plugins[ name ];

    if ( !set ) {
      return;
    }

    if ( !allowDisconnected && ( !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) ) {
      return;
    }

    for ( i = 0; i < set.length; i++ ) {
      if ( instance.options[ set[ i ][ 0 ] ] ) {
        set[ i ][ 1 ].apply( instance.element, args );
      }
    }
  }
};

})( jQuery );
(function( $, window, undefined ) {

  // jQuery.mobile configurable options
  $.extend($.mobile, {
    // define the window and the document objects
    window: $( window ),
    document: $( document ),

    //TODO: Remove once we pull in UI Core
    keyCode: $.ui.keyCode,

    // Place to store various widget extensions
    behaviors: {},
    // Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
    silentScroll: function( ypos ) {
      if ( $.type( ypos ) !== "number" ) {
        ypos = $.mobile.defaultHomeScroll;
      }

      // prevent scrollstart and scrollstop events
      $.event.special.scrollstart.enabled = false;

      setTimeout( function() {
        window.scrollTo( 0, ypos );
        $.mobile.document.trigger( "silentscroll", { x: 0, y: ypos });
      }, 20 );

      setTimeout( function() {
        $.event.special.scrollstart.enabled = true;
      }, 150 );
    },

    // DEPRECATED in 1.4
    // Find the closest parent with a theme class on it. Note that
    // we are not using $.fn.closest() on purpose here because this
    // method gets called quite a bit and we need it to be as fast
    // as possible.
    getInheritedTheme: function( el, defaultTheme ) {
      var e = el[ 0 ],
        ltr = "",
        re = /ui-(bar|body|overlay)-([a-z])\b/,
        c, m;
      while ( e ) {
        c = e.className || "";
        if ( c && ( m = re.exec( c ) ) && ( ltr = m[ 2 ] ) ) {
          // We found a parent with a theme class
          // on it so bail from this loop.
          break;
        }

        e = e.parentNode;
      }
      // Return the theme letter we found, if none, return the
      // specified default.
      return ltr || defaultTheme || "a";
    },

    // TODO the following $ and $.fn extensions can/probably should be moved into jquery.mobile.core.helpers
    //

    enhanceable: function( $set ) {
      return this.haveParents( $set, "enhance" );
    },

    hijackable: function( $set ) {
      return this.haveParents( $set, "ajax" );
    },

    haveParents: function( $set, attr ) {
      if ( !$.mobile.ignoreContentEnabled ) {
        return $set;
      }

      var count = $set.length,
        $newSet = $(),
        e, $element, excluded,
        i, c;

      for ( i = 0; i < count; i++ ) {
        $element = $set.eq( i );
        excluded = false;
        e = $set[ i ];

        while ( e ) {
          c = e.getAttribute ? e.getAttribute( "data-" + $.mobile.ns + attr ) : "";

          if ( c === "false" ) {
            excluded = true;
            break;
          }

          e = e.parentNode;
        }

        if ( !excluded ) {
          $newSet = $newSet.add( $element );
        }
      }

      return $newSet;
    },

    getScreenHeight: function() {
      // Native innerHeight returns more accurate value for this across platforms,
      // jQuery version is here as a normalized fallback for platforms like Symbian
      return window.innerHeight || $.mobile.window.height();
    },

    //simply set the active page's minimum height to screen height, depending on orientation
    resetActivePageHeight: function( height ) {
      var aPage = $( "." + $.mobile.activePageClass ),
        aPageHeight = aPage.height(),
        aPageOuterHeight = aPage.outerHeight( true );

      height = ( typeof height === "number" ) ? height : $.mobile.getScreenHeight();

      aPage.css( "min-height", height - ( aPageOuterHeight - aPageHeight ) );
    }
  });

  $.fn.removeWithDependents = function() {
    $.removeWithDependents( this );
  };

  $.removeWithDependents = function( elem ) {
    var $elem = $( elem );

    ( $elem.jqmData( "dependents" ) || $() ).remove();
    $elem.remove();
  };

  $.fn.addDependents = function( newDependents ) {
    $.addDependents( this , newDependents );
  };

  $.addDependents = function( elem, newDependents ) {
    var $elem = $( elem ),
      dependents = $elem.jqmData( "dependents" ) || $();

    $elem.jqmData( "dependents", $( dependents ).add( newDependents ) );
  };

  // note that this helper doesn't attempt to handle the callback
  // or setting of an html element's text, its only purpose is
  // to return the html encoded version of the text in all cases. (thus the name)
  $.fn.getEncodedText = function() {
    return $( "<a>" ).text( $( this ).text() ).html();
  };

  // fluent helper function for the mobile namespaced equivalent
  $.fn.jqmEnhanceable = function() {
    return $.mobile.enhanceable( this );
  };

  $.fn.jqmHijackable = function() {
    return $.mobile.hijackable( this );
  };

  $.find.matches = function( expr, set ) {
    return $.find( expr, null, null, set );
  };

  $.find.matchesSelector = function( node, expr ) {
    return $.find( expr, null, null, [ node ] ).length > 0;
  };

})( jQuery, this );


/*!
 * jQuery UI Widget 1.10.1
 * http://jqueryui.com
 *
 * Copyright 2013 jQuery Foundation and other contributors
 * Released under the MIT license.
 * http://jquery.org/license
 *
 * http://api.jqueryui.com/jQuery.widget/
 */
(function( $, undefined ) {

var uuid = 0,
  slice = Array.prototype.slice,
  _cleanData = $.cleanData;
$.cleanData = function( elems ) {
  for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
    try {
      $( elem ).triggerHandler( "remove" );
    // http://bugs.jquery.com/ticket/8235
    } catch( e ) {}
  }
  _cleanData( elems );
};

$.widget = function( name, base, prototype ) {
  var fullName, existingConstructor, constructor, basePrototype,
    // proxiedPrototype allows the provided prototype to remain unmodified
    // so that it can be used as a mixin for multiple widgets (#8876)
    proxiedPrototype = {},
    namespace = name.split( "." )[ 0 ];

  name = name.split( "." )[ 1 ];
  fullName = namespace + "-" + name;

  if ( !prototype ) {
    prototype = base;
    base = $.Widget;
  }

  // create selector for plugin
  $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
    return !!$.data( elem, fullName );
  };

  $[ namespace ] = $[ namespace ] || {};
  existingConstructor = $[ namespace ][ name ];
  constructor = $[ namespace ][ name ] = function( options, element ) {
    // allow instantiation without "new" keyword
    if ( !this._createWidget ) {
      return new constructor( options, element );
    }

    // allow instantiation without initializing for simple inheritance
    // must use "new" keyword (the code above always passes args)
    if ( arguments.length ) {
      this._createWidget( options, element );
    }
  };
  // extend with the existing constructor to carry over any static properties
  $.extend( constructor, existingConstructor, {
    version: prototype.version,
    // copy the object used to create the prototype in case we need to
    // redefine the widget later
    _proto: $.extend( {}, prototype ),
    // track widgets that inherit from this widget in case this widget is
    // redefined after a widget inherits from it
    _childConstructors: []
  });

  basePrototype = new base();
  // we need to make the options hash a property directly on the new instance
  // otherwise we'll modify the options hash on the prototype that we're
  // inheriting from
  basePrototype.options = $.widget.extend( {}, basePrototype.options );
  $.each( prototype, function( prop, value ) {
    if ( !$.isFunction( value ) ) {
      proxiedPrototype[ prop ] = value;
      return;
    }
    proxiedPrototype[ prop ] = (function() {
      var _super = function() {
          return base.prototype[ prop ].apply( this, arguments );
        },
        _superApply = function( args ) {
          return base.prototype[ prop ].apply( this, args );
        };
      return function() {
        var __super = this._super,
          __superApply = this._superApply,
          returnValue;

        this._super = _super;
        this._superApply = _superApply;

        returnValue = value.apply( this, arguments );

        this._super = __super;
        this._superApply = __superApply;

        return returnValue;
      };
    })();
  });
  constructor.prototype = $.widget.extend( basePrototype, {
    // TODO: remove support for widgetEventPrefix
    // always use the name + a colon as the prefix, e.g., draggable:start
    // don't prefix for widgets that aren't DOM-based
    widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name
  }, proxiedPrototype, {
    constructor: constructor,
    namespace: namespace,
    widgetName: name,
    widgetFullName: fullName
  });

  // If this widget is being redefined then we need to find all widgets that
  // are inheriting from it and redefine all of them so that they inherit from
  // the new version of this widget. We're essentially trying to replace one
  // level in the prototype chain.
  if ( existingConstructor ) {
    $.each( existingConstructor._childConstructors, function( i, child ) {
      var childPrototype = child.prototype;

      // redefine the child widget using the same prototype that was
      // originally used, but inherit from the new version of the base
      $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
    });
    // remove the list of existing child constructors from the old constructor
    // so the old child constructors can be garbage collected
    delete existingConstructor._childConstructors;
  } else {
    base._childConstructors.push( constructor );
  }

  $.widget.bridge( name, constructor );
};

$.widget.extend = function( target ) {
  var input = slice.call( arguments, 1 ),
    inputIndex = 0,
    inputLength = input.length,
    key,
    value;
  for ( ; inputIndex < inputLength; inputIndex++ ) {
    for ( key in input[ inputIndex ] ) {
      value = input[ inputIndex ][ key ];
      if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
        // Clone objects
        if ( $.isPlainObject( value ) ) {
          target[ key ] = $.isPlainObject( target[ key ] ) ?
            $.widget.extend( {}, target[ key ], value ) :
            // Don't extend strings, arrays, etc. with objects
            $.widget.extend( {}, value );
        // Copy everything else by reference
        } else {
          target[ key ] = value;
        }
      }
    }
  }
  return target;
};

$.widget.bridge = function( name, object ) {
  var fullName = object.prototype.widgetFullName || name;
  $.fn[ name ] = function( options ) {
    var isMethodCall = typeof options === "string",
      args = slice.call( arguments, 1 ),
      returnValue = this;

    // allow multiple hashes to be passed on init
    options = !isMethodCall && args.length ?
      $.widget.extend.apply( null, [ options ].concat(args) ) :
      options;

    if ( isMethodCall ) {
      this.each(function() {
        var methodValue,
          instance = $.data( this, fullName );
        if ( !instance ) {
          return $.error( "cannot call methods on " + name + " prior to initialization; " +
            "attempted to call method '" + options + "'" );
        }
        if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
          return $.error( "no such method '" + options + "' for " + name + " widget instance" );
        }
        methodValue = instance[ options ].apply( instance, args );
        if ( methodValue !== instance && methodValue !== undefined ) {
          returnValue = methodValue && methodValue.jquery ?
            returnValue.pushStack( methodValue.get() ) :
            methodValue;
          return false;
        }
      });
    } else {
      this.each(function() {
        var instance = $.data( this, fullName );
        if ( instance ) {
          instance.option( options || {} )._init();
        } else {
          $.data( this, fullName, new object( options, this ) );
        }
      });
    }

    return returnValue;
  };
};

$.Widget = function( /* options, element */ ) {};
$.Widget._childConstructors = [];

$.Widget.prototype = {
  widgetName: "widget",
  widgetEventPrefix: "",
  defaultElement: "<div>",
  options: {
    disabled: false,

    // callbacks
    create: null
  },
  _createWidget: function( options, element ) {
    element = $( element || this.defaultElement || this )[ 0 ];
    this.element = $( element );
    this.uuid = uuid++;
    this.eventNamespace = "." + this.widgetName + this.uuid;
    this.options = $.widget.extend( {},
      this.options,
      this._getCreateOptions(),
      options );

    this.bindings = $();
    this.hoverable = $();
    this.focusable = $();

    if ( element !== this ) {
      $.data( element, this.widgetFullName, this );
      this._on( true, this.element, {
        remove: function( event ) {
          if ( event.target === element ) {
            this.destroy();
          }
        }
      });
      this.document = $( element.style ?
        // element within the document
        element.ownerDocument :
        // element is window or document
        element.document || element );
      this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
    }

    this._create();
    this._trigger( "create", null, this._getCreateEventData() );
    this._init();
  },
  _getCreateOptions: $.noop,
  _getCreateEventData: $.noop,
  _create: $.noop,
  _init: $.noop,

  destroy: function() {
    this._destroy();
    // we can probably remove the unbind calls in 2.0
    // all event bindings should go through this._on()
    this.element
      .unbind( this.eventNamespace )
      // 1.9 BC for #7810
      // TODO remove dual storage
      .removeData( this.widgetName )
      .removeData( this.widgetFullName )
      // support: jquery <1.6.3
      // http://bugs.jquery.com/ticket/9413
      .removeData( $.camelCase( this.widgetFullName ) );
    this.widget()
      .unbind( this.eventNamespace )
      .removeAttr( "aria-disabled" )
      .removeClass(
        this.widgetFullName + "-disabled " +
        "ui-state-disabled" );

    // clean up events and states
    this.bindings.unbind( this.eventNamespace );
    this.hoverable.removeClass( "ui-state-hover" );
    this.focusable.removeClass( "ui-state-focus" );
  },
  _destroy: $.noop,

  widget: function() {
    return this.element;
  },

  option: function( key, value ) {
    var options = key,
      parts,
      curOption,
      i;

    if ( arguments.length === 0 ) {
      // don't return a reference to the internal hash
      return $.widget.extend( {}, this.options );
    }

    if ( typeof key === "string" ) {
      // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
      options = {};
      parts = key.split( "." );
      key = parts.shift();
      if ( parts.length ) {
        curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
        for ( i = 0; i < parts.length - 1; i++ ) {
          curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
          curOption = curOption[ parts[ i ] ];
        }
        key = parts.pop();
        if ( value === undefined ) {
          return curOption[ key ] === undefined ? null : curOption[ key ];
        }
        curOption[ key ] = value;
      } else {
        if ( value === undefined ) {
          return this.options[ key ] === undefined ? null : this.options[ key ];
        }
        options[ key ] = value;
      }
    }

    this._setOptions( options );

    return this;
  },
  _setOptions: function( options ) {
    var key;

    for ( key in options ) {
      this._setOption( key, options[ key ] );
    }

    return this;
  },
  _setOption: function( key, value ) {
    this.options[ key ] = value;

    if ( key === "disabled" ) {
      this.widget()
        .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
        .attr( "aria-disabled", value );
      this.hoverable.removeClass( "ui-state-hover" );
      this.focusable.removeClass( "ui-state-focus" );
    }

    return this;
  },

  enable: function() {
    return this._setOption( "disabled", false );
  },
  disable: function() {
    return this._setOption( "disabled", true );
  },

  _on: function( suppressDisabledCheck, element, handlers ) {
    var delegateElement,
      instance = this;

    // no suppressDisabledCheck flag, shuffle arguments
    if ( typeof suppressDisabledCheck !== "boolean" ) {
      handlers = element;
      element = suppressDisabledCheck;
      suppressDisabledCheck = false;
    }

    // no element argument, shuffle and use this.element
    if ( !handlers ) {
      handlers = element;
      element = this.element;
      delegateElement = this.widget();
    } else {
      // accept selectors, DOM elements
      element = delegateElement = $( element );
      this.bindings = this.bindings.add( element );
    }

    $.each( handlers, function( event, handler ) {
      function handlerProxy() {
        // allow widgets to customize the disabled handling
        // - disabled as an array instead of boolean
        // - disabled class as method for disabling individual parts
        if ( !suppressDisabledCheck &&
            ( instance.options.disabled === true ||
              $( this ).hasClass( "ui-state-disabled" ) ) ) {
          return;
        }
        return ( typeof handler === "string" ? instance[ handler ] : handler )
          .apply( instance, arguments );
      }

      // copy the guid so direct unbinding works
      if ( typeof handler !== "string" ) {
        handlerProxy.guid = handler.guid =
          handler.guid || handlerProxy.guid || $.guid++;
      }

      var match = event.match( /^(\w+)\s*(.*)$/ ),
        eventName = match[1] + instance.eventNamespace,
        selector = match[2];
      if ( selector ) {
        delegateElement.delegate( selector, eventName, handlerProxy );
      } else {
        element.bind( eventName, handlerProxy );
      }
    });
  },

  _off: function( element, eventName ) {
    eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
    element.unbind( eventName ).undelegate( eventName );
  },

  _delay: function( handler, delay ) {
    function handlerProxy() {
      return ( typeof handler === "string" ? instance[ handler ] : handler )
        .apply( instance, arguments );
    }
    var instance = this;
    return setTimeout( handlerProxy, delay || 0 );
  },

  _hoverable: function( element ) {
    this.hoverable = this.hoverable.add( element );
    this._on( element, {
      mouseenter: function( event ) {
        $( event.currentTarget ).addClass( "ui-state-hover" );
      },
      mouseleave: function( event ) {
        $( event.currentTarget ).removeClass( "ui-state-hover" );
      }
    });
  },

  _focusable: function( element ) {
    this.focusable = this.focusable.add( element );
    this._on( element, {
      focusin: function( event ) {
        $( event.currentTarget ).addClass( "ui-state-focus" );
      },
      focusout: function( event ) {
        $( event.currentTarget ).removeClass( "ui-state-focus" );
      }
    });
  },

  _trigger: function( type, event, data ) {
    var prop, orig,
      callback = this.options[ type ];

    data = data || {};
    event = $.Event( event );
    event.type = ( type === this.widgetEventPrefix ?
      type :
      this.widgetEventPrefix + type ).toLowerCase();
    // the original event may come from any element
    // so we need to reset the target on the new event
    event.target = this.element[ 0 ];

    // copy original event properties over to the new event
    orig = event.originalEvent;
    if ( orig ) {
      for ( prop in orig ) {
        if ( !( prop in event ) ) {
          event[ prop ] = orig[ prop ];
        }
      }
    }

    this.element.trigger( event, data );
    return !( $.isFunction( callback ) &&
      callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
      event.isDefaultPrevented() );
  }
};

$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
    if ( typeof options === "string" ) {
      options = { effect: options };
    }
    var hasOptions,
      effectName = !options ?
        method :
        options === true || typeof options === "number" ?
          defaultEffect :
          options.effect || defaultEffect;
    options = options || {};
    if ( typeof options === "number" ) {
      options = { duration: options };
    }
    hasOptions = !$.isEmptyObject( options );
    options.complete = callback;
    if ( options.delay ) {
      element.delay( options.delay );
    }
    if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
      element[ method ]( options );
    } else if ( effectName !== method && element[ effectName ] ) {
      element[ effectName ]( options.duration, options.easing, callback );
    } else {
      element.queue(function( next ) {
        $( this )[ method ]();
        if ( callback ) {
          callback.call( element[ 0 ] );
        }
        next();
      });
    }
  };
});

})( jQuery );

(function( $, undefined ) {

$.extend( $.Widget.prototype, {
  _getCreateOptions: function() {

    var elem = this.element,
      options = {};

    $.each( this.options, function( option ) {

      var value = $.mobile.getAttribute( elem[ 0 ], option.replace( /[A-Z]/g, function( c ) {
              return "-" + c.toLowerCase();
            }), true );

      if ( value != null ) {
        options[ option ] = value;
      }
    });

    return options;
  },

  enhanceWithin: function( target, useKeepNative ) {
    this.enhance( $( $[ this.namespace ][ this.widgetName ].initSelector, $( target ) ), useKeepNative );
  },

  enhance: function( targets, useKeepNative ) {
    var page, keepNative, $widgetElements = $( targets );

    // if ignoreContentEnabled is set to true the framework should
    // only enhance the selected elements when they do NOT have a
    // parent with the data-namespace-ignore attribute
    $widgetElements = $.mobile.enhanceable( $widgetElements );

    if ( useKeepNative && $widgetElements.length ) {
      // TODO remove dependency on the page widget for the keepNative.
      // Currently the keepNative value is defined on the page prototype so
      // the method is as well
      page = $.mobile.closestPageData( $widgetElements );
      keepNative = ( page && page.keepNativeSelector()) || "";

      $widgetElements = $widgetElements.not( keepNative );
    }

    $widgetElements[ this.widgetName ]();
  }
});
//TODO: Remove in 1.5 for backcompat only
$.mobile.widget = $.Widget;
})( jQuery );

























(function( $, undefined ) {

var doc = $( document );

$.mobile._Enhancer = function() {
  this._dependencies = {};
};

$.extend( $.mobile._Enhancer.prototype, {

  _defaultCallback: function( widget ) {
    var parts = widget.split( "." ),
      ns = parts[ 0 ],
      name = parts[ 1 ],
      ret = function( targetEl ) {
        // First try to grab the initSelector from the old location in case
        // some legacy code modified it. If not, grab it from the new location.
        var targets = $( $[ ns ][ name ].prototype.options.initSelector ||
          $[ ns ][ name ].initSelector, targetEl );

        if ( targets.length ) {
          $[ ns ][ name ].prototype.enhance( targets, true );
        }
      };

    return ret;
  },

  add: function( widget, widgetDeps, callback ) {
    var deps = this._dependencies;

    if ( !widgetDeps ) {
      widgetDeps = { dependencies: [] };
    }

    if ( !callback ) {
      callback = this._defaultCallback( widget );
    }

    deps[ widget ] = {
      deps: widgetDeps.dependencies,
      callback: callback
    };

    return this;
  },

  _enhance: function( el, idx, visited ) {
    var depIdx,
      dep = this._dependencies[ idx ];

    if ( dep && !visited[ idx ] ) {
      for ( depIdx in dep.deps ) {
        this._enhance( el, dep.deps[ depIdx ], visited );
      }
      dep.callback( el );
      visited[ idx ] = true;
    }
  },

  enhance: function( targetEl ) {
    var idx,
      visited = {},
      deps = this._dependencies;

    for ( idx in deps ) {
      this._enhance( targetEl, idx, visited );
    }

    return this;
  }
});

$.mobile._enhancer = new $.mobile._Enhancer();

// Support triggering "create" on an element
doc.bind( "create", function( e ) {
  $.mobile._enhancer.enhance( e.target );
});

})( jQuery );

(function( $, undefined ) {

$.widget( "mobile.page", {
  options: {
    theme: "a",
    domCache: false,
    keepNativeDefault: ":jqmData(role='none'), :jqmData(role='nojs')",
    contentTheme: null
  },

  // DEPRECATED for > 1.4
  // TODO remove at 1.5
  _createWidget: function() {
    $.Widget.prototype._createWidget.apply( this, arguments );
    this._trigger( "init" );
  },

  _create: function() {
    var attrPrefix = "data-" + $.mobile.ns,
      self = this;
    // if false is returned by the callbacks do not create the page
    if ( this._trigger( "beforecreate" ) === false ) {
      return false;
    }

    if ( this.options.role ) {
      this.element.attr( "data-" + $.mobile.ns + "role", this.options.role );
    }

    this.element
      .attr( "tabindex", "0" )
      .addClass( "ui-page ui-page-theme-" + this.options.theme );

    this._on( this.element, {
      pagebeforehide: "removeContainerBackground",
      pagebeforeshow: "_handlePageBeforeShow"
    });
    this.element.find( "[" + attrPrefix + "role='content']" ).each( function() {
      var $this = $( this ),
        theme = this.getAttribute( attrPrefix + "theme" ) || undefined;
        self.options.contentTheme = theme || self.options.contentTheme || ( self.element.jqmData("role") === "dialog" &&  self.options.theme );
        $this.addClass( "ui-content" );
        if ( self.options.contentTheme ) {
          $this.addClass( "ui-body-" + ( self.options.contentTheme ) );
        }
        // Add ARIA role
        $this.attr( "role", "main" ).addClass( "ui-content" );
    });

    // enhance the page
    $.mobile._enhancer.enhance( this.element[ 0 ] );
  },

  bindRemove: function( callback ) {
    var page = this.element;

    // when dom caching is not enabled or the page is embedded bind to remove the page on hide
    if ( !page.data( "mobile-page" ).options.domCache &&
      page.is( ":jqmData(external-page='true')" ) ) {

      // TODO use _on - that is, sort out why it doesn't work in this case
      page.bind( "pagehide.remove", callback || function(/* e */) {
        var $this = $( this ),
          prEvent = new $.Event( "pageremove" );

        $this.trigger( prEvent );

        if ( !prEvent.isDefaultPrevented() ) {
          $this.removeWithDependents();
        }
      });
    }
  },

  _setOptions: function( o ) {
    if( o.theme !== undefined ) {
      this.element.removeClass( "ui-body-" + this.options.theme ).addClass( "ui-body-" + o.theme );
    }

    if( o.contentTheme !== undefined ) {
      this.element.find( "[data-" + $.mobile.ns + "='content']" ).removeClass( "ui-body-" + this.options.contentTheme )
        .addClass( "ui-body-" + o.contentTheme );
    }
  },

  _handlePageBeforeShow: function(/* e */) {
    this.setContainerBackground();
  },

  removeContainerBackground: function() {
    var classes = ( $.mobile.pageContainer.attr( "class" ) || "" ).split( " " ),
      overlayTheme = null,
      matches;

    while ( classes.length > 0 ) {
      overlayTheme = classes.pop();
      matches = ( new RegExp( "^ui-overlay-([a-z])$" ) ).exec( overlayTheme );
      if ( matches && matches.length > 1 ) {
        overlayTheme = matches[ 1 ];
        break;
      } else {
        overlayTheme = null;
      }
    }

    $.mobile.pageContainer.removeClass( "ui-overlay-" + overlayTheme );
  },

  // set the page container background to the page theme
  setContainerBackground: function( theme ) {
    if ( this.options.theme ) {
      $.mobile.pageContainer.addClass( "ui-overlay-" + ( theme || this.options.theme ) );
    }
  },

  keepNativeSelector: function() {
    var options = this.options,
      keepNativeDefined = options.keepNative && $.trim( options.keepNative );

    if ( keepNativeDefined && options.keepNative !== options.keepNativeDefault ) {
      return [options.keepNative, options.keepNativeDefault].join( ", " );
    }

    return options.keepNativeDefault;
  }
});
})( jQuery );
















// ========================================================================

  // template for functions
  /*
  (function( $, window, undefined ) {

  $.rjs.foo = function() {
    this.init.apply(this, arguments);
  };

  $.extend($.rjs.foo.prototype, {

    someClass: " ui-foo",

    someFunction: function( name, reverse, $to, $from ) {
      $.extend(this, {
        name: name,
        reverse: reverse,
        $to: $to,
        $from: $from,
        deferred: new $.Deferred()
      });
    },

    usw: function(...)
  */


  // initializer
  (function( $, window, undefined ) {
    var $html = $( "html" );

    //remove initial build class (only present on first pageshow)
    function hideRenderingClass() {
      $html.removeClass( "ui-rjs-rendering" );
    }

    // trigger mobileinit event - useful hook for configuring $.rjs settings before they're used
    $( window.document ).trigger( "renderinit" );

    // Add rjs, initial load "rendering" classes to docEl
    $html.addClass( "ui-rjs ui-rjs-rendering" );

    // This is a fallback. If anything goes wrong (JS errors, etc), or events don't fire,
    // this ensures the rendering class is removed after 5 seconds, so content is visible and accessible
    setTimeout( hideRenderingClass, 5000 );

    $.extend( $.rjs, {
      // find and enhance the gadgets in the dom
      initialize: function() {
        // find present pages
        var $gadgets = $( ":rjsData(gadget='true')" );

        if ( !$gadgets.length ) {
          // what do we do here
        }

        // initialize navigation events now, after mobileinit has occurred and the page container
        // has been created but before the rest of the library is alerted to that fact
        $.rjs.rjsReadyDeferred.resolve();

        //remove initial build class (only present on first page)
        hideRenderingClass();

        // retrieve intial hash config
        if ( /* we are passed a rjs configuration */ ) {

        }

        // do something with the gadgets found (this used to be pages!)
        // maybe model gadget after pages
      }
    });
  }( jQuery, this ));

}));
