//============================================================================
// Global variables
var blank = new Image (1,1);
blank.src = "/blank.gif";


//============================================================================
// Turn visibility of an element on or off
function vOn(e) {
	if (browser=='IE') { e.style.visibility = 'visible'; }
	else if (browser=='NN') { e.style.visibility = 'show'; }
	else if (browser=='GECKO') { e.style.visibility = 'visible'; }
}

function vOff(e) {
	e.style.visibility = 'hidden';
}


//============================================================================
// Replace image node with spanned text node
function replaceImage(text) {
	parentID = "overlay_over";
	newID = "overlay_image";
	
	// Create a new span with the same ID as the old image
	// Create a text node and append it as a child to the new span.
	var newNode = document.createElement("div");
	newNode.id = newID;
	newNode.className = "wrap";
    var newText = document.createTextNode(text);
    newNode.appendChild(newText);

	// Parent node
    var parentNode = getID(parentID);
	// Child node
    var childNode = getID(newID);
	// Swap old/new span nodes
    var replaced = parentNode.replaceChild(newNode,childNode);
}


//============================================================================
// Replace text node with image node
function restoreImage(url) {
	parentID = "overlay_over";
	newID = "overlay_image"
	
	// Create a new span with the same ID as the old image
	// Create a text node and append it as a child to the new span.
	var newNode = document.createElement("img");
	newNode.id = newID;
	newNode.src = url;

	// Parent node
    var parentNode = getID(parentID);
	// Child node
    var childNode = getID(newID);
	// Swap old/new span nodes
    var replaced = parentNode.replaceChild(newNode,childNode);
}


//============================================================================
// Change text within span
function replaceSpan(text) {
	parentID = "wrap";
	newID = "image_span";
	
	// Create a new span with the same ID as the old span
	// Create a text node and append it as a child to the new span.
	var newNode = document.createElement("span");
	newNode.id = newID;
    var newText = document.createTextNode(text);
    newNode.appendChild(newText);

	// Parent node
    var parent = getID(parentID);
	// Child node
    var child = getID(newID);
	// Swap old/new span nodes
    var replaced = parent.replaceChild(newNode,child);
}




//============================================================================
//Dynamically create mouse events for the thumbnail divs
function create_thumbEvents(classname) {
	var div_list = document.getElementsByTagName('div');
	for (var i = 0; i < div_list.length; i++) {
		if ( div_list[i].className.match(eval('/^' + classname + '/')) ) {
			root = div_list[i];
			root.onmouseover = function() { vOn(this.childNodes[1]) };
			root.onmouseout = function() { vOff(this.childNodes[1]) };
		}
	}
}

//=================================================
// Local functions accessed through a common global interface
var classname = "thumb";

var local = new Object();		// Local object
local = {};
local.init = function() {
	create_thumbEvents(classname);
}

local.ajaxGetWaiting = function() {
	replaceImage('Downloading...');
}

local.ajaxGetDone = function() {
	restoreImage(current_url);
}