/*****************************************************************************
 *
 * File     : buttons.js
 * 
 * Project  : Whistler
 * 
 * Contents : Buttons logic
 *
 * Author: 
 *
 * Copyright 2007 Whistler Info
 * http://www.whistlerinfo.ca
 * All rights reserved.
 * 
 ***|***************************|***********************|*******************|*/

/************************************************************************
*
*	function:	onMouseDown
*
*	purpose:	
*
*************************************************************************/
function onMouseDown(theButton)
{
	var state = theButton.className;
	if (state == "buttonInflated") newState = "buttonEngaged";
	else if (state == "buttonSelectedInflated") newState = "buttonSelectedEngaged";
	else return;
	theButton.className = newState;
}

/************************************************************************
*
*	function:	onMouseUp
*
*	purpose:	
*
*************************************************************************/
function onMouseUp(theButton)
{
	var state = theButton.className;
	if (state == "buttonEngaged") 
	{
		newState = "buttonSelectedInflated";
		buttonPressed(theButton);
	}
	else if (state == "buttonSelectedEngaged") newState = "buttonSelectedInflated";
	else return;
	theButton.className = newState;
}

/************************************************************************
*
*	function:	onMouseOver
*
*	purpose:	
*
*************************************************************************/
function onMouseOver(theButton)
{
	var state = theButton.className;
	if (state == "button") newState = "buttonInflated";
	else if (state == "buttonSelected") newState = "buttonSelectedInflated";
	else return;
	theButton.className = newState;
}

/************************************************************************
*
*	function:	onMouseOut
*
*	purpose:	
*
*************************************************************************/
function onMouseOut(theButton)
{
	var state = theButton.className;
	if (state == "buttonInflated") newState = "button";
	else if (state == "buttonEngaged") newState = "button";
	else if (state == "buttonSelectedInflated") newState = "buttonSelected";
	else if (state == "buttonSelectedEngaged") newState = "buttonSelected";
	else return;
	theButton.className = newState;
}

/************************************************************************
*
*	function:	buttonPressed
*
*	purpose:	
*
*************************************************************************/
function buttonPressed(theButton)
{
	var toolbar = theButton.parentNode;
	var buttons = toolbar.childNodes;
	for (var index = 0; index < buttons.length; index++)
	{
		var aChild = buttons.item(index);
		if (aChild.tagName == null) continue;
		if (aChild.tagName.toLowerCase() != "span") continue;
		if (aChild.className.indexOf("button") != 0) continue;
		if (aChild == theButton) continue;
		aChild.className = "button";
		buttonDepressed(aChild);
	}
	theButton.className = "buttonSelected";
	handleButtonPressed(theButton);
}

/************************************************************************
*
*	function:	buttonDepressed
*
*	purpose:	
*
*************************************************************************/
function buttonDepressed(theButton)
{
	handleButtonDepressed(theButton);
}

/************************************************************************
*
*	function:	handleButtonPressed
*
*	purpose:	
*
*************************************************************************/
function handleButtonPressed(theButton)
{
	if (theButton.id == "mapButton") switchToMap();
	else if (theButton.id == "photoButton") switchToPhoto();
	
	var currentId = _currentPhotoId.innerHTML;
	var thumb = document.getElementById(currentId);
	var images = thumb.getElementsByTagName("img");
	for (var index = 0; index < images.length; index++)
	{
		var anImage = images.item(index);
		if (anImage.className == "thumb") break;
	}
	display(anImage);
}

/************************************************************************
*
*	function:	handleButtonDepressed
*
*	purpose:	
*
*************************************************************************/
function handleButtonDepressed(theButton)
{
}


