// Specify your image files here.  The specified image files
// must actually exist in the image_folder specified below.
//
var images = new Array(); // Don't change this line.
images.push("first-logo.gif");
images.push("logo-acxiom.gif");
images.push("logo-att.gif");
images.push("logo-bankofamerica.gif");
images.push("logo-bankofny.gif");
images.push("logo-bsi.gif");
images.push("logo-churchill.gif");
images.push("logo-deloitte.gif");
images.push("logo-drivesavers.gif");
images.push("logo-dtcc.gif");
images.push("logo-earlywarning.gif");
images.push("logo-ernst.gif");
images.push("logo-Evantix2.gif");
images.push("logo-firstdata.gif");
images.push("logo-fishnet.gif");
images.push("logo-goldmansachs.gif");
images.push("logo-ibm.gif");
images.push("logo-infosys.gif");
images.push("logo-ironmountain.gif");
images.push("logo-chase2.gif");
images.push("logo-jbr.gif");
images.push("logo-kpmg.gif");
images.push("logo-liveops.gif");
images.push("logo-morganstanley.gif");
images.push("logo-net2s.gif");
images.push("logo-radian.gif");
images.push("logo-recall.gif");
images.push("logo-sei.gif");
images.push("logo-sungard.gif");
images.push("logo-target.gif");
images.push("logo-trustwave.gif");
images.push("logo-tsys.gif");
images.push("logo-usbank.gif");
images.push("logo-wellsfargo.gif");
images.push("logo-wilmington.gif");
images.push("logo-wipro.gif");
images.push("logo-yodlee.gif");
images.push("logo-zoot.gif");


// It's easiest to put your image files in the same folder as this
// script.  But if you want to put them in another folder, then set
// image_folder to that folder's path, including a trailing slash.
//
var image_folder = "/rotating_logos/images/"; // set to null if images are in same folder as this script.


// If you want the imagebox to be hidden until the user scrolls the
// page down past a certain element, then set this variable to the
// id of that element.  Otherwise set it to null ('').  You can also
// adjust the display time and fade settings here.
//
var element_below_which_imagebox_will_be_displayed = '';
var imagebox_display_time = 2000; // in milliseconds.
var use_fadein = 1;
var fadeout_delay = 40;
var fadein_delay = 40;


//
// You probably don't need to change anything below here.
//


var curimage = 1;
var fadeout_interval = '';
var fadein_interval = '';
var current_opacity = 100;
var all_images = new Array();

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function topOfElement(eID)
{
	var i = findPos(document.getElementById(eID));
	return i[1];
}

function position_imagebox()
{
	if(document.body)
	{
		var disp = '';
		if(navigator.userAgent.indexOf("MSIE 5") > -1 || navigator.userAgent.indexOf("MSIE 6") > -1)
		{
			// IE <7 don't support position:fixed.
			disp = 'block';
		}
		else
		{
			var scrollpos = window.pageYOffset ? window.pageYOffset : document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
			if(element_below_which_imagebox_will_be_displayed != ''   &&   document.getElementById(element_below_which_imagebox_will_be_displayed)   &&   scrollpos < topOfElement(element_below_which_imagebox_will_be_displayed))
			{
				disp = 'none';
			}
			else
			{
				disp = 'block';
			}
		}
		document.getElementById("imagebox").style.display = disp;
	}
}

function init_imagebox()
{
	preload_images();
	position_imagebox();
}

function rotate_imagebox()
{
	if(document.getElementById("imagebox").style.display == 'none')
		return;

	fadeout_interval = setInterval("dec_opacity('imagebox')", fadeout_delay);
}

function set_opacity(eID,the_opacity)
{
	document.getElementById(eID).style.opacity = the_opacity / 100;
	document.getElementById(eID).style.filter = 'alpha(opacity=' + the_opacity + ')';
}

function dec_opacity(eID)
{
	current_opacity -= 5;
	set_opacity(eID,current_opacity);
	if(current_opacity <= 0)
	{
		clearInterval(fadeout_interval);
		advance_image();
		display_image();
		setTimeout("rotate_imagebox()", imagebox_display_time);
	}
}

function inc_opacity(eID)
{
	current_opacity += 5;
	set_opacity(eID,current_opacity);
	if(current_opacity >= 100)
	{
		clearInterval(fadein_interval);
	}
}

function advance_image()
{
	curimage++;
	if(curimage > numberOfImages) { curimage = 1; }
}

function display_image()
{
	document.getElementById("imagebox_image").src = get_image_source(curimage);
	if(use_fadein)
	{
		fadein_interval = setInterval("inc_opacity('imagebox')", fadein_delay);
	}
	else
	{
		current_opacity = 100;
		set_opacity('imagebox',current_opacity);
	}
}

function get_image_source(imagenum)
{
	return all_images[imagenum].src;
}

function print_debug(somestring)
{
	var debug = document.getElementById("debug");
	if(debug)
		debug.value = somestring;
}

function preload_images()
{
	numberOfImages = images.length;

	for(i = 1; i <= numberOfImages; i++)
	{
		all_images[i] = new Image;
		all_images[i].src = image_folder + images[i - 1]; // The "images" array is zero-indexed.
	}

	setTimeout("rotate_imagebox()", imagebox_display_time);
}

function schedule_onload_action(newfunc)
{
	var already_scheduled = window.onload;
	if(typeof window.onload != 'function')
	{
		window.onload = newfunc;
	}
	else
	{
		window.onload = function()
		{
			already_scheduled();
			newfunc();
		}
	}
}

function schedule_onresize_action(newfunc)
{
	var already_scheduled = window.onresize;
	if(typeof window.onresize != 'function')
	{
		window.onresize = newfunc;
	}
	else
	{
		window.onresize = function()
		{
			already_scheduled();
			newfunc();
		}
	}
}

function schedule_onscroll_action(newfunc)
{
	var already_scheduled = window.onscroll;
	if(typeof window.onscroll != 'function')
	{
		window.onscroll = newfunc;
	}
	else
	{
		window.onscroll = function()
		{
			already_scheduled();
			newfunc();
		}
	}
}

schedule_onload_action(init_imagebox);
schedule_onresize_action(position_imagebox);
schedule_onscroll_action(position_imagebox);

