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

var isIE = document.all ? true : false;

var tblMain = null;
var cellMain = null;

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

var baseopacity = 0;
var highlightTimer = '';

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

for ( var i=0; i < aImages.length; i++ )
{
	if ( aImages[i].className == 'imageThumbnail' )
	{
		aImages[i].onmouseover = function () { imageOver(this) };
		aImages[i].onmouseout = function () { imageOut(this) };
		
		aGallery[j] = new Image;
		aGallery[j].src = aImages[i].src.replace('_tn','');
		aGallery[j].title = aImages[i].title;
		aGallery[j].alt = aImages[i].alt;
		j++;
	}
}

function resizeMain()
{
	tblMain = document.getElementById('mainContentTable');
	cellMain = document.getElementById('mainContentCell');
	
	imgMain = document.getElementById('imageMain');
	imgFade = document.getElementById('imageFade');
	imgHold = document.getElementById('imageHold');
	
	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';
		setImage(imgMain.src);
		imgMain.style.visibility = 'visible';
	}
	//document.getElementById('statusCell').innerHTML = 'self.innerHeight=' + self.innerHeight + '<br>' + 'document.documentElement.clientHeight=' + document.documentElement.clientHeight + '<br>' + 'bHght=' + bHght;
}

function setFade ( imageName ) 
{
	var selectImage = getImage(imageName);
	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;
	//divInfo.innerHTML = selectImage.alt;
}

function setImage ( imageName ) 
{
	var selectImage = getImage(imageName);
	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;
}

function gradualFade ()
{
	if ( browserDetect == 'mozilla' )
	{
		if ( imgFade.style.MozOpacity < 1 )
			imgFade.style.MozOpacity = parseFloat(imgFade.style.MozOpacity) + 0.1;
		else
		{
			setImage(imgFade.src);
			clearTimer();
		}
	}
	else if ( browserDetect == 'ie' )
	{
		if ( imgFade.filters.alpha.opacity < 100 )
			imgFade.filters.alpha.opacity += 10;
		else
		{
			setImage(imgFade.src);
			clearTimer();
		}
	}
	else 
		clearTimer();
}

function imageOver ( image )
{
	image.className = 'imageHover';
	setFade(image.src.replace('_tn',''));
	resetFade();
	highlightTimer = setInterval('gradualFade()',50);
}

function imageOut ( image )
{
	image.className = 'imageThumbnail';
	clearTimer();
	resetFade();
}

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

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

	// 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 getImage ( filename )
{
	for ( i = 0; i < aGallery.length; i++ )
	{
		if ( aGallery[i].src.indexOf(filename) != -1 )
			return aGallery[i];
	}
	return null;
}

function clearTimer ()
{
	if ( window.highlightTimer ) 
		clearInterval(highlightTimer);
}

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;
}

