// a function to change the content of the show case viewer

var currentShowCase = 0

function updateShowCaseContent(itemInArray) {

	currentShowCase = itemInArray

	// add info to right column 
	var storeInfo = "<h2>" 
	storeInfo += showcases[itemInArray]['storeName']
	storeInfo += "</h2>" 
	storeInfo += "<p>" 
	storeInfo += showcases[itemInArray]['description']
	storeInfo += "</p>" 
	storeInfo += showcases[itemInArray]['templateInfo']

	// add visit button
	storeInfo += "<a href=\"http://"+ showcases[itemInArray]['storeHandle'] +".enstore.com\" id=\"visit-showcase\">"
	storeInfo += "<span class=\"left\"></span><span class=\"right\"></span>"
	storeInfo += "Visit "+ showcases[itemInArray]['storeName'] +"</a>"
	
	$("#showcase-information").hide();
	$("#showcase-information").html(storeInfo);
	$("#showcase-information").fadeIn();
	$("#page_button_"+itemInArray+"").addClass("active")

	var screenshot = mediaURL + "/site/main/showcases/" + showcases[itemInArray]['storeHandle'] + ".gif"

	$(function () {

		var img = new Image();

		$(img).load(function () {
			$(this).css('display', 'none');
			$('#showcase-screenshot').html(this);
			$(this).fadeIn();
		}).error(function () {
			// notify the user that the image could not be loaded
		}).attr('src', screenshot);
	});

}

function changeShowCase(newShowCase) {
		
	if (currentShowCase != newShowCase)
	{
		$(".showcase-container").fadeOut("fast", function(){
			$("#page_button_"+currentShowCase+"").removeClass("active")
			$("#showcase-screenshot").html("")
			$("#showcase-information").html("")
			$(this).show();
			updateShowCaseContent(newShowCase)
		
		})
	}
	
}

$(document).ready(function() {

	// Shuffle the order of the array
	var i = showcases.length;

	while (--i) {
		j = Math.floor(Math.random() * (i + 1));
		temp = showcases[i];
		showcases[i] = showcases[j];
		showcases[j] = temp;
	}
	
	// first store
	updateShowCaseContent(0);
	
	// create pagination
	var pagination = ""
	for (i=0;i<showcases.length;i++)
	{
		if (i == 0) {
			pagination += "<div class=\"pagination-button active\" onClick=\"changeShowCase("+i+")\" id=\"page_button_"+i+"\">&nbsp;</div>"
		} else {
			pagination += "<div class=\"pagination-button\" onClick=\"changeShowCase("+i+")\" id=\"page_button_"+i+"\">&nbsp;</div>"
		}
	}
	// add pagination to DOM
	$("#showcase-pagination").html(pagination);
	
});





// the show cases
var showcases = [
	{
		"storeHandle": "ohnodoom",
		"storeName": "OhNo!Doom",
		"description": "Oh No! Doom is a Chicago artist collective and carries a wide range of beautiful artwork. The team consists of designers, illustrators and plush artists and they operate a local store in Bucktown. Each month their web store is updated with a new artist’s work.",
		"templateInfo": "<li><b>Template: </b>Custom Template</li><li><b>Based on: </b>Asphalt</li>"
	},
	{
		"storeHandle": "buro",
		"storeName": "BURO",
		"description": "From iPods and iMacs, to the latest set of hip headphones and swanky covers for digital devices BURO offers the coolest gear to make most of where, and how you work and play.",
		"templateInfo": "<li><b>Template: </b>Custom Template</li><li><b>Based on: </b>Alpine</li>"
	},
	{
		"storeHandle" : "cookerystore",
		"storeName" : "The Cookery Store",
		"description" : "The Cookery Store is the web store of the Ashburton Cookery School. Because the Cookery School is often asked where to find the equipment they use, they set up a web store for everyone to order specialist equipment.",
		"templateInfo" : "<li><b>Template: </b>Custom Template</li><li><b>Based on: </b>Raconteurs</li>"
	},
	{
		"storeHandle" : "tmgsilver",
		"storeName" : "Tammy Gilchrest",
		"description" : "Tammy Gilchrest is a smith who works with metalsmithing, chainmaille and PMC (precious metal clay) to create jewelry. One of the techniques she uses is called Viking Knitting and she also teaches all of the techniques she uses.",
		"templateInfo" : "<li><b>Template: </b>Hawaii</li>"
	},
	{
		"storeHandle" : "joemamma",
		"storeName" : "Joe Mamma",
		"description" : "Whether you’re looking for a pretty bike or in need of biking accessoires, go to Joe Mamma Cycles’ web store. This Canadian bike shop sells BMX bikes and fixed gear, along with shoes and DVDs.",
		"templateInfo" : "<li><b>Template: </b>Custom Template</li><li><b>Based on: </b>Asphalt</li>"
	},
	{
		"storeHandle" : "brewstock",
		"storeName" : "Brewstock",
		"description" : "Brewstock’s owner Aaron Hyde is a very dedicated homebrewer who provides other homebrewers with everything they need to make their own special beer, wine and cheese. You can also buy his own homemade products, like yogurt and cheese.",
		"templateInfo" : "<li><b>Template: </b>Marley </li>"
	},
	{
		"storeHandle" : "sweetpea",
		"storeName" : "Sweetpea",
		"description" : "Sweetpea Wholesome Baby’s Web Store is an organic, eco-friendly baby store that focuses on sustainability. The store offers its customers colorful, stylish and durable products, ranging from baby books and blankets to maternity wear and baby carriers.",
		"templateInfo" : "<li><b>Template: </b>Bishop </li>"
	},
	{
		"storeHandle" : "wbbasics",
		"storeName" : "Well Balanced Basics",
		"description" : "The web store of Well Balanced Basics provides its customers with a wide range of nutritional and wellness products. Based in Camarillo, California their store offers powders, gels, tablets, capsules, foods and oils to live a healthier and balanced life.",
		"templateInfo" : "<li><b>Template: </b>Custom Template</li><li><b>Based on: </b>Hawaii</li>"
	},
	{
		"storeHandle" : "rikstoet",
		"storeName" : "Rik Stoet High End Audio",
		"description" : "Rik Stoet High End Audio sells audio products and complete audio solutions. Thanks to their 15 years of experience, they can provide a wide range of amplifiers, speakers, turntables and audio accessoires from many brands. ",
		"templateInfo" : "<li><b>Template: </b>Raconteurs </li>"
	},
	{
		"storeHandle" : "tecgadgets",
		"storeName" : "Tec Gadgets",
		"description" : "Accessoires and decals for your Mac, iPod, iPhone or iPad are available at TecGadgets. They are a Germany-based web store and carry a range of handy accessoires that make the use of your Apple device even more pleasant.",
		"templateInfo" : "<li><b>Template: </b>Custom Template</li><li><b>Based on: </b>Raconteurs</li>"
	},
	{
		"storeHandle" : "meeniegreenie",
		"storeName" : "One Green Street",
		"description" : "Founded by Sherry Eichberger, One Green Street sells only eco-friendly products. Whether you need clothing, make-up or pillows, One Green Street has it. The store was founded in order to offer the public healthier alternatives of everyday products.",
		"templateInfo" : "<li><b>Template: </b>Raconteurs </li>"
	}
];


