/**
 * Featured Site Randomizer
 *
 * @author			Barry Malcolm Harley
 * @version			1.0.0
 * @copyright		Copyright (c) 2011 ZootAlore! Creative
 */
 
/**
 * Load the randomizer
 *
 * @author 	Barry Malcolm Harley
 * @return 	void
 */
$(function() {
	randomSite();
});	
 
/**
 * Select a random site from a JSON array and print in a container
 *
 * @author 	Barry Malcolm Harley
 * @return 	void
 */
function randomSite() 
{
	// pull a list of text blocks from the JSON array
	$.getJSON('/static/js/featured-sites.json', 
		function(data)
		{
			// get random text block
			featuredSite = data.sites[Math.floor(Math.random()*data.sites.length)];
			// get a reference to the container element
			var siteContainer = document.getElementById("random-site");
			
			// print text block
			printSite(siteContainer, featuredSite);
		}
	);
}

/**
 * Print some featured site in a containing element
 *
 * @author 	Barry Malcolm Harley
 * @param	DOM object
 * @param	Object
 * @return 	void
 */

function printSite(container, site)
{
	var markup = '<a href="' + site.link + '">';
	markup += '<img id="screenshot" src="/static/img/global/footer/featured_sites/' + site.screenshot + '" alt="' + site.name + '" class="left" width="136px" height="86px" /></a>';
	markup += '<h3 class="dark_highlight underline_link"><a href="' + site.link+ '">' + site.name + '</a></h3>';
	markup += site.description + ' <a href="' + site.link + '">(Read More)</a>';
	// print to container
	container.innerHTML = markup;
}
