 
  /* globals */
 
 var scrollSpeed = 10;
 var scrollEaseIn = 6;
 
 var fadeIncrement = 0.04;

 var autoScrollDelay = 6000;
 var nextZIndex = 2; 

 if (!currentBanner) var currentBanner = new Array();
 if (!bannerCount) var bannerCount = new Array();
 if (!bannerTransition) var bannerTransition = new Array();
 if (!timeout) var timeout = new Array();
 if (!autoint) var autoint = new Array();

 var pathToVariWidthBanners = 'http://i.expansys.com/j/6c/images/sprites/home/slim_banner/';
 
 /* constructors */
 
 function bannerImage(center, type, link, text, tracking) {
	 this.center = center;
	 this.image = center;
	 this.text = text;
	 this.tracking = tracking;
	 
	 if (type != '') {
	 this.type = type;
	 /*this.left = pathToVariWidthBanners + type + '/left.png';
	 this.right = pathToVariWidthBanners + type + '/right.png';
	 this.back = pathToVariWidthBanners + type + '/back.png';*/
   this.left = pathToVariWidthBanners + 'left.png';
	 this.right = pathToVariWidthBanners + 'right.png';
	 this.back = pathToVariWidthBanners + 'back.png';
 	}
	 
	 this.link = link;
	 if (this.link.indexOf("?") < 0 && tracking != "") this.link = this.link + '?se=s' + this.tracking;
	 else this.link = this.link + '&se=s' + this.tracking;
 }
 
  function variWidthBanner(id, height) {
	this.id = id;
	this.type = 'variWidthBanner';
	this.banners = new Array();
	this.height = height;
	this.add = addBanner;
	this.render = renderVariWidthBanner;
	this.transitionType = 'scroll';
	bannerTransition[id] = 'scroll';
	currentBanner[id] = 0;
 }
 
   function photoBanner(id, width, height) {
	this.id = id;
	this.type = 'photoBanner';
	this.height = height;
	this.width = width;
	this.banners = new Array();
	this.add = addBanner;
	this.render = renderPhotoBanner;
	this.transitionType = 'fade';
	bannerTransition[id] = 'fade';
	currentBanner[id] = 0;
 }
 
 
 /* methods */
 
 function addBanner(center, type, link, text, tracking) {
	 this.banners.push(new bannerImage(center, type, link, text, tracking));
	 bannerCount[this.id] = this.banners.length;
 }
 
 
 function renderVariWidthBanner() {
	if (this.banners.length > 0) {

	var outerClassName = 'scrollBanner';
	var innerClassName = 'slider';
	if (this.transitionType == 'fade') {
		outerClassName = 'fadeBanner';
		innerClassName = 'fadeElements';
	}

	document.write('<div class="' + outerClassName + '" id="' + this.id + '" style="height:72px;">');

	document.write('<div id="'+ innerClassName +'" style="height:72px;">');

	 var bMax = this.banners.length - 1;
	 writeVariWidthBanner(this.banners[bMax].link, -100, this.height, this.banners[bMax].back, this.banners[bMax].left, this.banners[bMax].right, this.banners[bMax].center, this.transitionType);
	 for (x in this.banners) writeVariWidthBanner(this.banners[x].link, ((x) * 100), this.height, this.banners[x].back, this.banners[x].left, this.banners[x].right, this.banners[x].center, this.transitionType);	
	 writeVariWidthBanner(this.banners[0].link, (bMax+1) * 100, this.height, this.banners[0].back, this.banners[0].left, this.banners[0].right, this.banners[0].center, this.transitionType);
	 document.write('</div>');
	 
	 if (this.banners.length > 1) renderNextPrevLinks(this.id);
 	 
	 document.write('</div>');
	 
	 if (this.banners.length > 1) {
	 document.write('<p class="scrollBannerNav" id="'+ this.id +'Nav">');
	 for (x = this.banners.length - 1; x >= 0; x--) {
		var page = parseInt(x) + 1;	 
		document.write('<a ');
		if (page == 1) document.write('class="current" ');
		document.write ('id="'+ this.id +'NavLink'+ x +'" href="javascript:resetScrollInterval(\''+ this.id +'\');switchBanners(\''+ this.id +'\','+ x +');">'+ page +'</a> ');
	 }
	 document.write('</p>');
 	}
	 
	 var bannerset = document.getElementById(this.id);
	 bannerset.firstChild.style.left = '0%';

 	}
 }
 
 
 function renderNextPrevLinks(id) {
	 document.write ('<a class="prevLink" href="javascript:resetScrollInterval(\''+ id +'\');prevBanner(\''+ id +'\');">&lt;</a>');
	 document.write ('<a class="nextLink" href="javascript:resetScrollInterval(\''+ id +'\');nextBanner(\''+ id +'\');">&gt;</a>');
 }
 
 
  function renderPhotoBanner() {
	 if (this.banners.length > 0) {
	 
	var outerClassName = 'photoBanner';
	var innerClassName = 'slider';
	if (this.transitionType == 'fade') {
		outerClassName = 'fadeBanner';
		innerClassName = 'fadeElements';
	}

	 document.write('<div id="photoBannerContainer" style="height:'+ this.height +'px;width:' + this.width + 'px">');
	 document.write('<div class="'+ outerClassName +'" id="' + this.id + '" style="height:'+ this.height +'px;width:' + this.width + 'px">');
	 document.write('<div id="'+ innerClassName +'" style="height:'+ this.height +'px;width:'+ this.width +'px">');

	 var bMax = this.banners.length - 1;
	 var bannerid = 1;
	 writePhotoBanner(this.banners[bMax].link, -100, this.width, this.height, this.banners[bMax].image, this.banners[bMax].text, this.transitionType, this.id, 0);
	 for (x in this.banners) writePhotoBanner(this.banners[x].link, (x) * 100, this.width, this.height, this.banners[x].image, this.banners[x].text, this.transitionType, this.id, bannerid++);
	 writePhotoBanner(this.banners[0].link, (bMax+1) * 100, this.width, this.height, this.banners[0].image, this.banners[0].text, this.transitionType, this.id, bannerid);
	 
	 document.write('</div>');
	 
	 if (this.banners.length > 1) renderNextPrevLinks(this.id);
	 
	 document.write('</div>');
	 document.write('</div>');
	 
	 var bannerset = document.getElementById(this.id);
	 bannerset.firstChild.style.left = '0%';
	 
 	}
	}

   	function writeVariWidthBanner(link, position, height, back, left, right, center, transitionType) {
		if (transitionType == 'scroll') document.write('<div class="banner" onmouseover="window.status=\''+ link +'\';" onmouseout="window.status=\'\';" style="background:Url(\''+ back +'\') top repeat-x;left:'+ position +'%;height:'+ height +'px;" onclick="location.href=\''+ link +'\';" >');
		if (transitionType == 'fade') document.write('<div class="banner" onmouseover="window.status=\''+ link +'\';" onmouseout="window.status=\'\';" style="background:Url(\''+ back +'\') top repeat-x;left:0%;top:0%;height:'+ height +'px;" onclick="location.href=\''+ link +'\';" >');
		document.write('<div class="inner" style="height:72px;">');
		document.write('<img src="'+ left +'" class="left" width="28" height="72" />');
		document.write('<img src="'+ right +'" class="right" width="28" height="72" />');
		document.write('<img src="'+ center +'" class="center" width="400" height="72" />');
		document.write('</div>');
		document.write('</div>');
 	}
  
  	function writePhotoBanner(link, position, width, height, image, text, transitionType, id, ord) {
	 	if (transitionType == 'scroll') document.write('<div class="banner" onmouseover="window.status=\''+ link +'\';" onmouseout="window.status=\'\';" style="left:'+ position +'%;height:'+ height +'px;width:'+ width +'px" onclick="location.href=\''+ link +'\';" >');
		if (transitionType == 'fade') document.write('<div class="banner" id="'+ id +'Banner'+ ord +'" onmouseover="window.status=\''+ link +'\';" onmouseout="window.status=\'\';" style="left:0%;top:0%;height:'+ height +'px;width:'+ width +'px" onclick="location.href=\''+ link +'\';" >');
		document.write('<div class="inner" style="height:'+ height +'px;width:'+ width +'px">');

		document.write('<img src="'+ image +'" alt="'+ text +'" width="230" height="180" />');

		document.write('<div class="bannerText" style="width:' + width + 'px;">');
		document.write('<a href="'+ link +'">'+ text +'</a>');
		document.write('</div>');
				
		document.write('</div>');
		document.write('</div>');
 	}
 

 	 /* functions */
 
 function resetScrollInterval(id) {
	 if (autoint[id] != null) {window.clearInterval(autoint[id]);
	 autoint[id] = window.setInterval(function() { nextBanner(id); }, autoScrollDelay);
 }}
 
 function setPos(banner, pos) {
	banner.style.left = pos + '%';
 }
 
 function getPos(banner) {
	return parseInt(banner.style.left);
 }
 
 function switchBanners(id,bannerId) {
	var bannerset = document.getElementById(id);
	idealpos = (bannerId) * -100;
	currentpos = getPos(bannerset.firstChild);
	window.clearTimeout(timeout[id]);
	if (bannerTransition[id] == 'scroll') timeout[id] = window.setTimeout(function() { slideBanners(id, idealpos) }, scrollSpeed);
	if (bannerTransition[id] == 'fade') timeout[id] = window.setTimeout(function() {

		document.getElementById(id + 'Banner' + bannerId).style.opacity = 0;
		if (document.getElementById(id + 'Banner' + bannerId).style.filter) document.getElementById(id + 'Banner' + bannerId).style.filter  = "alpha(opacity=0)";
		for (var i = 0; i <= (bannerCount[id]+1); i++) if (document.getElementById(id + 'Banner' + i)) {
			if (document.getElementById(id + 'Banner' + i).style.zIndex == 3) document.getElementById(id + 'Banner' + i).style.zIndex = 2;
			else document.getElementById(id + 'Banner' + i).style.zIndex = 1;
		}
		document.getElementById(id + 'Banner' + bannerId).style.zIndex = 3;

		fadeBanners(id, bannerId)
		

	}, scrollSpeed);
	setCurrentNav(id, bannerId);
	currentBanner[id] = bannerId;
 }
 
