
window.onload = function() {  afterLoad('TheDeck');  }
document.onmousemove = mouseMove;

var itemDescription = '123';
var TouchingSomething = 0;
var ShowThisDiv = 'nada';
var wItem;
var itemCount = 0;

function mouseMove(ev){
	ev = ev || window.event;
	var mousePos = mouseCoords(ev);
	if (TouchingSomething) {
			itemDescription.style.top = mousePos.y + 15;
			itemDescription.style.left = mousePos.x + 15;
	}
}

function mouseCoords(ev){
	if ( ev.pageX || ev.pageY ) {
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}

var FunctionLock = 0;
function NoOverLap(selectedDiv) {
	if (FunctionLock) {
		setTimeOut(NoOverLap(selectedDiv),200);
	} else {
		FunctionLock = 1;
		loopOverDivs(selectedDiv);
	}
}

// Cross-browser support
function returnObjById(id)  { 
    if (document.getElementById) { var returnVar = document.getElementById(id); }
	else if (document.all) { var returnVar = document.all[id]; }
	else if (document.layers) { var returnVar = document.layers[id]; }
    return returnVar; 
}

// If any cross-browser support is found it will be added here
function returnObjByTagName(id) {
	var returnVar = contentDiv.getElementsByTagName(id);
	return returnVar; 
}

// This positions the Divs, sets top and left, and zIndex
function loopOverDivs(selectedDiv) {
	if (FunctionLock) {
		setTimeOut(loopOverDivs(selectedDiv),200);
	} else {
		if (event.type == 'mouseover') {
			TouchingSomething = 1;
			itemDescriptionID = selectedDiv + 'Text';
			itemDescription = returnObjById(itemDescriptionID);
			itemDescription.className = "VisibleDiv";
			itemDescription.style.zIndex = 11;
		} else if (event.type == 'mouseout') {
			TouchingSomething = 0;
			itemDescriptionID = selectedDiv + 'Text';
			itemDescription = returnObjById(itemDescriptionID);
			itemDescription.className = "InvisibleDiv";
			itemDescription.style.zIndex = 0;
		}
		FunctionLock = 1;
		CurrentTop = 150;
		CurrentLeft = 25;
		CurrentOrder = 1;
		for (var i = 0; i < allContainedElements.length; i++) {
			var elem = allContainedElements[i];
			elem.style.top = CurrentTop + 'px';
			elem.style.left = CurrentLeft + 'px';
			elem.style.zIndex = CurrentOrder;
			CurrentOrder++;
			if ((event.type == 'mouseover') && (elem.id == selectedDiv)) {
				CurrentTop += 200;
				CurrentLeft += 100;
				//elem.style.width = 390;
				//elem.style.height = 490;
			} else if ((event.type == 'mouseout') && (elem.id == selectedDiv)) {
				//elem.style.width = 300;
				//elem.style.height = 400;
			} else {
				CurrentTop += 25;
				CurrentLeft += 50;
			}
		}
		FunctionLock = 0;
	}
}

function increaseSize() {
	for (var i = 0; i < allImages.length; i++) {
		var elem = allImages[i];
		var oldWidth = elem.width;
		var newWidth = ((oldWidth / 100) * 125);
		elem.width = newWidth;
	}
}

function decreaseSize() {
	for (var i = 0; i < allImages.length; i++) {
		var elem = allImages[i];
		var oldWidth = elem.width;
		var newWidth = ((oldWidth / 100) * 75);
		elem.width = newWidth;
	}
}


function select(selectedDiv) {
	var thediv = returnObjById(selectedDiv);
	if (thediv.className == 'CardMO') { thediv.className = 'Card'; }  else if (thediv.className == 'Card') { thediv.className = 'CardMO'; }
	loopOverDivs(selectedDiv);
}

function afterLoad(selectedDiv) {
	if (itemCount != 7) {
		setTimeOut(afterLoad(selectedDiv),200);
	}  else {
		contentDiv = returnObjById("TheDeck"); 
		allContainedElements = returnObjByTagName("DIV");
		allImages = returnObjByTagName("IMG");
		loopOverDivs(selectedDiv);
	}
}

function upDateCount() {
	itemCount++;
}

function changeZindex(selectedDiv) {
	loopOverDivs(selectedDiv);
	var thediv = returnObjById(selectedDiv);
	thediv.style.zIndex = 10;
}
