document.write("<style type='text/css'>#thephoto {visibility:hidden;}</style>");

var currentPhotoIndex = 0;
var firstPic = 0;

var transitionTime = 7 * 1000;
var imageWidth = 550;
var imageId = 'singleBanner';
var imageZIndex = 10;

function initImage() {
	if (document.getElementById)
	{
		image = document.getElementById(imageId);
	}
	image.style.zIndex = imageZIndex;
	image.style.width = imageWidth;
	setOpacity(image, 0);
	image.src = Photos[currentPhotoIndex];
	image.title = names[currentPhotoIndex];
	image.style.visiblity = "visible";

	if (photoCount == 1)
	{
		setOpacity(image, 100);
	}
	else
	{
		if (firstPic == 0)
		{
			setOpacity(image, 100);
			firstPic = 1;
		}
		else
		{
			fadeIn(imageId, 0);
		}
		window.setTimeout("fadeOut('" + imageId + "'," + 100 + ")", transitionTime);
	}
}

function fadeIn(objId, opacity)
{
	if (document.getElementById)
	{
		obj = document.getElementById(objId);
		if (opacity <= 100)
		{
			setOpacity(obj, opacity);
			opacity += 5;
			if (opacity < 50)
			{
				window.setTimeout("fadeIn('" + objId + "'," + opacity + ")", 70)
			}
			else
			{
				window.setTimeout("fadeIn('" + objId + "'," + opacity + ")", 40);
			}
		}
	}
}

function setOpacity(obj, opacity)
{
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

function fadeOut(objId, opacity)
{
   if (document.getElementById)
   {
      obj = document.getElementById(objId);
      if (opacity >= 0)
      {
         setOpacity(obj, opacity);
         opacity -= 5;
         if (opacity > 50)
         {
            window.setTimeout("fadeOut('" + objId + "'," + opacity + ")", 70);
         }
         else
         {
            window.setTimeout("fadeOut('" + objId + "'," + opacity + ")", 40);
         }
         if (opacity == 0)
         {
            window.setTimeout("", 50);
            changePictureSource();
         }
      }
   }
}

function nextPic()
{
   currentPhotoIndex = currentPhotoIndex + 1*1;
   if (currentPhotoIndex >= (photoCount))
   {
      currentPhotoIndex = 0;
   }   
   changePictureSourceManually(currentPhotoIndex);
}

function prevPic()
{
   currentPhotoIndex = currentPhotoIndex - 1*1;
   if (currentPhotoIndex < 0)
   {
      currentPhotoIndex = (photoCount - 1);
   }
   changePictureSourceManually(currentPhotoIndex);
}


function changePictureSourceManually(index)
{
   currentPhotoIndex = index;

   image = document.getElementById(imageId);
   image.src = Photos[currentPhotoIndex];
   image.style.zIndex = imageZIndex;
   image.style.width = imageWidth;
   setOpacity(image, 100);

   image.title = names[currentPhotoIndex];
   image.style.visiblity = "visible";

   setOpacity(image, 100);
   window.setTimeout("", transitionTime);
}

function changePictureSource()
{
   if (currentPhotoIndex < (photoCount - 1))
   {
      currentPhotoIndex++;
   }
   else
   {
      currentPhotoIndex = 0;
   }
   initImage();
}

function clickLink()
{
   var photoIndex = currentPhotoIndex;
   if (url[photoIndex] != '')
   {
      location.href = url[photoIndex];
   }
}

window.onload = function()
{
   initImage();
}