function prepareGallery() {
		
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	
	if (!document.getElementById("gallery_thumbnails")) return false;
	
	var gallery = document.getElementById("gallery_thumbnails");
	var links = gallery.getElementsByTagName("a");
		
	for (var i=0; i < links.length; i++) {
		links[i].onclick = function() {
			return showPic(this);
		}
		links[i].onkeypress = links[i].onclick;
	}

	showPic(links[0]);

}

function showPic(whichpic) {
	
	if (!document.getElementById("gallery_image")) return false;
	if (!document.getElementById("gallery_caption")) return false;
	
	var newsource = whichpic.getAttribute("href");
	var placeholder = document.getElementById("gallery_image");
		
	placeholder.setAttribute("src", newsource);
	
	if (whichpic.getAttribute("title")) {
		var newdescription = whichpic.getAttribute("title");
	} else {
		var newdescription = "";
	}
	
	var description = document.getElementById("gallery_caption");
	if (description.firstChild.nodeType == 3) {
		description.firstChild.nodeValue = newdescription;
	}
	
	return false;
	
}


function tab(selected_tab) {

	   var live = document.getElementById("gallery_live"); 
//	   var promo = document.getElementById("gallery_promo");
	   var tour = document.getElementById("gallery_tour");		
//	   var fanart = document.getElementById("gallery_fanart");
	   var video = document.getElementById("gallery_video");		

	   if (selected_tab=="live") 	{ live.className = "live_select"; } 		else { live.className = "live"; }
//	   if (selected_tab=="promo") 	{ promo.className = "promo_select"; } 		else { promo.className = "promo"; }
	   if (selected_tab=="tour") 	{ tour.className = "tour_select"; } 		else { tour.className = "tour"; }
//	   if (selected_tab=="fanart") 	{ fanart.className = "fanart_select"; } 	else { fanart.className = "fanart"; }
	   if (selected_tab=="video") 	{ video.className = "video_select"; } 		else { video.className = "video"; }

}

function getPage(div, id, position){

        var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }

        var file = 'ajax/thumbs.php?id=' + id + '&pos=' + position;

        xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
        xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data

                var content = xmlhttp.responseText; //The content data which has been retrieved ***

                if( content ){ //Make sure there is something in the content variable

                document.getElementById(div).innerHTML = content;  //Change the inner content of your div to the newly retrieved content ****
				prepareGallery();
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}



function addLoadEvent(func) {
	
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
	
}

addLoadEvent(prepareGallery);
