var gallery = {
		_events: [],
		_box: 0,
		_thumbs: [],
		_images: [],
		addLightBoxEvents: function(){
			//console.log("adding Lightboxes");
			gallery._thumbs = document.getElementById("thumbnail_list").getElementsByTagName("img");
			for(var i=0;i<gallery._thumbs.length;i++){
				var thisImage = gallery._thumbs[i];
				var image_properties = thisImage.parentNode.title.split("##");
				thisImage.id = i;
				gallery._events[i] = bbcjs.dom.addEventListener(thisImage,"click", gallery.show, thisImage);
				gallery._images.push({
					width:  (image_properties[1])? image_properties[1] : 400,
					height: (image_properties[2])? image_properties[2] : 267,
					description: (image_properties[0])? image_properties[0] : thisImage.alt,
					src: "/scotland/music/celticconnections/images/gallery/" + thisImage.parentNode.href.substr(thisImage.parentNode.href.indexOf("?")+1) + ".jpg"
				});
				//console.log(gallery._images.length + " in lightbox");
			}
		},
		addLightBoxEvent: function(){
			var main_image = document.getElementById("gallery_image").getElementsByTagName("img")[0];
			var p_tag = document.createElement("p");
			p_tag.appendChild(document.createTextNode("**CLICK ON IMAGE TO VIEW FULL SIZE**"));
			document.getElementById("gallery_image").insertBefore(p_tag, main_image);
			main_image.onclick = function(){
				var tempObj = Object();
				var img_temp = new Image();
				tempObj.src = this.src;
				img_temp.src = this.src;
				var maxWidth;
				if(document.body.clientWidth){
					maxWidth=document.body.clientWidth - 70;
				} else {
					maxWidth=document.documentElement.clientWidth - 70;
				}
				var maxHeight;
				if(document.body.clientHeight){
					maxHeight=document.body.clientHeight - 70;
				} else {
					maxHeight=document.documentElement.clientHeight - 70;
				}
				var ratio;
				if(img_temp.height > maxHeight){
					ratio = (maxHeight ) / img_temp.height;
					tempObj.width = img_temp.width * ratio;
					tempObj.height = img_temp.height * ratio;
				} else {
					tempObj.width = img_temp.width;
					tempObj.height = img_temp.height;
				}
				tempObj.description = document.getElementById("image_caption").innerHTML;
				gallery._box = new bbcjs.ui.LightBox([tempObj]);
				gallery._box.open();
			}
		},
		show: function(ev){
			var e = ev || window.event;
			//console.log("image " + this.id + " pressed");
			//console.log(gallery._images);
			gallery._box = new bbcjs.ui.LightBox(gallery._images);
			gallery._box.open(parseInt(this.id));
			bbcjs.dom.stopEvent(e);
		}
	};