

(function (window) {

	//private variables
	var
	//root api url
	apiURL = "http://example.com:8000/api/v1/",
	//authentication, SWIX Username and Generated API Key
	username,
	apiKey,
	//debug mode settings
	debugMode,
	debugMsg = function(msg)
	{
		if (debugMode)
			console.log(msg);
	},
	//utility function for setting a default param
	defaultParam = function(param, defaultVal)
	{
		if (param == undefined)
			return defaultVal;

		return param;
	},
	// execute a jsonp/GET request
	jsonp = function(path, callback, params)
	{
		var head = document.getElementsByTagName('head')[0];
		var script = document.createElement('script');
		script.type = 'text/javascript';

		var prefix = '?';
		if (path.indexOf('?') >= 0)
			prefix = '&';


		var id = 1;
		//generate a unique id for the callback(jsonp padding)
		//then add the callback to the list of callbacks
		while (SWIX.jsonp_callbacks[id] !== undefined)
			id += Math.floor(Math.random()*11); //always a whole number

		//define our callback.
		//essentially calls our callback and performs some cleanup.
		SWIX.jsonp_callbacks[id] = function()
		{
			//execute callback clean up
			delete SWIX.jsonp_callbacks[id];
			callback.apply(params, arguments);

		};

		path += prefix +
				'username=' + username + "&api_key=" + apiKey +
				'&format=jsonp&callback=' +
				encodeURIComponent('SWIX.jsonp_callbacks['+ id +']');

		src = apiURL + path;
		script.setAttribute('src', src);
		debugMsg('requesting: ' + src);

		head.appendChild(script);

	},
	// local swix variable also public in window
	SWIX = window.SWIX = {};


	//initialization function, initialized username and api key
	// also initialized debug mode. (which currently doesn't really do anything)
	SWIX.init = function(user, key, debug)
	{
		username = user;
		apiKey = key;
		debugMode = defaultParam(debug, false);
		return this;
	};

	//Get All brands associated with an account
	SWIX.getBrands = function(callback, params)
	{
		endpointURL = 'brand/';
		jsonp(endpointURL, callback, params);
		return this;
	};

	//Get Metadata associated with a brand by the brands ID
	SWIX.getBrandByID = function(id, callback, params)
	{
		endpointURL = 'brand/' + id + '/';
		jsonp(endpointURL, callback, params);
		return this;
	};

	//Get List of Pods associated with a particular brand
	SWIX.getBrandPods = function(brandID, callback, params)
	{
		endpointURL = 'brand/'+ brandID + '/pod/';
		jsonp(endpointURL, callback);
		return this;
	};

	//Get Pod Metadata given a particular brand id and pod id
	SWIX.getPodByID = function(brandID, podID, callback, params)
	{
		endpointURL = 'brand/' + brandID + '/pod/' + podID + '/';
		jsonp(endpointURL, callback, params);
		return this;
	};

	//Get a pods series data
	SWIX.getPodSeriesData = function(brandID, podID, metric, graph, callback, params)
	{
		metric = defaultParam(metric, '');
		graph = defaultParam(graph, 'highcharts');
		param = ""
		
		if(metric != '')
		{
		    param = "?fields=" + metric + "&graph=" + graph;
		}
		else
		{
		    param = "?graph=" + graph;
		}
		
		
		endpointURL = 'brand/' + brandID + '/pod/' + podID + '/seriesdata/' + param;
		jsonp(endpointURL, callback, params)
		return this;
	};

	SWIX.jsonp_callbacks = {};
}(window));

@@ -2882,18 +2882,8 @@
 h, '
-highcharts
 ');%0A
@@ -2958,47 +2958,148 @@
 tric
- + %22&graph=%22 + graph;%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09
+;%0A%09%09%7D%0A%09%09%0A%09%09if(graph != '')%0A%09%09%7B%0A%09%09    if( param != '')%0A%09%09    %7B%0A%09%09        param = param + %22&graph=%22 + graph;%0A%09%09    %7D%0A%09%09    else%0A%09%09    %7B%0A%09%09    
     
@@ -3125,16 +3125,24 @@
  graph;%0A
+%09%09    %7D%0A
 %09%09%7D%0A%09%09%0A%09

Allow pod series to be graph format, or other formats