// Requires the share & jQuery libraries to be included first

if (!window['netShelter']) 
	window['netShelter'] = {};

netShelter.ProductModel = function(
	keyName,
	title,
	description,
	storyFeedPath,
	videoModel,
	purchasePath,
	learnMorePath
) {
	this.keyName =				keyName				||	"";
	this.title =				title				||	"";
	this.description =			description			||	"";
	this.storyFeedPath =		storyFeedPath		||	"";
	this.videoModel =			videoModel			||	[];
	this.purchasePath =			purchasePath		||	"";
	this.learnMorePath =		learnMorePath		||	"";
}

netShelter.ProductModel.fromXML = function(node) {
	with (netShelter) {
		var node = $(node);
	
		var result = new ProductModel(
			node.attr('id'),
			node.attr('title'),
			node.attr('description'),
			node.attr('story_feed_path'),
			[],							// Haven't bothered making a VideoModel yet 
			node.attr('purchase_path'),
			node.attr('learn_more_path')
		);
		
		return result;
	}
}

netShelter.getProductModelsFromFeed = function(productFeedPath, callback) {
	return netShelter.getModelsFromXMLFeed({
		'feedPath':		productFeedPath, 
		'parser':		netShelter.ProductModel.fromXML, 
		'nodeName':		'product', 
		'callback':		modelListToDict(callback),
		'dataType':		'xml'
	});
	
	function modelListToDict(callback) {
		return function(list) {
			dict = {};

			for (var i = 0; i < list.length; i++) {
				dict[list[i].keyName] = list[i];
			}
		
			callback(dict);
		}
	}
}

