(function() {
	var glow,
		enclosure,
		contents,
		controls,
		inputs;
	
	// Modifiables
	var rdns = "drugreport", // namespace
		latest = 1; // first one
	
	// Constants
	var D = {
		content: ".rd-content",
		controls: ".rd-controls",
		main: ".rd-switcher",
		label: ".rd-label"
	};
	var labelswitch = false;
	
	if (typeof(gloader) == 'undefined') {
		return;
	}
	
	gloader.load(
	["glow", "1", "glow.dom", "glow.events"],
	{
		async: false,
		onLoad: function(fetchedGlow) {
			glow = fetchedGlow;
			glow.ready(init);
		}
	});
	
function init() {
	enclosure = glow.dom.get("div#rd-" + rdns);
	contents = enclosure.get(D.content).get("img");
	contents.css("display", "none");
	controls = glow.dom.get(D.controls);
	inputs = controls.get("input");
	
	
	enclosure.get(D.controls).css("display", "block");
	glow.dom.get(contents[latest - 1]).css("display", "block");
	enclosure.get(D.controls).children().filter(function() {
		return (glow.dom.get(this).is("input") && glow.lang.trim(glow.dom.get(this).attr("type")) == "radio");
	}).each(function(i) {
		if (i == latest - 1) {
			this.checked = "checked";
		}
	});
	
	enclosure.get(D.controls).children().filter(function() {
		return (glow.dom.get(this).is("input") && glow.lang.trim(glow.dom.get(this).attr("type")) == "radio");
	}).each(function(i) {
		var context = {elm: glow.dom.get(this), index: i};
		glow.events.addListener(
			this,
			"click",
			trigger,
			context
		);
	});

}

function trigger() {
	var context = this;
	contents.each(function(i) {
		if (i == context.index) {
			this.style.display = "block";
		} else {
			this.style.display = "none";
		}
	});
}

})();