function load()
{
    colourGalleryLink();
}

function colourGalleryLink()
{
    var file_name = document.location.href;
    var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
    var file = file_name.substring(file_name.lastIndexOf("/")+1, end);
    
    var links = document.getElementsByTagName('a')
    var gal = getGallery();
        
    for (i=0; i<links.length; i++)
    {
	if (unescape(links[i].innerHTML) == unescape(gal) && links[i].getAttribute("rel") == "galleryLink")
	{
	    links[i].style.color = "white";
	    links[i].style.background = "black";
	}
    }
}

function clicker(gallery, image, alt)
{    
    var thediv=document.getElementById('displaybox');
    var darken=document.getElementById('darkenBG');
    
    if(thediv.style.display == "none")
    {
	thediv.style.display = "";
	darken.style.display = "";
	
	thediv.style.top = (coords()+50)+"px";  //set the top of the pop-up div to be 50px below the top of the screen
	
	thediv.innerHTML = "<img src='images/galleries/" + gallery + "/" + image + "' alt=\"" + alt + "\" class=\"large\" /><br /><p class=\"largeImageCaption\">" + alt + "</p><div class=\"closebox\" onclick='return clicker();'></div>";
    }
    else
    {
	thediv.style.display = "none";
	darken.style.display = "none";
	thediv.innerHTML = "";
    }
    return false;
}

function getGallery()
{    
    var query = window.location.search.substring(1);
    var params = query.split('&');
    for (var i=0; i<params.length; i++)
    {
	var pos = params[i].indexOf('=');
	if (pos > 0)
	{
	    var key = params[i].substring(0,pos);
	    var val = params[i].substring(pos+1);
	    if (key == "gallery")
	    {
		return val;
	    }
	}
    }
}

// gets how far down the page is scrolled
function coords()
{
    var coords;

    if(/msie/i.test(navigator.userAgent))
    {
	coords = document.documentElement.scrollTop;
    }
    else
    {
	coords = window.pageYOffset;
    }
	
    return coords;
}