if(!window.WWWROOT) window.WWWROOT = "/mskcc/"
if(!window.RESOURCES) window.RESOURCES = "/mskcc_resources/"

/*************** CACHE IMAGE ***************/
var imageCache = new Object()
function cacheImage(ID, onSrc, offSrc){
	imageCache[ID] = new Object()
	imageCache[ID].on = new Image()	
	imageCache[ID].on.src = onSrc
	if(offSrc){
		imageCache[ID].off = new Image()	
		imageCache[ID].off.src = offSrc
	}
}

/*************** CACHE NAVIGATION IMAGE CACHE ***************/
var _staging = false
function createNavigationImageCache(){
	var WWWROOT = arguments[0]
	for(var i=1;i<arguments.length;i++){
		var ID = arguments[i];
		cacheImage("n" + ID, 
			WWWROOT + "_assets/navigation-on/" + ((_staging)?"_staging/":"") +  ID + ".gif", 
			WWWROOT + "_assets/navigation-off/" + ((_staging)?"_staging/":"") +  ID + ".gif"
		)
	}
}

/*************** CACHE TOOLS ***************/
function cacheTools(color, tools){
	color = color || "blue";
	tools = tools || ["appointment", "www_gateway", "newsletter"];
	for(var i=0;i<tools.length;i++){
		cacheImage(tools[i], 
			RESOURCES + "images/tools/on/" + color + "/" + tools[i] + ".gif", 
			RESOURCES + "images/tools/off/" + color + "/" + tools[i] + ".gif"
		)
	}
}

/*************** CACHE TOOLS ***************/
function cachePageTools(){
	var tools = ["look_up_terms", "plus", "minus", "close_terms"];
	for(var i=0;i<tools.length;i++){
		cacheImage(tools[i], 
			RESOURCES + "images/tools/on/" + tools[i] + ".gif", 
			RESOURCES + "images/tools/off/" + tools[i] + ".gif"
		)
	}
}
cachePageTools();

/*************** IMAGE ON ***************/
function imageOn(ID, statusMessage){
	if(!document.images[ID] || !imageCache[ID]) return 

	checkAndCacheOffImage(ID)

	document.images[ID].src = imageCache[ID].on.src
	if(statusMessage) window.status = statusMessage
	return true
}

/*************** CHECK AND CACHE OFF IMAGE ***************/
function checkAndCacheOffImage(ID){
	if(imageCache[ID].off) return 

	imageCache[ID].off = new Image()	
	imageCache[ID].off.src = document.images[ID].src
}

/*************** IMAGE OFF ***************/
function imageOff(ID){
	if(!document.images[ID] || !imageCache[ID]) return 

	document.images[ID].src = imageCache[ID].off.src
	window.status = ''
	return true
}

/*************** FIRST NAV ON ***************/
function firstNavOn(element){
	element.style.backgroundColor = "#718DBB"
	element.style.backgroundImage = "url(/mskcc_resources/images/navigation/first/on.gif)"
}

/*************** FIRST NAV OFF ***************/
function firstNavOff(element, bgcolor){
	element.style.backgroundColor = bgcolor || "#BDAF61"
	element.style.backgroundImage = "url(/mskcc_resources/images/navigation/first/off.gif)"
}

