
// escape HTML function
function escapeHtml(unsafe) {
	return unsafe
		.replace("&", "&amp;")
		.replace("<", "&lt;")
		.replace(">", "&gt;")
		.replace("\"", "&quot;")
		.replace("'", "&#039;");
}

// define Showcase class
function Showcase() {

	this.items = showcaseItems;

	var self = this;
	
	// create showcase
	$("#showcaseContainer").html(
			"<div id=\"networkShowcase\">" +
//				"<img/>" +
				"<p class=\"description\"></p>" +
				"<p class=\"link\"><a class=\"_seeMoreLink\" target=\"_blank\">Visit</a></p>" +
				"<ul/><a target=\"_blank\" />" +
				"<div>sites »</div>" +
			"</div>"
	);

	// add in the buttons
	var first = true;
	$.each(this.items, function(id, item) {
		
		// preload background
		var img = new Image();
		img.src = "/images/showcase/bg-"+id+".png";
		self.images[id] = img;
		
		// make button
		var buttonClass = "button_"+id;
		$("#networkShowcase ul").append(
				"<li class=\""+buttonClass+"\">" +
					"<img src=\"/images/division-icons/"+id+".png\" />" +
				"</li>"
		);
		
		// on hover over button, switch to item
		$("#networkShowcase li."+buttonClass).hover(function() {
			self.switchTo(id);
		});

	});
	
	this.switchTo(showcaseInit);
	
	$("showcaseContainer > p.loading").remove();
	
}
Showcase.prototype = {
		images: [],
		items: null,
		switchTo: function(id) {
	
			var item = this.items[id];
			var showcase = $("#networkShowcase");
			
			// set content
			showcase.find("p.description").html(item.description);
			$("#networkShowcase p.link a, #networkShowcase > a")
				.attr("href", item.url)
				.attr("title", "Visit " + item.title);
			showcase.find("p.description").css("color", "#"+item.textColour);
			showcase.find(" > img").remove();
			showcase.prepend(this.images[id]);
			
			
			// switch buttons
			showcase.find("li").removeClass("active");
			showcase.find("li.button_"+item.id).addClass("active");
		}
}

// actual page code
var showcase; 
$(document).ready(function() {
	
	showcase = new Showcase();
	
});


