function findPosX(obj)
{
	var curleft = 0;
	if( obj.offsetParent )
	{
		while( obj.offsetParent )
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if( obj.x )
	{
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if( obj.offsetParent )
	{
		while( obj.offsetParent )
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if( obj.y )
	{
		curtop += obj.y;
	}
	return curtop;
}

function getViewportWidth()
{
	var viewportwidth;
	var viewportheight;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	
	if(typeof window.innerWidth != "undefined" )
	{
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if( typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0 )
	{
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	// older versions of IE
	else
	{
		viewportwidth = document.getElementsByTagName("body")[0].clientWidth;
		viewportheight = document.getElementsByTagName("body")[0].clientHeight;
	}
	return viewportwidth;
}

function getViewportHeight()
{
	var viewportwidth;
	var viewportheight;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	
	if(typeof window.innerWidth != "undefined" )
	{
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if( typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0 )
	{
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	// older versions of IE
	else
	{
		viewportwidth = document.getElementsByTagName("body")[0].clientWidth;
		viewportheight = document.getElementsByTagName("body")[0].clientHeight;
	}
	return viewportheight;
}

function getScrollLeft()
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof(window.pageYOffset) == "number" )
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else if( document.body && (document.body.scrollLeft || document.body.scrollTop ))
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if( document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop ))
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return scrOfX;
}

function getScrollTop()
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof(window.pageYOffset) == "number" )
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else if( document.body && (document.body.scrollLeft || document.body.scrollTop ))
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if( document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop ))
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return scrOfY;
}

function initSuckerfishDropDown()
{
	if( document.all && document.getElementById )
	{
		var NavRoot = document.getElementById('SuckerFishDropDown');
		if( typeof(NavRoot) != 'undefined' )
		{
			for( i=0; i < NavRoot.childNodes.length; i++ )
			{
				var Node = NavRoot.childNodes[i];
				if( Node.nodeName == 'LI' )
				{
					Node.onmouseover = function()
					{
						this.className += ' over';
					}
					Node.onmouseout = function()
					{
						this.className = this.className.replace(' over','');
					}
				}
			}
		}
	}
}

function updateShadows()
{
	var ShadowLeft = document.getElementById('shadowleft');
	var ShadowRight = document.getElementById('shadowright');
	var ShadowLogo = document.getElementById('shadowlogo');
	var PowerDesigns = document.getElementById('powerdesigns');
	var Site = document.getElementById('site');
	var WindowWidth = document.body.clientWidth;
	var PhotoDisplay = document.getElementById('photodisplay');
	
	if( typeof(Site) == 'undefined' )
	{
		alert('Site undefined');
		return;
	}
	
	// ShadowLeft
	if( typeof(ShadowLeft) != 'undefined' )
	{
		// Position left shadow
		if( WindowWidth < 820 )
		{
			ShadowLeft.style.display = 'none';
			Site.style.borderLeft = '1px solid #C0C0C0';
		}
		else
		{
			Site.style.borderLeft = '0px';
			ShadowLeft.style.left = (findPosX(Site)-10) + 'px';
			ShadowLeft.style.height = parseInt(Site.offsetHeight) + 'px';
			ShadowLeft.style.display = 'block';
		}
	}
	
	// ShadowRight
	if( typeof(ShadowRight) != 'undefined' )
	{
		// Position left shadow
		if( WindowWidth < 820 )
		{
			ShadowRight.style.display = 'none';
			Site.style.borderRight = '1px solid #C0C0C0';
		}
		else
		{
			Site.style.borderRight = '0px';
			ShadowRight.style.left = (findPosX(Site)+800) + 'px';
			ShadowRight.style.height = parseInt(Site.offsetHeight) + 'px';
			ShadowRight.style.display = 'block';
		}
	}
	
	// ShadowLogo
	if( typeof(ShadowLogo) != 'undefined' )
	{
		ShadowLogo.style.left = (parseInt(Site.offsetLeft)+23) + 'px';
		ShadowLogo.style.display = 'block';
	}
	
	if( typeof(PowerDesigns) != 'undefined' )
	{
		if( WindowWidth < 900 )
		{
			PowerDesigns.style.display = 'none';
		}
		else
		{
			PowerDesigns.style.left = (findPosX(Site)+800) + 'px';
			PowerDesigns.style.top = (parseInt(Site.offsetHeight)-166) + 'px';
			PowerDesigns.style.display = 'block';
		}
	}

	if( PhotoDisplay != null )
	{
		PhotoDisplay.style.width = WindowWidth + 'px';
		PhotoDisplay.style.height = parseInt(Site.offsetHeight) + 'px';
	}
}

var ContentPageRightColumnHeight = -1;

function updateContentPageHeight()
{
	var ContentPage = document.getElementById('contentpage');
	var LeftColumn = document.getElementById('leftcolumn');
	var RightColumn = document.getElementById('rightcolumn');
	var Site = document.getElementById('site');
	var Menu = document.getElementById('menu');
	var Topbar = document.getElementById('topbar');
	
	var ShowSponsor = false;
	
	if( ContentPage != null )
	{	
		if( ContentPageRightColumnHeight == -1 )
		{
			ContentPageRightColumnHeight = RightColumn.offsetHeight;
			ShowSponsor = true;
		}
		var RightColumnHeight = (getViewportHeight()-findPosY(ContentPage)-29-36);
		if( RightColumnHeight < LeftColumn.offsetHeight-17 )
		{
			RightColumnHeight = LeftColumn.offsetHeight-17;
			if( RightColumnHeight < ContentPageRightColumnHeight )
			{
				RightColumnHeight = ContentPageRightColumnHeight;
			}
			RightColumn.style.height = RightColumnHeight + "px";
		}
		else if( RightColumn.style.height == "" )
		{
			if( RightColumn.offsetHeight < RightColumnHeight )
			{
				RightColumn.style.height = RightColumnHeight + "px";
			}
			else
			{
				RightColumn.style.height = RightColumn.offsetHeight+150 + "px";
			}
		}
		else
		{
			if( ContentPageRightColumnHeight > RightColumnHeight )
			{
				RightColumn.style.height = ContentPageRightColumnHeight+150 + "px";
			}
			else
			{
				RightColumn.style.height = RightColumnHeight + "px";
			}
		}
		
		if( ShowSponsor == true )
		{
			document.getElementById('sponsor').style.display = 'block';
			ShowSponsor = false;
		}
	}
}

var PhotoListingArray = Array();
var PhotoListingCurrent = 0;
var PhotoListingPreloader = null;
var PhotoListingTitle = "";
var PhotoHolderLeft = 0;
var PhotoHolderTop = 0;

function openPhotoListing(Title,PhotoArray,StartIndex)
{
	var PhotoDisplay = document.getElementById('photodisplay');
	var ImageHolder = document.getElementById('photodisplayimageholder');
	var Image = document.getElementById('photodisplayimage');
	var WindowWidth = getViewportWidth();
	var WindowHeight = getViewportHeight();
	
	var ControlLeft = document.getElementById('photodisplaycontrolleft');
	var ControlRight = document.getElementById('photodisplaycontrolright');
	var PhotoDisplayTitle = document.getElementById('photodisplaytitle');
	
	if(( PhotoDisplay == null ) || ( ImageHolder == null ) || ( Image == null ))
	{
		return;
	}
	
	if( isNaN(StartIndex) )
	{
		StartIndex = 0;
	}
	
	PhotoListingArray = PhotoArray;
	PhotoListingCurrent = StartIndex;
	PhotoListingTitle = Title;
	
	if( PhotoListingArray.length > 1 )
	{
		ControlLeft.style.display = 'inline';
		ControlRight.style.display = 'inline';
	}
	else
	{
		ControlLeft.style.display = 'none';
		ControlRight.style.display = 'none';
	}
	
	Image.src = "img/photoloading.jpg";
	ImageHolder.style.left = (parseInt((WindowWidth-200)/2)+getScrollLeft()) + "px";
	ImageHolder.style.top = (parseInt((WindowHeight-50)/2)+getScrollTop()) + "px";
	PhotoDisplay.style.display = 'block';
	ImageHolder.style.display = 'block';
	displayPhoto(PhotoListingCurrent);
}

function previousPhoto()
{
	PhotoListingCurrent--;
	if( PhotoListingCurrent < 0 )
	{
		PhotoListingCurrent = PhotoListingArray.length-1;
	}
	displayPhoto(PhotoListingCurrent);
}

function nextPhoto()
{
	PhotoListingCurrent++;
	if( PhotoListingCurrent >= PhotoListingArray.length )
	{
		PhotoListingCurrent = 0;
	}
	displayPhoto(PhotoListingCurrent);
}

function displayPhoto(Index)
{
	var PhotoDisplayTitle = document.getElementById('photodisplaytitle');
	var PhotoDisplayDescription = document.getElementById('photodisplaydescription');
	
	var Title = PhotoListingArray[Index][1];
	if( Title.length == 0 )
	{
		Title = PhotoListingTitle;
	}
	
	if( PhotoListingArray.length > 1 )
	{
		PhotoDisplayTitle.innerHTML = Title + " (" + (PhotoListingCurrent+1) + "/" + PhotoListingArray.length + ")";
	}
	else
	{
		PhotoDisplayTitle.innerHTML = Title;
	}
	
	PhotoDisplayDescription.innerHTML = PhotoListingArray[Index][2];
	
	PhotoListingPreloader = new Image();
	PhotoListingPreloader.onload = openPhotoLoaded;
	PhotoListingPreloader.src = PhotoListingArray[Index][0];
}

function closePhoto()
{
	var PhotoDisplay = document.getElementById('photodisplay');
	var ImageHolder = document.getElementById('photodisplayimageholder');
	var Image = document.getElementById('photodisplayimage');
	
	if(( PhotoDisplay == null ) || ( ImageHolder == null ))
	{
		return;
	}
	
	PhotoDisplay.style.display = 'none';
	ImageHolder.style.display = 'none';
	Image.src = "img/photoloading.jpg";
	Image.style.width = "200px";
	Image.style.height = "50px";
}

function openPhotoLoaded()
{
	var Image = document.getElementById('photodisplayimage');
	updatePhotoHolderPosition()
	Image.src = PhotoListingPreloader.src;
}

function updatePhotoHolderPosition()
{
	var Image = document.getElementById('photodisplayimage');
	var ImageHolder = document.getElementById('photodisplayimageholder');
	
	if( ImageHolder.style.display != "block" )
	{
		return;
	}
	var WindowWidth = getViewportWidth();
	var WindowHeight = getViewportHeight();
	var ImageWidth = parseInt(PhotoListingPreloader.width);
	var ImageHeight = parseInt(PhotoListingPreloader.height);
	var Propotion = ImageWidth/ImageHeight;
	var NewWidth,NewHeight,Factor;
	
	if( ImageWidth > ImageHeight )
	{
		if( ImageWidth > 500 )
		{
			Factor = ImageWidth/500;
			NewWidth = 500;
			NewHeight = ImageHeight/Factor;
		}
		else
		{
			NewWidth = ImageWidth;
			NewHeight = ImageHeight;
		}
	}
	else
	{
		if( ImageHeight > 500 )
		{
			Factor = ImageHeight/500;
			NewHeight = 500;
			NewWidth = ImageWidth/Factor;
		}
		else
		{
			NewWidth = ImageWidth;
			NewHeight = ImageHeight;
		}
	}
	
	Image.style.width = NewWidth + "px";
	Image.style.height = NewHeight + "px";
	
	var HolderLeft = parseInt((WindowWidth-NewWidth)/2);
	var HolderTop = parseInt((WindowHeight-parseInt(ImageHolder.offsetHeight))/2);
	
	if( HolderLeft < 0 )
	{
		HolderLeft = 0;
	}
	if( HolderTop < 0 )
	{
		HolderTop = 0;
	}
	
	PhotoHolderLeft = HolderLeft;
	PhotoHolderTop = HolderTop;
	
	
	ImageHolder.style.width = NewWidth + "px";
	
	ImageHolder.style.left = (PhotoHolderLeft+getScrollLeft()) + "px";
	ImageHolder.style.top = (PhotoHolderTop+getScrollTop()) + "px";
}

var YearList_CurrentYearObject = null;
var YearList_Default_Open_Year = 0;

function yearListOpen(Year)
{
	if( YearList_CurrentYearObject != null )
	{
		YearList_CurrentYearObject.style.display = 'none';
	}
	
	var Object = document.getElementById('YearList_' + Year);
	
	if( Object != null )
	{
		Object.style.display = 'block';
		YearList_CurrentYearObject = Object;
	}
}

function yearListLoad()
{
	var CurrentDate = new Date();
	var CurrentYear = parseInt(CurrentDate.getFullYear());
	
	var CurrentYearObject = document.getElementById('YearList_' + CurrentYear);
	
	while( CurrentYearObject != null )
	{
		if( CurrentYear != YearList_Default_Open_Year )
		{
			CurrentYearObject.style.display = 'none';
		}
		else
		{
			CurrentYearObject.style.display = 'block';
			YearList_CurrentYearObject = CurrentYearObject;
		}
		CurrentYear--;
		CurrentYearObject = document.getElementById('YearList_' + CurrentYear);
	}
}

function sdftLoad()
{
	// Initialize suckerfish dropdown
	initSuckerfishDropDown();
	
	updateContentPageHeight();
	
	// Place and show shadows
	updateShadows();
	
	yearListLoad();
}

function sdftResize()
{
	updatePhotoHolderPosition();
	
	updateContentPageHeight();
	
	// Update shadows
	updateShadows();
}

window.onload = sdftLoad;
window.onresize = sdftResize;
window.onscroll = updatePhotoHolderPosition;