var imagecount = 0;
var bigimages = new Array(20);
var boolimage = false;
var currentimg = 0;
var newWindow=true;

function openWindow(imgName,W,H,features){

	newWindow=window.open(imgName,'name','width='+W+',height='+H+','+features+'')
	newWindow.focus()
}
function changeimgto(imgname,imgurl)
{
     var imageto = window.document.getElementById(imgname);
	 if (imageto != null)
	 {
		imageto.src = imgurl;
	 }
}
//Put all the image element that has alt attribute value into an array
function analyseimgs()
{
  var altstr = null;
  for (var i =0; i <document.images.length; i++)
   {
		altstr = document.images[i].alt;
		if (altstr != null && altstr.length>0 && (altstr.indexOf(".jpg") != -1 || altstr.indexOf(".gif") != -1))
		{
		   if (!hasduplicate(altstr))
		   {
			bigimages[imagecount] = altstr;
			imagecount++;
		   }
		}
   }
  imagecount--;
  boolimage = true;
}
function previousimg(imgname)
{
   if (!boolimage)
	{
	 analyseimgs();
	}
	if (imagecount >0)
	{
		if (currentimg > 0)
		{
		 currentimg--;
		}else
		{
	 	 currentimg = imagecount;
		}
		changeimgto(imgname,bigimages[currentimg]);
	}
}
function nextimg(imgname)
{
	if (!boolimage)
	{
	 analyseimgs();
	}
	if (imagecount > 0)
	{
		if (currentimg < imagecount)
		{
			 currentimg++;
		}else
		{
			currentimg = 0;
		}
		changeimgto(imgname,bigimages[currentimg]);
	}
}
function hasduplicate(imgname)
{
  if (imagecount > 0)
  {
	for (var i = 0; i < imagecount-1; i++)
	{
		if (imgname.indexOf( bigimages[i] ) != -1)
		{
			return true;
		}
	}
  }
  return false;
}
function isNetscape()
{
	if (navigator.appName == "Netscape")
	  return true;
	else
	  return false;
}
