function insertPrintLink(text) {
    var printHTML = "<div class=\"pageTools\"><a href=\"#\" onclick=\"print(); return(false);\">" + text + "</a></div>";
    document.write(printHTML);
}

function handleDropDowns(e) {
    if (document.all) trg = window.event.srcElement;
    else trg = e.target;

    if(trg.nodeName != "BODY" && trg.nodeName != "HTML") {
        if(hasClass(trg.parentNode.parentNode, "pageNavigation") && hasClass(trg.parentNode.parentNode.parentNode, "pageNavigation")) {
            if(hasClass(trg, "current") || hasClass(trg.parentNode, "current")) {
                closeDropDowns();
				replaceClass(trg.parentNode.parentNode, "closed", "opened");
                return false;
            }
        }
        else {
            closeDropDowns();
        }
    }
    else {
        closeDropDowns();
    }
}

function closeDropDowns() {
    var openedDropDowns = getElementsByClassName("opened");
    for(i=0; i<openedDropDowns.length; i++) {
        replaceClass(openedDropDowns[i], "opened", "closed");
    }
}

OnLoadHandler.appendFunction("activateDropDowns()", true);
function activateDropDowns() {
    var dropDownCandidates = getElementsByClassName("pageNavigation");
    if (dropDownCandidates.length > 0) {
        document.onclick = handleDropDowns;
        if (document.captureEvents) document.captureEvents(Event.CLICK);
        for (i=0; i<dropDownCandidates.length; i++) {
            replaceClass(dropDownCandidates[i], "pageNavigation", "pageNavigationContainer");
            addClass(dropDownCandidates[i].getElementsByTagName("UL")[0], "pageNavigation");
            addClass(dropDownCandidates[i].getElementsByTagName("UL")[0], "closed");
			
			
			// Create a "shadow" of the current element to be shown in the list when opening the dropdown
			liElems = dropDownCandidates[i].getElementsByTagName("li");
			var shadowLi = document.createElement("li");
			shadowLi.innerHTML = liElems[0].innerHTML;
			shadowLi.className = "shadow";
			liElems[0].parentNode.insertBefore(shadowLi, liElems[1]);
			
        }
    }
}

function viewLargeVersion(url, thumbnailId, text) {
    largeImagePlaceHolder = document.getElementById("largeImage");
    largeImagePlaceHolderWidth = largeImagePlaceHolder.parentNode.style.width;
    largeImageCaption = document.getElementById("largeText");
    thumbNailImage = document.getElementById(thumbnailId);
    largeImagePlaceHolder.src = thumbNailImage.src;
    largeImagePlaceHolder.src = url;
    largeImageCaption.innerHTML = text;
    largeImagePlaceHolder.style.width = largeImagePlaceHolderWidth;
}


