if (top.location != self.location){top.location = self.location;}

var isIE = document.all ? true : false;

var defHght = 840;
var defWdth = 800;

var tblMain = null;
var cellMain = null;

var imgHold = null;
var imgMain = null;
var imgFade = null;
	
var browserDetect = '';

var baseopacity = 0;

var aImages = document.images;
var aGallery = new Array();
var j = aGallery.length;

//imgMain.onmouseover = function () { imageOver(this) };
//imgMain.onmouseout = function () { imageOut(this) };
//imgFade.onmouseover = function () { imageOver(this) };
//imgFade.onmouseout = function () { imageOut(this) };

var aGallery = new Array();
var j = aGallery.length;
var imageRoot = 'http://www.philhathcock.com/images/';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'pillars.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_0058.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_0332.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'ascent.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_0501.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_0573.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'fountain.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_0660.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_0951.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'balance.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1160.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1328.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1371.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1467.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1528.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'boomer.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1544.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1693.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1698.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1799.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'crescent.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1805.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'inflight.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1829.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'DSC_1066.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1849.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1856.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_0060.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_0456.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1162.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1267.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1278.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1329.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1432.jpg';
aGallery[j] = new Image;
aGallery[j++].src = imageRoot + 'IMG_1912.jpg';
var imageHold = false;
var imageTimer = '';
var highlightTimer = 0;
var imageCurrent = 0;

function slideShow ()
{
	highlightTimer++;
	if (highlightTimer > 100)
	{
		if (highlightTimer == 101)
		{
			resetFade();
			setFade();		
		}
		
		if ( browserDetect == 'mozilla' )
		{
			if ( imgFade.style.MozOpacity < 1 )
			{
				imgFade.style.MozOpacity = parseFloat(imgFade.style.MozOpacity) + 0.1;
			}
			else
			{
				setMain();
			}
		}
		else if ( browserDetect == 'ie' )
		{
			if ( imgFade.filters.alpha.opacity < 100 )
			{
				imgFade.filters.alpha.opacity += 10;
			}
			else
			{
				setMain();
			}
		}
	}
}

function setMain () 
{		
		
	var selectImage = aGallery[imageCurrent];
	var imgDimensions = getDimensions(selectImage);

	imgMain.style.left = ( getPageLeft(imgHold) - imgDimensions.w/2 ) + 'px';
	imgMain.height = imgDimensions.h;
	imgMain.width = imgDimensions.w;
	imgMain.src = selectImage.src;
	
	imageCurrent++;
	if ( imageCurrent == aGallery.length )
		imageCurrent = 0;

	highlightTimer = 0;
}

function resetFade ()
{
	if ( browserDetect == 'mozilla' )
		imgFade.style.MozOpacity = baseopacity/100;
	else if ( browserDetect == 'ie' )
		imgFade.filters.alpha.opacity = baseopacity;
}

function setFade ( imageName ) 
{
	var selectImage = aGallery[imageCurrent];
	var imgDimensions = getDimensions(selectImage);

	imgFade.style.left = ( getPageLeft(imgHold) - imgDimensions.w/2 ) + 'px';
	imgFade.height = imgDimensions.h;
	imgFade.width = imgDimensions.w;
	imgFade.src = selectImage.src;
}

function resizeMain()
{
	tblMain = document.getElementById('mainContentTable');
	cellMain = document.getElementById('mainImageCell');
	
	imgHold = document.getElementById('imageHold');
	imgMain = document.getElementById('imageMain');
	imgFade = document.getElementById('imageFade');
	imgMain.style.visibility = 'hidden';

	browserDetect = imgFade.filters ? 'ie' : typeof imgFade.style.MozOpacity == 'string' ? 'mozilla' : '';
	
	var bWdth,bHght;
			
	cellMain.style.fontSize = '1px';
	
	// all except Explorer
	if ( self.innerHeight ) 
	{
		bHght = self.innerHeight;
		bWdth = self.innerWidth;
	}
	// Explorer 6 Strict Mode
	else 
	if ( document.documentElement && document.documentElement.clientHeight )
	{
		bHght = document.documentElement.clientHeight;
		bWdth = document.documentElement.clientWidth;
	}
	// other Explorers
	else if ( document.body ) 
	{
		bHght = document.body.clientHeight;
		bWdth = document.body.clientWidth;
	}
	
	bHght = Math.min(bHght,970);
	bWdth = Math.min(bWdth,980);
	
	//the following is trying to adjust for scroll bars and chrome but is not working depending on if window is maximized or not
	bHght -= ( isIE ) ? 140 : 10;
	
	tblMain.style.height = bHght + 'px';
	tblMain.style.width = bWdth + 'px';
	
	if ( typeof document.getElementById('imageFade').src == 'string' )
	{
		imgMain.style.top = getPageTop(imgHold) + 'px';
		imgFade.style.top = getPageTop(imgHold) + 'px';
		setMain();
		setFade();
		imgMain.style.visibility = 'visible';
		imageTimer = setInterval( 'slideShow()', 80);
	}
	//document.getElementById('statusCell').innerHTML = 'self.innerHeight=' + self.innerHeight + '<br>' + 'document.documentElement.clientHeight=' + document.documentElement.clientHeight + '<br>' + 'bHght=' + bHght;
}


function imageOver (image)
{
	if ( window.highlightTimer ) 
		clearInterval(highlightTimer);
	resetFade();
	imageHold = true;
}

function imageOut (image)
{
	resetFade();
	imageHold = false;
	slideShow();
}

function getImage ( filename )
{
	for ( var i = 0; i < aGallery.length; i++ )
	{
		if ( aGallery[i].src.indexOf(filename) != -1 )
			return aGallery[i];
	}
	return null;
}

function getDimensions ( imgObj )
{
	// Default dimensions of slideshow box
	var display_height = Math.min(cellMain.clientHeight, defHght);
	var display_width = Math.min(cellMain.clientWidth, defWdth);

	// Ensure the slide fits inside the slideshow box
	if ( (imgObj.width / imgObj.height) > (display_width / display_height) )
		// Slide is too wide for box, so adjust its height
		display_height = (display_width / imgObj.width) * imgObj.height;
	else
		// Slide is too high for box, so adjust its width
		display_width = (display_height / imgObj.height) * imgObj.width;
		
	return {w : display_width, h : display_height};
}

function getPageLeft (obj) 
{
	var left = 0;
	do
		left += obj.offsetLeft;
	while ( (obj = obj.offsetParent) );
	return left;
}

function getPageTop (obj) 
{
	var top = 0;
	do
		top += obj.offsetTop;
	while ( (obj = obj.offsetParent) );
	return top;
}