/* Plugin Development Pattern from http://www.learningjquery.com/2007/10/a-plugin-development-pattern */

//
// create closure
//
(function($) {
	//
	// plugin definition
	//
	$.fn.jumpmenu = function(options) {
		
		// build main options before element iteration
		var opts = $.extend({}, $.fn.jumpmenu.defaults, options);
		
		// iterate and reformat each matched element
		return this.each(function() {
			$this = $(this);
			// build element specific options
			var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
			
			// perform plugin actions
			$this.empty();
			var $newmenu = $("<select>");
			$newmenu.appendTo($this);
			$newmenu.append('<option value="">' + o.menudefault + '</option>');
			for (var i in o.menuitems) {
				$newmenu.append('<option value="' + o.menuitems[i] + '">' + i + '</option>');
			}
			$newmenu.change( function() {
				var newlocation = $(this).find("option:selected").eq(0).attr("value");
				if (newlocation != "")  window.location = newlocation;
			});
		});
	};
	
	//
	// plugin defaults
	//
	$.fn.jumpmenu.defaults = {
		//define default values
		menudefault : "-- Please select --",
		menuitems : { "Google": "http://www.google.com", "Yahoo": "http://www.yahoo.com" }
	};
	
//
// end of closure
//
})(jQuery);