/* Gallery Thumbnail flip through script.
* Needs work to make it more MooTools-y - TBB
* Will not conflict with MooTools.
* Need to define gThumbs variable on each page.
* This script file *NEEDS* to be called from the bottom
* of the page.
*/

var gThumbImgs = $$('.gthumb');
var gThumbPath = '/img/brands/';
var gThumbIndex = 0;
var gThumbExec; 
var gThumbSpeed = 300;

function gThumbCycleThrough(e){ 
	e.src = gThumbPath+gThumbs[gThumbIndex]; 
	if(gThumbIndex >= (gThumbs.length-1)){	gThumbIndex = 0; } 
	else { gThumbIndex = gThumbIndex+1; } 
}
function gThumbClear(){ clearTimeout(gThumbExec); this.src = this.title; }
function gThumbStart(){ gThumbExec = setInterval(gThumbCycleThrough,gThumbSpeed,this); }

function gThumbRunCycle(){
	for(i=0; i < gThumbImgs.length; i++){
	gThumbImgs[i].title = gThumbImgs[i].src;
	/* IE handles setInterval differently. */
	if(navigator.appName.match(/Microsoft internet explorer/i)){
		gThumbImgs[i].onmouseover = function(){
			gThumbExec = setInterval("gThumbCycleThrough("+this.id+")",50);
		};
	} else {
		gThumbImgs[i].onmouseover = gThumbStart;
	}
		gThumbImgs[i].onmouseout = gThumbClear;
	} 
}
window.onload = gThumbRunCycle;

