var DownloadsServer		= 'http://downloads.bbc.co.uk';
var PlaylistServer		= 'http://www.bbc.co.uk';
var PlaylistDevServer	= 'http://scot-dev0.national.core.bbc.co.uk';
var SiteURL				= "/sandbox/";

// load an instance of glow
var glow;
var dom;
var $;
var events;
var anim;


gloader.load(["glow", "1", "glow.dom", "glow.anim", "glow.net", "glow.data", "glow.events", "glow.widgets.Carousel"], 
{
	async: true,
	onLoad: function(glowLocal)
	{
		glowLocal.ready(function()
		{

			glow = glowLocal;
			dom = glowLocal.dom;
			$ = glowLocal.dom.get;
			events = glowLocal.events;
			anim = glowLocal.anim;

			// set the var "pageID" to the pages body class
			var pageID = glow.dom.get('body').attr('id');
			
			// run a conditional statement on the var "pageID" 
			switch(pageID)
			{
				case 'feature':
					VideoSet.Initialise();
					break;
				default:
					break;
			}

			// Check to see if a timeline exists
//			if(glow.dom.get("#timeline").length > 0)
//			{
//				originalTimeline = glow.dom.get("#timeline-events").html();
//
//				glow.events.addListener("#timeline-tabs a", 'click', function(e){
//					e.preventDefault();
//
//					var theEra = glow.dom.get(this).parent().attr("class");
//					changeTimeline(theEra);
//				});
//			}

			// Check to see if a promo-row exists
			if(glow.dom.get(".promo-row").length > 0)
			{
				var promoMaxHeight = 0;
				var promoList = glow.dom.get(".promo-row .promo");
				
				// Loop through each promo to find the maximum height
				promoList.each(function(i){
					// in this function: this == myNodeList[i]
					var promoHeight = glow.dom.get(this).height();

					if(promoHeight > promoMaxHeight)
					{
						promoMaxHeight = promoHeight;
					}
				});

				// Apply the maximum height
				glow.dom.get(".promo-row .promo").height(promoMaxHeight);
			}
		});
	}
});

function changeTimeline(theEra)
{
	glow.dom.get("#timeline").attr("class", theEra);

	if (glow.dom.get("body").hasClass(theEra))
	{
		// Restore original HTML which has correct event highlighted
		glow.dom.get("#timeline-events").empty().append(originalTimeline);
	}
	else
	{
		// Load in file which contains list of events relating to the era
		glow.net.get("/scotland/history/demo/inc/" + theEra + ".ssi",
		{
			onLoad:function(response){
				glow.dom.get("#timeline-events").empty().append(response.text());
			},
			onError:function(){
			}
		});
	}
}