/* vim: set expandtab tabstop=4 shiftwidth=4: */

// +----------------------------------------------------------------------+
// | $Workfile: global.js $
// +----------------------------------------------------------------------+
// | Javascript v1.2                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2008 Bueche Studios                                    |
// +----------------------------------------------------------------------+
// | Author: Michael Bueche [mbueche@satx.rr.com]                         |
// +----------------------------------------------------------------------+

// $Header: /Consulting/BuecheStudios.com/Website/Version3/www/html/js/global.js 3     3/30/08 11:08p Engineer $

//-------------------------------------------------------------------------
/**
* This is the global Javascript function library that is included on every
* page.  It contains basic methods to get, set, and retrieve objects ad their
* properties in such a way that when used properly, they are browser independent
*
* @version		$Revision: 3 $
* @package		Library
* @author		Michael Bueche [mbueche@satx.rr.com]
* @since		1.2
* @see
*/
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
// Dependencies:
//				None
//-------------------------------------------------------------------------


/**
* Boolean value that stores weather or not the browser
* is Internet Explorer
*
* @var		boolean
*/
var $isIE = document.all ? true : false;

/**
* Boolean value that stores weather or not the browser
* is Netscape
*
* @var		boolean
*/
var $isNN = document.all ? false : true;

/**
* Changing this to true will alert errors when
* they are encountered.
*
* @var		boolean
*/
var $bolErrors	= true;


/**
* Changing this to true will alert warnings when
* they are encountered.
*
* @var		boolean
*/
var $bolWarnings = true;


/**
* Changing this to true will alert debug statements
* when they are encountered.
*
* @var		boolean
*/
var $bolDebug = false;



/**
* Gets an element using the DOM getElementBy[Name/Id] methods
* to retrieve an object. Returns false on failure to retieve
* the object by that Name/Id
*
* @access	public
* @author	Michael Bueche [michael.bueche@billingconcepts.com]
*
* @param	string	Object Name/Id
* @return	object on success, false on failure
*/
function $($strObjectId)
{
	// First Try to get the object by it's Id:
	if ( $obj = document.getElementById( $strObjectId ) )
	{
		return $obj;
	}
	// if warnings is turned on, alert the developer/user
	else if ( $bolDebug )
	{
		alert('The Object you specified: ' + $strObjectId + 	' does not exist');
	}

	return false;
}


/**
* Retrieves the value of the object passed.  returns false if the
* object can not be found or if the object does not have a value
* property
*
* @access	public
* @author	Michael Bueche [michael.bueche@billingconcepts.com]
*
* @param
* @return
*/
function $F($strObjecId)
{
	if ( $obj = $( $strObjectId ) )
	{
		if ( $obj.value || $obj.value == '' )
		{
			return $obj.value;
		}

		else if ( $bolWarnings )
		{
			alert(
				'This Object: ' + $strObjectId + 	' does not have a ' +
				'value property.  Please insure that you have the ' +
				'correct variable name;'
			);
		}
	}

	return false;
}


/**
* Sets the value of a form element if it has a
*
* @access	public
* @author	Michael Bueche [michael.bueche@billingconcepts.com]
*
* @param
* @return
*/
function fSetValue($strObjecId, $mixNewValue)
{
	if ( $obj = $( $strObjectId ) )
	{
		if ( $obj.value || $obj.value == '' )
		{
			$obj.value = $mixNewValue;
			return true;
		}

		else if ( $bolWarnings )
		{
			alert(
				'This Object: ' + $strObjectId + 	' does not have a ' +
				'value property.  Please insure that you have the ' +
				'correct variable name;'
			);
		}
	}

	return false;
}

/**
* Slides the content slider up or down
*
* @param	object $objReceiver
* @param	int $intIncrement
* @param	int $intInitialHeight
* @param	int $intMaxHeight
* @param	function $callback
* @return	void
*/
function fSlider( $objReceiver, $intIncrement, $intInitialHeight, $intMaxHeight, $callback )
{
	var $height = $intInitialHeight;

	function fResizeContainer()
	{
		$height = Number( $height ) + Number( $intIncrement );

		if ( $height < 0 )
		{
			$objReceiver.style.height = '0px';
			if ( $callback != null )
			{
				$callback();
			}
			return;
		}

		if ( $height > $intMaxHeight )
		{
			$objReceiver.style.height = $intMaxHeight + 'px';
			if ( $callback != null )
			{
				$callback();
			}

			if ( $( 'theGoods' ) )
			{
				$( 'theGoods' ).style.display = '';
			}

			return;
		}

		$objReceiver.style.height = $height+'px';
		setTimeout( fResizeContainer, 30 );
	}

	setTimeout( fResizeContainer, 30 );
}

/**
* Determines whether to slide the content up or down
*
* @param	object $objReceiver
* @param	function $callback
* @return	void
*/
function fToggleSlider( $objReceiver, $callback )
{
	$callback = $callback ? $callback : null;

	var $intIncrement = 25;
	var $intInitialHeight = 0;
	var $intMaxHeight = $objReceiver.getAttribute( 'maxHeight' );

	if ( !$intMaxHeight )
	{
		alert( 'NO MAX HEIGHT' );
		return;
	}

	if( $objReceiver.style.height == $intMaxHeight + 'px' )
	{
		$intIncrement = -25;
		$intInitialHeight = $intMaxHeight;
		fFadeToWhite();
	}

	fSlider( $objReceiver, $intIncrement, $intInitialHeight, $intMaxHeight, $callback );
}



/**
* Fades an Object to White in 5 steps
*
* @param	void
* @return	void
*/
function fFadeToWhite()
{
	var $opacity = 100;
	var $theObj  = $( 'theGoods' );

	function fFadeContainer()
	{
		$opacity = Number( $opacity ) - 20;

		if ( $opacity <= 0 )
		{
			$( 'theGoods' ).style.display = 'none';
			return;
		}

		fChangeOpacity( $theObj, $opacity );
		setTimeout( fFadeContainer, 30 );
	}

	setTimeout( fFadeContainer, 30 );
}

/**
* Changes the Opacity of an object
*
* @param	object $objToChange
* @param	integer $intOpacity (0 to 100)
* @return	void
*/
function fChangeOpacity( $objToChange, $intOpacity )
{
	if ( document.all )
	{
		$objToChange.filters.alpha.opacity	= $intOpacity;
	}
	else
	{
		$objToChange.style.MozOpacity = ( $intOpacity / 100 );
	}
}

// Navigation Functions:
function fGotoHome()		{ gotoPage( 'Home' );			}
function fGotoAboutMe()		{ gotoPage( 'AboutMe' );		}
function fGotoPortfolio()	{ gotoPage( 'Portfolio' );		}
function fGotoContact()		{ gotoPage( 'Contact' );		}
function fGotoClientLogin() { gotoPage( 'ClientLogin' );	}

/**
* Redirect to the appropriate Page
*
* @param	string $strPage
* @return	void
*/
function gotoPage( $strPage )
{
	window.location.href = 'index.php?Page=' + $strPage;
}