// This is the javascript file that goes with /index.jsp
var debug = false;
var verbose = false;

function initPage()
{
	// initializes HTML page
	if (debug && verbose) alert( "entering initPage" );

	// init focus

	// init images
	initImages( "imgRandomPhoto" );
	
	return true;
}

function initFocus( strElement )
{
	// accepts the ID of an element and attempts to make it the focus
	// if element does not exist or does not have a focus() method, ignores
	if (debug && verbose) alert( "entering initFocus" );
	
	var objExistingElement = document.getElementById(strElement);
	
	if ( objExistingElement )
	{
		if (debug && verbose) alert( "element found with ID [" + strElement + "]: " + objExistingElement );
		
		if ( objExistingElement.focus )
		{
			if (debug && verbose) alert( "element has focus() method - calling method immediately" );
			objExistingElement.focus();
		}
		else
		{
			if (debug) alert( "element does not have focus() method" );
		}
	}
	else
	{
		if (debug) alert( "no element found with ID [" + strElement + "]" );
	}
	
}

function initImages( strElement )
{
	if (debug && verbose) alert( "entering initImages" );
	
	var objExistingElement = document.getElementById(strElement);
	
	if ( objExistingElement )
	{
		if (debug && verbose) alert( "element found with ID [" + strElement + "]: " + objExistingElement );
		
		if ( objExistingElement.src )
		{
			if (debug && verbose) alert( "element has src property - setting to [" + randomPhoto + "]");
			objExistingElement.src = "/images/photo/" + randomPhoto();
		}
		else
		{
			if (debug) alert( "element does not have src property" );
		}
	}
	else
	{
		if (debug) alert( "no element found with ID [" + strElement + "]" );
	}
	
}

function randomPhoto()
{
	var imgPhotos = new Array("IMG_0087.JPG","IMG_0461.JPG","IMG_0480.JPG","IMG_0492.JPG");
	var randomIndex = ( Math.round( Math.random() * (imgPhotos.length - 1) ) );
	var randomPhoto = imgPhotos[randomIndex];
	
	if ( isPhotoTall(randomPhoto) ) changeDivTop("divOutro", 360);

	return randomPhoto;
}

function isPhotoTall( strPhoto )
{
	if ( strPhoto == "IMG_0461.JPG" )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function changeDivTop( strElement, iDisplace )
{
	if (debug && verbose) alert( "entering changeDivTop new" );
	
	var objExistingElement = document.getElementById(strElement);
	
	if ( objExistingElement )
	{
		if (debug && verbose) alert( "element found with ID [" + strElement + "]: " + objExistingElement );
		
		if ( objExistingElement.style )
		{
			if (debug && verbose) alert( "element has style property: " + objExistingElement.style);

			objExistingElement.style.posTop += iDisplace;
		}
		else
		{
			if (debug) alert( "element does not have style property" );
		}
	}
	else
	{
		if (debug) alert( "no element found with ID [" + strElement + "]" );
	}
}


