// JavaScript Document

(function($) {
    $.fn.extend({
        priceFetcher: function(options) {
			
			var defaults = {
    			url: 'fetch.php',
    			bufferTime: 3000
    		};

			
			var options = $.extend(defaults, options);
			
			return this.each(function() { 
				
				var obj = $(this);
				var op  = options;
			    var productId = obj.children('input').val();
			    var target    = obj.children('span');
			    
			    obj.fetch(target, op, productId);
			    
			    setInterval(function() {
			    	obj.fetch(target, op, productId);
			    }, op.bufferTime);
			    
			})
        }
    });
	
	$.fn.fetch = function(target, options, productId)
	{
		$.post(options.url, {
			action: 'fetch',
			productId: productId
		}, function(data) {
			$(target).html(data);
		});
	}
	
	
	
})(jQuery);



