/*
    jQuery.hotDeals.js v1.0
	Copyright (C) 2011 Daniel Harrison
	Date: Thur May 26 2011
	
	Requires:
		- jQuery 1.4.x

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

(function($){ 

	$.fn.hotDeals = function(options) {

		

		// Internal vars
		var opts = $.extend({}, $.fn.hotDeals.defaults, options); 
		
		//obj vars
		var panel = $(this);

		
		//get hot deals content
		$.post(  
			opts.siteRoot+opts.scriptUrl,
			function(data){
				if (data.success) {
					buildHotDeals(data);
				}
			},  
			"json"
		); 
		
		
		function buildHotDeals(data){
			
			
			
			var id = data.id;
			var text = data.text;
			var price = data.price;
			var image_id = data.image_id;
			
			panel.empty();
			
			var anchor = panel.append(
				"<a href='"+opts.siteRoot+"/search_cars/"+id+"'>"+
					"<div class='inner'>"+
						"<div style='float:left; height:68px'>"+
							"<img src='"+opts.siteRoot+"/images/hot_deals_logo.png' alt='Hot Deals Logo'/>"+
						"</div>"+
						"<div class='price'>"+
							"<span style='font-size:50%;vertical-align:super'>$</span>"+price+
						"</div>"+
					"</div>"+
					"<div class='inner'>"+
						"<div class='image'>"+
							"<img src='http://service.ultimate.net.au/ubs_mtaq/member/upload/ubs_mtaq_show_photo.asp?pic_id="+image_id+"&w=80' style='border:5px solid white'  alt='Hot Deals Image'/>"+
						"</div>"+
						"<div class='text'>"+
							text+
						"</div>"+
					"</div>"+
					"<div class='view-more'>View more »</div>"+
				"</a>");
		}
		  
	};  
	
	// plugin defaults - added as a property on our plugin function
	$.fn.hotDeals.defaults = {
		siteRoot: '.',
		scriptUrl: '/controller/hot_deals'
	};
})(jQuery);
