var numscrollimages = 0;
var imgindex = 0;
var quitanimation = false;
var currentimage = 0;

function doimagechanger()
{
	quitanimation = false;
	if(preloadimages())
	{
		startanimation();
	}
	else
	{
		// if the browser can't swap images, then we just static-display the 'last' image in the array
		document.getElementById('scrollerimg').src = image_src[numscrollimages-1];
		document.getElementById('scrollerimg').alt = image_alt[numscrollimages-1];
		document.getElementById('scrollerlink').href = image_link[numscrollimages-1];
	}
}

function startanimation()
{
	document.getElementById('scrollerimg').src = image_src[0];
	document.getElementById('scrollerimg').alt = image_alt[0];
	document.getElementById('scrollerlink').href = image_link[0];
	setTimeout(function(){changer()}, 2500);

}

function stopanimation()
{
	quitanimation = true;
}


function preloadimages()
{
	image_src = new Array();
	image_link = new Array();
	image_alt = new Array();

      image_src[0] = "images/frame1.png";		image_link[0] = "dps.php";		image_alt[0] = "View DPS";
      image_src[1] = "images/frame2.png";		image_link[1] = "dpsl.php";		image_alt[1] = "View DPSLab";
      image_src[2] = "images/frame3.png";		image_link[2] = "sr2.php";		image_alt[2] = "View SR2";
      image_src[3] = "images/frame4.png";		image_link[3] = "epsilon.php";	image_alt[3] = "View Epsilon";
      image_src[4] = "images/frame5.png";		image_link[4] = "sigma.php";	image_alt[4] = "View Sigma";
      image_src[5] = "images/frame6.png";		image_link[5] = "ninja.php";	image_alt[5] = "View Ninja";
      image_src[6] = "images/frame7.png";		image_link[6] = "eclipse.php";	image_alt[6] = "View Eclipse";
      image_src[7] = "images/frame8.png";		image_link[7] = "products.php";	image_alt[7] = "Products";


	numscrollimages=image_src.length;

	if (document.images)
	{
		var i = 0;
		var image_object = [];      
		for(i=0; i<numscrollimages; i++)
		{
			image_object[i] = new Image();
			image_object[i].src = image_src[i];
		}

		return true;
	}

	return false;
}  

function changer()
{
	if(quitanimation) return;

	// if we're at the last image, then we quit
	if(imgindex == numscrollimages-1)
	{
		quitanimation = true;
		return;
	}

	changeimage();

	setTimeout(function(){changer()}, 2500);
}

function changeimage() 
{
	imgindex ++;
	if(imgindex > numscrollimages-1)
	{
		imgindex = 0;
	}

	document.getElementById('scrollerimg').src = image_src[imgindex];
	document.getElementById('scrollerimg').alt = image_alt[imgindex];
	document.getElementById('scrollerlink').href = image_link[imgindex];

	currentimage = imgindex;
}

function detectbrowser()
{
	if(navigator.userAgent.indexOf('MSIE') !=-1) { return 'MSIE'; }
	if(navigator.userAgent.indexOf('Firefox') !=-1) { return 'Firefox'; }
	return 'unknown';
}

function selectframe(navpos)
{
	quitanimation = true;

	if(navpos == currentimage) return;
	if(!document.images) return;

	document.getElementById('scrollerimg').src = image_src[navpos];
	document.getElementById('scrollerimg').alt = image_alt[navpos];
	document.getElementById('scrollerlink').href = image_link[navpos];
	currentimage = navpos;
}

function baseName(url) 
{
    return url.substring(url.lastIndexOf('/') + 1);
}

