var AnimationTickCount = 0;
var CurrentTick = 0;
var AnimationMultiplier = 9;
var intervalGrow;
var intervalShrink;
var month = 0;
var initialized = false;

function ShowAlbums(Month)
{
	month = Month;
	Resize();
}

function ShowFullSize(ImageId, AlbumId)
{
	var winW = 630, winH = 460;

	if (parseInt(navigator.appVersion) > 3) 
	{
		if (navigator.appName=="Netscape") 
		{
			winW = window.innerWidth - 18;
			winH = window.innerHeight + scrollMaxY;
		}
		if (navigator.appName.indexOf("Microsoft") > -1) 
		{
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	
	document.getElementById('ModalPopup').style.backgroundColor = "gray";
	document.getElementById('ModalPopup').style.filter = "alpha(opacity=70)";
	document.getElementById('ModalPopup').style.opacity = "0.7";
	document.getElementById('ModalPopup').style.width = winW + "px";
	document.getElementById('ModalPopup').style.height = winH + "px";
	document.getElementById('ModalPopup').style.zIndex = "1000";
	document.getElementById('ModalPopup').style.position = "absolute";
	document.getElementById('ModalPopup').style.top = "0px";
	document.getElementById('ModalPopup').style.left = "0px";
	document.getElementById('ModalPopup').style.textAlign = "center";
	document.getElementById('ModalPopup').style.display = "";
	document.getElementById('ModalPopupImage').innerHTML = Gallery.GetFullSizeImage(ImageId, AlbumId).value;
	document.getElementById('ModalPopupImage').style.display = "";
	document.getElementById('tableModalPopupImage').style.display = "";
	document.getElementById('ModalPopupImage').innerHTML = document.getElementById('ModalPopupImage').innerHTML;
	
	var browserName = navigator.userAgent.toLowerCase();
	var browserVersion = parseInt(navigator.appVersion);
	if (navigator.userAgent.toLowerCase().indexOf("msie 6") >= 0)
	{
		document.getElementById('ModalPopupImage').style.width = winW;
		document.getElementById('ModalPopupImage').style.height = winH;
		document.getElementById('ModalPopupImage').style.paddingTop = "100px";
	}
}

function HideFullSize()
{
	document.getElementById('ModalPopup').style.display = "none";
	document.getElementById('ModalPopupImage').style.display = "none";
	document.getElementById('tableModalPopupImage').style.display = "none";
}

function DrawAlbums()
{
	var MonthsToDisplay = parseInt(document.getElementById('MonthsToDisplay').value);
	var CurrentAlbum = parseInt(document.getElementById('CurrentAlbum').value);
	var CurrentImage = parseInt(document.getElementById('CurrentImage').value);
	var CurrentMonth = parseInt(month);
	document.getElementById('MonthTabs').innerHTML = Gallery.GetMonthTabs(CurrentMonth, MonthsToDisplay).value;
	var GalleryHtml = Gallery.GetAlbums(month, CurrentAlbum, CurrentImage).value;
	document.getElementById('CurrentAlbum').value = parseInt(GalleryHtml.substring(0,GalleryHtml.indexOf('|')));
	var start = GalleryHtml.indexOf('|') + 1;
	GalleryHtml = GalleryHtml.substring(start, GalleryHtml.length - start);
	document.getElementById('PhotoGalleryData').innerHTML = GalleryHtml;
	document.getElementById('tableModalPopupImage').style.display = "none";
	Animate();
}

function Resize()
{	
	if (initialized == true)
	{
		if (document.getElementById('ActivePanel') != null)
		{
			var timerlen = 1;
			var FinalHeight = 26;
			CurrentTick = parseInt(document.getElementById('ActivePanel').style.height.replace(/px/,""));
			AnimationTickCount = FinalHeight;
			document.getElementById('ActivePanel').style.overflow = "hidden";
			document.getElementById('PhotoThumbnail').style.overflow = "hidden";
			document.getElementById('PhotoThumbnail').style.display = "none";
			intervalShrink = setInterval('PerformShrinkAnimation();', timerlen);
		}
	}
	else
	{
		DrawAlbums();
		initialized = true;
	}
}

function Animate()
{
	if (document.getElementById('ActivePanel') != null)
	{
		var timerlen = 1;
		var MaxHeight = parseInt(document.getElementById('ActivePanel').style.height.replace(/px/,""));
		if (parseInt(document.getElementById('PhotoThumbnail').style.height.replace(/px/,"")) > MaxHeight)
		{
			MaxHeight = parseInt(document.getElementById('PhotoThumbnail').style.height.replace(/px/,""));
		}
		MaxHeight = MaxHeight + 10;
		document.getElementById('PhotoThumbnail').style.height = "";
		AnimationTickCount = MaxHeight;
		document.getElementById('ActivePanel').style.height = "28px";
		document.getElementById('ActivePanel').style.overflow = "hidden";
		document.getElementById('PhotoThumbnail').style.overflow = "hidden";
		intervalGrow = setInterval('PerformAnimation();', timerlen);
	}
}

function PerformShrinkAnimation()
{
	if (CurrentTick < AnimationTickCount)
	{
		clearInterval(intervalShrink);
		DrawAlbums();
		CurrentTick = 0;
	}
	else
	{
		document.getElementById('ActivePanel').style.height = CurrentTick + "px";
		CurrentTick = CurrentTick - (1 * AnimationMultiplier);
	}
}

function PerformAnimation()
{
	if (CurrentTick > (AnimationTickCount / AnimationMultiplier))
	{
		CurrentTick = 0;
		clearInterval(intervalGrow);
		document.getElementById('PhotoThumbnail').style.display = "";
	}
	else
	{	
		CurrentTick = CurrentTick + 1;
		document.getElementById('ActivePanel').style.height = (CurrentTick * AnimationMultiplier) + "px";
	}
}

function SetCurrentMonth(Month)
{
	document.getElementById('CurrentMonth').value = Month.toString();
	document.getElementById('CurrentAlbum').value = '0';
	initialized = false;
	clearInterval(intervalGrow);
	clearInterval(intervalShrink);
	document.getElementById('CurrentImage').value = "0";
	ShowAlbums(Month);	
	initialized = true;
}

function ShowThumbnail(AlbumId, ImageId)
{
	var CurrentAlbum = parseInt(document.getElementById('CurrentAlbum').value);
	var CurrentMonth = parseInt(document.getElementById('CurrentMonth').value);
	document.getElementById('CurrentAlbum').value = AlbumId;
	document.getElementById('CurrentImage').value = ImageId;
	if (CurrentAlbum != AlbumId)
	{
		ShowAlbums(CurrentMonth);
	}
	else
	{
		document.getElementById('tdPhotoThumbnail').innerHTML = Gallery.GetThumbnail(ImageId, AlbumId).value;
	}
}
