function setup(){
	var lightArea = document.getElementById("lightbox-items");
	var links = lightArea.getElementsByTagName("a");
	var pics = lightArea.getElementsByTagName("img");
	
	// open it onclick
	for (var i=0; i<links.length; i++ ) {
		var sectionId = links[i].getAttribute("href");
		links[i].destination = sectionId;
		links[i].onclick = function() {			
			getContent(this.destination);
			return false;
		}
	}
}
function handleLoad(request){
	var responseData = request.text()
	var trimmedData = /<body>([\s\S]*)<\/body>/.exec(responseData)[1];
   	lightbox(trimmedData);
	return false;
}
function getContent(url){
	
	 var second = url.split("/christmas/")[1];
	 if (second != null){
	 var finalurl = "lb"+second;
	 }
	 else {
	 	finalurl = "lb"+url;
		}	
	bbcjs.http.get(finalurl, {onLoad:handleLoad} );
}
// create lightbox
function lightbox(contents){
	var recipeContent = contents;
	
	var myTemplate = '<div class="bbcjsUiLightBoxDefault" style="width:{width};height:{height}">' +
	'<a onclick="window.print()" href="#" class="recprint">Print</a>' +
	'<p><span id="bbcjsUiLightBoxClose" title="Return to main window"><a href="#" id="focushere">Close window</span></a></p>' + 
	'<img src="tiny.gif" width="{width}" height="1" alt="{description}" />'+
	'<div style="width:{width};height:{height}">{recipe}</div>' +
	'<div id="bbcjsUiLightBoxNext" title="Next">Forward &amp;gt;&amp;gt;</div>' +
	'<div id="bbcjsUiLightBoxPrevious" title="Previous">&amp;lt;&amp;lt; Back</div>' + 
	'</div>';		
	
	var myLightBox = new bbcjs.ui.LightBox([{
    width: '524', 
	height:'476',  
	recipe:recipeContent
	}], {
    maskColor: '#000000',
    maskOpacity: '25',
    borderWidth: 1,
    borderColor: '#45899b',
    closeBackground: '#ffffff',
	closeColor: '#414b51',
	template:myTemplate
	});
		
	myLightBox.open();
	document.getElementById("focushere").focus();
		
}
	

	
	

bbcjs.addOnLoadItem(setup);