function fadeBanners(id, bannerId) {

	var opacity = parseFloat(document.getElementById(id + 'Banner' + bannerId).style.opacity);
	

	document.getElementById(id + 'Banner' + bannerId).style.opacity = opacity + fadeIncrement;
	if (document.getElementById(id + 'Banner' + bannerId).style.filter) document.getElementById(id + 'Banner' + bannerId).style.filter  = "alpha(opacity=" + parseInt((opacity + fadeIncrement)*100) + ")";


	if (opacity + fadeIncrement <= 1) {
		window.clearTimeout(timeout[id]);
		timeout[id] = window.setTimeout(function() { fadeBanners(id, bannerId) }, scrollSpeed); 
	} else {
	 	currentBanner[id] = bannerId;
	}

}

 function slideBanners(id, idealpos) {
	 var bannerset = document.getElementById(id);
	 currentpos = parseInt(bannerset.firstChild.style.left);
	 var dir;
	 newpos = (((parseFloat(currentpos) * (scrollEaseIn - 1)) + parseFloat(idealpos)) / scrollEaseIn);
	 if (currentpos < newpos) dir = 1;
	 if (currentpos > newpos) dir = -1;
	 newpos = parseInt(newpos);
	 if (newpos == currentpos) newpos += dir;
	 
	 if (currentpos != idealpos) { 
		 setPos(bannerset.firstChild, newpos);
		 window.clearTimeout(timeout[id]);
		 timeout[id] = window.setTimeout(function() { slideBanners(id, idealpos) }, scrollSpeed); 
	  } else {
		   setPos(bannerset.firstChild, idealpos);
		  
		  if (idealpos == 100) {
			  setPos(bannerset.firstChild, ((bannerCount[id] - 1) * -100));
			  	currentBanner[id] = bannerCount[id] - 1;
			    }
		  
		  if (idealpos == ((bannerCount[id]) * -100)) {
			  setPos(bannerset.firstChild, 0);
			  currentBanner[id] = 0;
		  }
	   }
 	}
 
 	function setCurrentNav(id, newid) {
	 	if (newid < 0) newid = bannerCount[id] - 1;
	 	if (newid >= bannerCount[id]) newid = 0;
	 	if (document.getElementById(id + 'NavLink' + currentBanner[id])) document.getElementById(id + 'NavLink' + currentBanner[id]).className = '';
	 	if (document.getElementById(id + 'NavLink' + newid)) document.getElementById(id + 'NavLink' + newid).className = 'current';
 	}
 	
 	function nextBanner(id) {
	 	var bannerId = currentBanner[id] + 1;
	 	if (bannerId < (bannerCount[id])) switchBanners(id,bannerId);
	 	else switchBanners(id,0);
 	}
 	
 	function prevBanner(id) {
	 	var bannerId = currentBanner[id] - 1;
	 	if (bannerId > -1) switchBanners(id,bannerId);
	 	else switchBanners(id,bannerCount[id] - 1);

 	}
 	
 	function startAutoScroll(id) {
		 autoint[id] = window.setInterval(function() { nextBanner(id); }, autoScrollDelay);
	}