function sharpRedirect(){
    var getSharpId = new String(location);
    var urlLength = getSharpId.length;
    var sharpIndex = getSharpId.indexOf("#");
    if (sharpIndex > -1) {
        sharp = getSharpId.slice(sharpIndex - urlLength + 1);
        if(sharp != getSharpId)
        {
	        var menuElement = document.getElementById("secondMenu_" + sharp).firstChild;
	        if (menuElement) {
	            var onclickStr = menuElement.onclick;
	            onclickStr = onclickStr.toString();
	            
	            var startIndex = onclickStr.indexOf("Discovery");
	            //alert(startIndex);
	            var title = onclickStr.substring(startIndex, onclickStr.length - 5);
	        }
	        openClose(menuElement, sharp, title);
        }
    }
	setLinks();
}


function watch(){
    if (oldLocation != location) {
        oldLocation = location.toString();
        sharpRedirect();
        randomImg();
    }
    var time = setTimeout("watch()", 500);
}

var lock = false;
var oldLocation = location.toString();
watch();

function openClose(element, id, title){ //alert(activeId);
    if (document.getElementById("active_contentMenu")) {
        document.getElementById("active_contentMenu").id = "";
    }
    element.id = "active_contentMenu";
    document.getElementById("content_" + activeId).className = "mid-content-ajax";
    document.getElementById("content_" + id).className = "mid-content-ajax_active";
    activeId = id;
    
    document.title = title;
    if (!lock) {
        randomImg();
        lock = true;
    }
}


function setLinks(){
	var printLink;
	var emailLink;
	printLink = document.getElementById("print_" + activeId).value;
	emailLink = document.getElementById("email_" + activeId).value;
	document.getElementById("print_page").innerHTML = printLink;
	document.getElementById("email_page").innerHTML = emailLink;
	
}

