(function($) {
	var base
	  , settings = {
	  		endpoint : 'http://www.vimeo.com/api/oembed.json'
	  	  , callback : 'embedVimeoJSONResponseHTML' + (Math.floor(1000000 * Math.random()))
	  }
	  , script;
	var fn = {
		_init : function(options) {
			if (options) settings = $.extend(true, settings, options);
			base = this;
			script = $('<script type="text/javascript">&lt;/script&gt;').appendTo('head');
			fn._embed();
			return base;
		}
	  , _embed : function() {
	  		script.attr('src', fn._prepareURL()).appendTo('head');
	  	} 
	  , _prepareURL : function() {
	  		var url = settings.endpoint + '?url=' + encodeURIComponent(settings.url) + '&callback=' + settings.callback;
	  		// (optional) The exact width of the video. Defaults to original size.
	  		if (settings.width) 
	  			url += '&width='+ settings.width
	  		// (optional) Same as width, but video will not exceed original size. 
	  		if (settings.maxwidth)
	  			url += '&maxwidth='+ settings.maxwidth
	  		// (optional) The exact height of the video. Defaults to original size.
	  		if (settings.height)
	  			url += '&height='+ settings.height
	  		//(optional) The exact height of the video. Defaults to original size.
	  		if (settings.maxheight)
	  			url += '&maxheight='+ settings.maxheight
	  		// (optional) Show the byline on the video. Defaults to true.
	  		if (settings.byline)
	  			url += '&byline='+ settings.byline
	  		// (optional) Show the title on the video. Defaults to true.
	  		if (settings.title)
	  			url += '&title='+ settings.title
	  		// (optional) Show the user's portrait on the video. Defaults to true.	
	  		if (settings.portrait)
	  			url += '&portrait='+ settings.portrait
	  		// (optional) Specify the color of the video controls.
	  		if (settings.color)
	  			url += '&color='+ settings.color
	  		// (optional) Automatically start playback of the video. Defaults to false.
	  		if (settings.autoplay)
	  			url += '&autoplay='+ settings.autoplay
	  		// (optional) Play the video again automatically when it reaches the end. Defaults to false.
	  		if (settings.loop)
	  			url += '&loop='+ settings.loop
	  		// (optional) Make the embed code XHTML compliant. Defaults to true.
	  		if (settings.xhtml)
	  			url += '&xhtml='+ settings.xhtml
	  		// (optional) Enable the Javascript API for Moogaloop. Defaults to false.
	  		if (settings.api)
	  			url += '&api='+ settings.api
	  		// (optional) Add the "wmode" parameter. Can be either transparent or opaque.
	  		if (settings.wmode)
	  			url += '&wmode='+ settings.wmode
	  		// (optional) Use our new embed code. Defaults to true. NEW!
	  		if (settings.iframe)
	  			url += '&iframe='+ settings.iframe
	  		return url;
	  	}
	}
	window[settings.callback] = function(jsonResponse) {$(base).each(function() { $(this).html(unescape(jsonResponse.html));});}
	$.fn.vimeo = function(a) {return fn._init.apply( this, arguments );}
})(jQuery);
