/* vim: set expandtab tabstop=4 shiftwidth=4: */

// +----------------------------------------------------------------------+
// | $Workfile: index.js $
// +----------------------------------------------------------------------+
// | Javascript 1.5                                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2007 Bueche Studios                                    |
// +----------------------------------------------------------------------+
// | @Author: Michael Bueche <mbueche@satx.rr.com>				          |
// +----------------------------------------------------------------------+

// $Header: /Consulting/Diamante Homes/www.diamantehomes.com/www/html/js/index.js 2     12/08/08 12:51a Engineer $

/**
* Rotates the Main Image every 3 seconds
*
* @param
* @return
*/
var img = document.getElementById( 'indexImage' );
var intNext;

function rotateMainImage()
{
	var arrImg = img.src.split( '_' );
	var intImg = parseInt( arrImg[2].replace( '.jpg', '' ) );

	if ( intImg < 4  )
	{
		intNext = ++intImg;
	}
	else
	{
		intNext = 1;
	}

	var temp = new Image();
	temp.src = "images/index_main_" + padWithZero( intNext ) + '.jpg';

	setTimeout( changeImage, 2000 );
}

function changeImage()
{
	intAmount = 100;

	function fade()
	{
		if ( intAmount == 0 )
		{
			img.src = "/images/index_main_" + padWithZero( intNext ) + '.jpg';
			setTimeout( fadein, 100 );
		}
		else
		{
			intAmount -= 10;
			fChangeOpacity( intAmount );
			setTimeout( fade, 100 );
		}
	}

	function fadein()
	{
		if ( intAmount == 100 )
		{
			setTimeout( rotateMainImage, 2000 );
		}
		else
		{
			intAmount += 10;
			fChangeOpacity( intAmount );
			setTimeout( fadein, 100 );
		}
	}

	setTimeout( fade, 500 );
}


function fChangeOpacity( $intOpacity )
{
	if ( document.all )
	{
		img.style.filter = 'alpha(opacity=' + $intOpacity + ')';
		// img.filters.alpha.opacity = $intOpacity;
	}
	else
	{
		img.style.MozOpacity = ( $intOpacity/100 );
	}
}


function padWithZero( n )
{
	n = parseInt( n );

	if ( n < 9 )
	{
		return '0' + n;
	}

	return n;
}