var lastLogo = 1;
var imageCount = 0;
		
function startFade() {
	var isIE = ( navigator.appName == 'Microsoft Internet Explorer' ) ? true : false;
		
	//get the number of image holders on page
	if ( !isNaN(placeholderCount) ) {
		imageCount = placeholderCount;
	} else {
		for (var j = 1; j <= 20; j++) {
			if (document.getElementById('imgFadeLogo' + j)) {
				imageCount = j;
			} else {
				break;
			}
		}
	}
		
	//get random offset so it starts at different logo
	var offset = Math.round(Math.random() * (aryLogos.length-1))
	lastLogo = lastLogo + offset;

	//start each placeholder fading logos
	for (var i = 1; i <= imageCount; i++) {
		//now fade in image
		if ( isIE ) {
			fadeLogoIE(i);			
		} else {
			fadeLogo(i, -1, 100, true);
		}
	}
}
	
function fadeLogoIE(imgID) {
	if (document.getElementById('imgFadeLogo' + imgID)) {
		//get a reference to the next image and link, based on id
		var imgL = document.getElementById('imgFadeLogo' + imgID);
		var aL = document.getElementById('aFadeLink' + imgID);
		
		//set the filter
		imgL.style.filter = "progid:DXImageTransform.Microsoft.Fade('duration=2')";
		
		if (imgL.filters) {
			imgL.filters[0].apply();
				
			//if the src is the spacer, image is faded out, 
			//so change to next image to fade in
			if (imgL.src == imgSpacer.src) {
				if (lastLogo < aryLogos.length) {
					imgL.src = eval('imgLogo' + lastLogo + '.src');
					aL.href = aryLinks[lastLogo];
					lastLogo++;
				} else {
					imgL.src = imgLogo1.src;
					aL.href = aryLinks[1];
					lastLogo = 2;
				}
			} else {
				imgL.src = imgSpacer.src;
			}
				
			//run the filter
			imgL.filters[0].play();
		}

		//if we have more logos than placeholders, we will do fading	
		if ( (aryLogos.length - 1) > imageCount) {
			
			//set this image to fade in/out again
			if (imgL.src == imgSpacer.src) {
				window.setTimeout('fadeLogoIE(' + imgID + ')', 2050);
			} else {
				window.setTimeout('fadeLogoIE(' + imgID + ')', 5000);
			}
		}
	}
}


function fadeLogo(imgID, dir, opac, boolLoad) {
	if (document.getElementById('imgFadeLogo' + imgID)) {
		var timeWait = 100;
			
		//get a reference to the next image and link, based on id
		var imgL = document.getElementById('imgFadeLogo' + imgID);
		var aL = document.getElementById('aFadeLink' + imgID);

		//set the opacity
		setOpacity(imgL, opac);

		//if opac = 0 (trans), load new image
		if (opac == 0 || boolLoad) {
			if (lastLogo < aryLogos.length) {
				imgL.src = eval('imgLogo' + lastLogo + '.src');
				aL.href = aryLinks[lastLogo];
				lastLogo++;
			} else {
				imgL.src = imgLogo1.src;
				aL.href = aryLinks[1];
				lastLogo = 2;
			}
		}
			
		//if reached opaq. or trans, change direction of fade
		if (opac == 100) {
			timeWait = 5000;
			dir = -1;
		} else if (opac == 0) {
			dir = 1;
		}
			
		var nextOpac = opac + (dir * 5);
			
		//if we have more logos than placeholders, we will do fading		
		if ( (aryLogos.length - 1) > imageCount) {
			window.setTimeout('fadeLogo(' + imgID + ',' + dir + ',' + nextOpac + ',false)', timeWait);
		}
	} 
}

function setOpacity(obj, opacity) {
		//prevent Moz flicker
		opacity = (opacity == 100)?99.999:opacity;
	  
		// older IE/Win
		obj.style.filter = 'alpha(opacity:' + opacity + ')';
	  
		// Safari&lt;1.2, Konqueror
		obj.style.KHTMLOpacity = opacity/100;
	  
		// Older Mozilla and Firefox
		obj.style.MozOpacity = opacity/100;
	  
		// Safari 1.2, newer IE, Firefox and Mozilla, CSS3
		obj.style.opacity = opacity/100;
}
