// FEED FORMAT
// s - Symbol
// n - Name
// n4- Notes
(function($){
    $.fn.yahooFinance = function(opts) {    	    	
    	// **************************
    	// SETTINGS
    	// **************************
    	var el			= this;
    	var defaults	= {
    		"feedOptions" : "nxsl1t1cl1t1cpobae7e8e9t8mwva2j3rr2e7dy", //s1t1c6k2pobaee7e8e9g3t8mwvv1t7t6",
    		"symbol"	  : "VIP.L",
    		"url"		  : "http://download.finance.yahoo.com/d/quotes.csv",
    		"proxy"		  : "/finance/proxy.php"
    	}
    	options = $.extend(defaults, opts);
	$.Sweet.setDelimiters('<%...%>');
    	// **************************
    	// METHODS
    	// **************************
    	function parseTemplates () {    
    		$.ajax({ url : 'finance.tpl', async: false, cache: true, dataType: 'text', success: function(data, text, xhtmlr) { tplFinance = data; } });
    		$('#finance').template(tplFinance);
    	};
    	function loadData (opts) {    
    		$.ajax({
    			url: options.proxy,
    		    	data: { "url": options.url, 
    				"feedOptions": options.feedOptions, 
    				"symbol": options.symbol 
    			},
    		    	dataType 	: 'text',
    		    	cache		: false,
    		    	success		: function(data){ 
    		    		$('#finance').applyData($.csv()(data), { noIterate: true });
    		    	},
    		    	error		: function(xhr, err, e){ 
    		    		console.log("Error: ", xhr, err, e); 
    		    	}
    		}); 
    		return false;
    	};
    	function parseData (opts) {    
    	    	
    	};
    	function injectData (opts) {    
    	    	
    	};
    	function loadGraph (opts) {    
    	    	
    	};
    	// **************************
    	// LOGIC
    	// **************************
    	return this.each(function() {
    		parseTemplates();
    		loadData(options);
    	});
    };
})(jQuery);

var tplFinance	= "";
