var contentLoader = new Class({
	initialize: function(targetId,menuId) {
		this.feedConduit = "doubleYourBagContent.action";
		this.myTarget = $(targetId);
		this.myMenu = $(menuId);
		this.myMenuItems = this.myMenu.getElements('a');
		this.myMenuItems.each(function(item) {
			item.addEvent("click", function(event) {
				this.loadContent(item.id);
				this.setMenu(item);
				event = new Event(event).stop();
			}.bind(this));
		}.bind(this));
	},
	loadContent: function(itemID) {	
		var myAjax = new Ajax(this.feedConduit+'?title='+itemID, {
			method: 'get',
			evalScripts: true,
			update: this.myTarget,
			onRequest: function(data) {
				this.myTarget.setHTML('<p class="error">Loading...</p>');
			}.bind(this),
			onFailure: function(data) {
				this.myTarget.setHTML('<p class="error">Could not load content.</p>');
			}.bind(this)
		}).request();
	},
	setMenu: function(item) {
		this.myMenuItems.each(function(myItem) {
			myItem.removeClass('on');
		});
		item.addClass('on');
	}	
});

window.addEvent('domready', function() {
	 var myContentLoader = new contentLoader('contentTarget','sectionMenu');
});

function updateDownloadLink(path) {
	if ($('shareDownloads')) {
		this.myDownload = $('shareDownloads').getElement('a');
		this.myDownload.href = path;
	}
}


