jQuery(document).ready(function() {
	$(".token").hover(
			function () {
		        $(this).children(".thumb").addClass("thumb_on");
		        $(this).children(".thumb_info,.thumb_controls").stop().fadeTo(300, 1);
		      }, 
		      function () {
				    $(this).children(".thumb").removeClass("thumb_on");
			    $(this).children(".thumb_info,.thumb_controls").stop().fadeTo(300, 0);
		      }
	)
});

var showThumbControlArray = [];

function showThumbControls(thumbNum) {
	thumbNode = document.getElementById("thumb_" + thumbNum);
	thumbChildren = thumbNode.childNodes;
	showThumbControl = showThumbControlArray[thumbNum];
	showThumbControl = (showThumbControl == undefined) ? false : showThumbControl;
	for (var i=0; i < thumbChildren.length; i++) {
		currNode = thumbChildren[i];
		currClassName = currNode.className;
		if (currClassName == "thumb" || currClassName == "thumb_on") {
			image = currNode.getElementsByTagName("img")[0];
			controls = currNode.getElementsByTagName("div")[0];
			currNode.className = showThumbControl ? "thumb" : "thumb_on";
			if (image != null) {
			    image.style.display = showThumbControl ? "block" : "none";
			}
			controls.style.display = showThumbControl ? "none" : "block";
		} else if (currClassName == "thumb_info" || currClassName == "thumb_info_on") {
			currNode.className = showThumbControl ? "thumb_info" : "thumb_info_on";
		}
	}
	showThumbControlArray[thumbNum] = !showThumbControl;
}

function highlightThumb(thumb) {
	thumbChildren = thumb.childNodes;
	for (var i=0; i < thumbChildren.length; i++) {
		currNode = thumbChildren[i];
		currClassName = currNode.className;
		if (currClassName == "thumb") {
			currNode.className = "thumb_on";
		}
	}
}

function unhighlightThumb(thumb) {
	thumbChildren = thumb.childNodes;
	for (var i=0; i < thumbChildren.length; i++) {
		currNode = thumbChildren[i];
		currClassName = currNode.className;
		if (currClassName == "thumb_on") {
			currNode.className = "thumb";
		}
	}
}

function popUp(pop_url, winname, windowWidth, windowHeight, resizable, scrollbars, menubar, toolbar) {
	var windowOpts = "";
	windowOpts += (windowWidth != null) ? "width="+windowWidth : "";
	windowOpts += (windowHeight != null) ? ",height="+windowHeight : "";
	windowOpts += (resizable != null) ? ",resizable="+resizable : "";
	windowOpts += (scrollbars != null) ? ",scrollbars="+scrollbars : "";
	windowOpts += (menubar != null) ? ",menubar="+menubar : "";
	windowOpts += (menubar != null) ? ",toolbar="+toolbar : "";
	if (windowOpts.length > 0) {
    	window.open(pop_url,winname,windowOpts);
    } else {
    	window.open(pop_url,winname);
    }
}

function popUpToken(url, tokenID, width, height) { //launches pop up window
    popUp(url, tokenID, width, height, "no", "no", "no", "no")
}

function newWin (link) {
    window.open(link.href);
    return false;
}
