;

var host = "auctions.cmauctioncenter.com";

(function ($) {
	$.fn.cmac = function(options) {

		// The defaults
  		var defaults = {
			showDesc: true,
			category: false
  		};
  
		// Merge the defaults with the passed ones
  		var options = $.extend(defaults, options);
	
		return this.each(function () {
			var obj = $(this);
			// Get the url

			var url = 'http://' + host + '/auctions/nextOne';

			if (options.category.length) { 
				url += '/' + options.category.split(" ").join("_");
			}

			url += '?callback=?';

			$.getJSON(url,
				function(data) { 
					var html = '';
					if (data.Auction) { 
						html =  '<p class="title"><strong>'+data.Auction.title+'</strong></p>';
						html += '<p class="date">Date: '+data.Auction.hDate+'</p>';
						if (options.showDesc) { 
							html += '<p class="description">'+data.Auction.description+'</p>';
						}
						html += '<p class="link"><a href="http://'+host+'/auction/'+
							data.Auction.id + '/' + data.Auction.slug + 
							'">More Info</a></p>';
					} else { 
						html = 'No upcoming auctions';
					}

					obj.html(html);
				}
			);
    	});
  	};
})(jQuery);
