//myTrace = new traceWindow();
//myTrace.open();

//==========================================================
var CarouselOptions = new Object;
//==========================================================
CarouselOptions.transitionType_SEQUENTIAL		= 0;
CarouselOptions.transitionType_RANDOM			= 1;

CarouselOptions.transitionToUse_IMMEDIATE		= 1;
CarouselOptions.transitionToUse_FADE			= 2;
CarouselOptions.transitionToUse_WINDOW			= 3;
CarouselOptions.transitionToUse_SHRINK			= 4;

CarouselOptions.controlsLocation_TOP			= 0;
CarouselOptions.controlsLocation_BOTTOM			= 1;
//==========================================================

function iterateObject(obj, title)
	{
	alert("iterateObject" + (title?" " + title:""));
	var stuff = "";
	var lines = 0
	for (att in obj)
		{
		if (typeof obj[att] != "function")
			{
			stuff += att + " = " + obj[att] + "\n";
			if (++lines > 49)
				{
				alert(stuff);
				stuff = "";
				lines = 0;
				}
			}
		}
	if (stuff.length)
		alert(stuff);
	}

//===========================================
// browser compatibility functions start here
//===========================================
function elevateAttribute(tag,attrName)
	{
	if (document.all) return;
	var attr = tag.attributes.getNamedItem(attrName);
	if (attr)
		tag[attrName] = attr.nodeValue;

	}
function findChildNode(tag, index)
	{
	if (document.all)
		return tag.children[index];
	var item = 0;
	for (x = 0; x < tag.childNodes.length; x++)
		{
		var node = tag.childNodes[x];
		if (node.nodeName != "#text")
			if (item++ == index)	//intentional increment after compare
				return node;
		}
	}
//=========================================
// browser compatibility functions end here
//=========================================

function CarouselPanel(tagId, opts)
	{
	this.tagId		= tagId;
	this.tag		= document.getElementById(tagId);
	this.tag		= findChildNode(this.tag, 0);
	elevateAttribute(this.tag,"tabText");
	elevateAttribute(this.tag,"tabText2");
	elevateAttribute(this.tag,"exposureTime");
	elevateAttribute(this.tag,"hoverText");
	elevateAttribute(this.tag,"tabWidth");

	this.tabText		= "";
	this.tabText2		= "";
	this.exposureTime	= 0;
	this.hoverText		= "";
	this.tabWidth		= 0;

	this.tag.style.display	= "none";

	if (this.tag.tabText     ) this.tabText      = this.tag.tabText;
	if (this.tag.tabText2    ) this.tabText2     = this.tag.tabText2;
	if (this.tag.exposureTime) this.exposureTime = new Number(this.tag.exposureTime);
	if (this.tag.hoverText   ) this.hoverText    = this.tag.hoverText;
	if (this.tag.tabWidth    ) this.tabWidth     = this.tag.tabWidth;

	//-----------------------------------------------
	//use the optional array to override the defaults
	//-----------------------------------------------
	if (opts)
		for (var i in opts)
			this[i] = opts[i];
	}

function CarouselEvents()
	{
	this.panelChange	= function(how, from, to){};
	this.timerAction	= function(on){};
	this.hoverAction	= function(on){};
	this.parent		= null;	//filled in later, points to the Carousel instance

	this.panelChange_TIMER	= 1;
	this.panelChange_NEXT	= 2;
	this.panelChange_PREV	= 3;
	this.panelChange_TAB	= 4;
	}

//==========================================================

function Carousel(id, panels, width, height, opts)
	{
	//===================
	// private properties
	//===================
	this.id			= id;				//the id of the tag in which to render
	this.panels		= panels;
	this.width		= width;
	this.height		= height;
	this.currentPanel 	= generateRandomInteger(0, panels.length - 1);
	this.running		= false;
	this.expiredWidth	= 0;
	this.hovering		= false;
	this.transittionIndex	= 0;
	this.homeTag		= document.getElementById(id);	//so we only have to find it once
	this.controlsTag	= null;
	this.tabBarTag		= null;
	this.panelTag		= null;
	this.previousPanel	= 0;
	this.panelChangeMethod	= 0;	//for event - captures what caused the change
	this.inTransition	= false;	//no hover border while in transition


	//==================
	// public properties
	//==================
	this.showTabs		= false;
	this.showNavigation	= true;
	this.showPageOf		= true;
	this.showCountdown	= true;
	this.showOnOff		= true;
	this.runTimer		= true;
	this.stopTimerOnManual	= false;
	this.countdownWidth	= 30;				//in pixels
	this.transitionsToUse	=	[
					CarouselOptions.transitionToUse_IMMEDIATE,
					CarouselOptions.transitionToUse_FADE,
					CarouselOptions.transitionToUse_WINDOW,
					CarouselOptions.transitionToUse_SHRINK
					];
	this.fadeSpeed		= 1;
	this.events		= new CarouselEvents;
	this.exposureTime	= 10;				//in seconds
	this.pageOfFormat	= "%1/%2";
	this.transitionType	= CarouselOptions.transitionType_RANDOM;
	this.revealSpeed	= 50;
//new
	this.countdownImageCount	= 0;
	this.countdownImageFormat	= "";
	this.countdownStopPrompt	= "Stop Auto Advance";
	this.countdownStartPrompt	= "Start Auto Advance";

	this.ulcImageCurrent	= null;
	this.urcImageCurrent	= null;
	this.ulcImage		= null;
	this.urcImage		= null;
	this.tabBarExcessWidth	= 0;

	this.controlsLocation	= CarouselOptions.controlsLocation_TOP;

	this.prevImage		= null;
	this.nextImage		= null;
	this.stopImage		= null;
	this.startImage		= null;

	this.showHoverStripes	= false;

	//-----------------------------------------------
	//use the optional array to override the defaults
	//-----------------------------------------------
	if (opts)
		for (var i in opts)
			this[i] = opts[i];

	//range check currentPanel in case it was reset
	if (this.currentPanel >= panels.length)
		this.currentPanel = panels.length - 1;
	if (this.currentPanel < 0)
		this.currentPanel = 0;

	revealSpeed		= this.revealSpeed;
	this.events.parent	= this;

	//=====================================================
	// public methods
	//=====================================================
	this.next = function(how)
		{
		if (!how)
			{
			how = this.events.panelChange_NEXT;
			if (this.stopTimerOnManual == true)
				this.stop();
			}
		this.panelChangeMethod = how;
		this.previousPanel= this.currentPanel;
		this.currentPanel++;
		if (this.currentPanel >= this.panels.length)
			this.currentPanel = 0;
		this.expiredWidth = 0;
		this.changePanel();
		}
	this.prev = function()
		{
		if (this.stopTimerOnManual == true) this.stop();
		this.previousPanel= this.currentPanel;
		this.currentPanel--;
		if (this.currentPanel < 0)
			this.currentPanel =  this.panels.length - 1;
		this.expiredWidth = 0;
		this.panelChangeMethod = this.events.panelChange_PREV;
		this.changePanel();
		}
	this.stop = function()
		{
		if (this.running == true)
			{
			this.running = false;
			this.expiredWidth = 0;
			this.buildControls();
			if (this.iTimerID) window.clearInterval(this.iTimerID);
			this.iTimerID = null;
			this.events.timerAction(false);
			}
		}
	this.start = function()
		{
		if (this.runTimer == true)
			{
			this.running = true;
			this.setPanelTimer();
			this.events.timerAction(true);
			}
		}
	this.showPanel = function(which)
		{
		if (this.stopTimerOnManual == true) this.stop();
		if (which < 0) which = 0;
		if (which >= this.panels.length) which = this.panels.length - 1;
		this.previousPanel	= this.currentPanel;
		this.currentPanel		= which;
		this.expiredWidth	= 0;
		this.panelChangeMethod = this.events.panelChange_TAB;
		this.changePanel();
		}
	this.reset = function()
		{
		var wasRunning = this.running;
		this.stop();

		this.homeTag.innerHTML		= "";
		this.timerControl1		= null;
		this.controlsTag		= document.createElement("div");
		this.controlsTag.className	= "carouselControls";

		if (this.controlsLocation == CarouselOptions.controlsLocation_TOP)
			this.homeTag.appendChild(this.controlsTag);

		if (this.showTabs == true)
			{
			this.tabBarTag			= document.createElement("div");
			this.tabBarTag.className	= "carouselTabBar";
			this.homeTag.appendChild(this.tabBarTag);
			}

		this.panelShell			= document.createElement("div");
		if (this.height != 0)this.panelShell.style.height = this.height + "px";
		this.homeTag.appendChild(this.panelShell);

		this.panelTag			= document.createElement("div");
		this.panelTag.className		= "carouselBody reveal";
		var me				= this;
		this.panelTag.me		= me;
		this.panelTag.onmouseover	= function(){this.me.hoverstart.call(me);};
		this.panelTag.onmouseout	= function(){this.me.hoverstop.call(me);};
		this.panelShell.appendChild(this.panelTag);

		if (this.controlsLocation == CarouselOptions.controlsLocation_BOTTOM)
			this.homeTag.appendChild(this.controlsTag);

		this.buildDisplay();
		this.inTransition = true;
		var me = this;
		reveal(this.panelTag, function(){me.transitionComplete.call(me);});
		if (wasRunning) this.start();
		}

	//=====================================================
	// private methods
	//=====================================================
	this.hoverstart = function()
		{
		this.hovering = true;
		this.hoverStripes();
		this.events.hoverAction(this.hovering);
		}
	this.hoverstop = function()
		{
		this.hovering = false;
		this.hoverStripes();
		this.events.hoverAction(this.hovering);
		}
	this.getInteger = function(text)
		{
		if (text.length > 2 && text.substr(text.length - 2) == "px")
			return new Number(text.substr(0, text.length - 2));
		else
			return 0;
		}
	this.hoverStripes = function()
		{
		if	(	this.showHoverStripes	== false
			||	this.running		== false
			||	this.inTransition	== true
			)
			return;
		if (document.getElementById("hoverStripe1") == null)
			{
			var borderHeight	= this.getInteger(this.panelTag.currentStyle.borderTopWidth)
						+ this.getInteger(this.panelTag.currentStyle.borderBottomWidth);
			var borderWidth		= this.getInteger(this.panelTag.currentStyle.borderLeftWidth)
						+ this.getInteger(this.panelTag.currentStyle.borderRightWidth);

			//top
			var top			= document.createElement("div");
			top.id			= "hoverStripe1";
			top.className		= "hoverStripe";
			top.style.position	= "absolute";
			top.style.top		= "0px";
			top.style.left		= "0px";
			top.style.height	= "6px";
			top.style.width		= (this.panelTag.offsetWidth - borderWidth) + "px";
			top.style.fontSize	= "1px";
			this.panelTag.appendChild(top);

			//bottom
			var bottom		= document.createElement("div");
			bottom.id		= "hoverStripe2";
			bottom.className	= "hoverStripe";
			bottom.style.position	= "absolute";
			bottom.style.top	= (this.panelTag.offsetHeight - 6 - borderHeight) + "px";
			bottom.style.left	= "0px";
			bottom.style.height	= "6px";
			bottom.style.width	= top.style.width;
			bottom.style.fontSize	= "1px";
			this.panelTag.appendChild(bottom);

			//left
			var left		= document.createElement("div");
			left.id			= "hoverStripe3";
			left.className		= "hoverStripe";
			left.style.position	= "absolute";
			left.style.top		= "6px";
			left.style.left		= "0px";
			left.style.height	= (this.panelTag.offsetHeight - 2*6 - borderHeight) + "px";
			left.style.width	= "6px";
			left.style.fontSize	= "1px";
			this.panelTag.appendChild(left);

			//right
			var right		= document.createElement("div");
			right.id		= "hoverStripe4";
			right.className		= "hoverStripe";
			right.style.position	= "absolute";
			right.style.top		= "6px";
			right.style.left	= (this.panelTag.offsetWidth - 6 - borderWidth) + "px";
			right.style.height	= left.style.height;
			right.style.width	= "6px";
			right.style.fontSize	= "1px";
			this.panelTag.appendChild(right);
			}
		document.getElementById("hoverStripe1").style.display = 
		document.getElementById("hoverStripe2").style.display = 
		document.getElementById("hoverStripe3").style.display = 
		document.getElementById("hoverStripe4").style.display = (this.hovering)?"block":"none";
		}
	this.setPanelTimer = function()
		{
		if (this.running == true)
			{
			this.expiredWidth = 0;
			this.buildControls();
			var timeToUse = this.panels[this.currentPanel].exposureTime;
			if (timeToUse == 0) timeToUse = this.exposureTime;
			var recallRate	= (timeToUse * 1000) / this.countdownWidth;
			var me = this;
			if (this.iTimerID) window.clearInterval(this.iTimerID);
			this.iTimerID = window.setInterval(function(){me.tick.call(me);}, recallRate);
			}
		}
	this.tick = function()
		{
		if (this.hovering == true)return;
		this.expiredWidth++;
		if (this.expiredWidth > this.countdownWidth)
			{
			this.expiredWidth = 0;
			this.next(this.events.panelChange_TIMER);
			}
		else
			this.buildControls();
		}
	this.panelHeight = function()
		{
		var remove = 0;
		if (this.showTabs == true)
			remove = this.tabBarTag.offsetHeight;
		if (this.showTimer == true || this.showNavigation == true)
			if (this.controlsTag.offsetHeight > remove)
				remove = this.controlsTag.offsetHeight;
		return this.height - remove;
		}
	this.changePanel = function()
		{
		this.hovering = true;

		var transition = CarouselOptions.transitionToUse_IMMEDIATE;
		if (this.transitionsToUse.length > 0)
			{
			if (this.transitionsToUse.length == 1)
				{
				transition = this.transitionsToUse[0];
				}
			else
				{
				if (this.transitionType	== CarouselOptions.transitionType_RANDOM)
					{
					index = generateRandomInteger(0, (this.transitionsToUse.length - 1));
					transition = this.transitionsToUse[index];
					}
				else
					{
					this.transittionIndex += 1;
					if (this.transittionIndex >= this.transitionsToUse.length)
						 this.transittionIndex = 0;
					transition = this.transitionsToUse[this.transittionIndex];
					}
				}
			}
		switch (transition)
			{
			case CarouselOptions.transitionToUse_IMMEDIATE:
				this.buildDisplay();	// no transition
				this.transitionComplete();
				break;
			case CarouselOptions.transitionToUse_FADE:
				this.inTransition = true;
				this.opacity = 100;	//fade
				this.fadeout();
				break;
			case CarouselOptions.transitionToUse_WINDOW:
				this.inTransition = true;
				var me = this;		//window shade
				this.hovering = true;
				reveal(this.panelTag, function(){me.rolldown.call(me);});
				break;
			case CarouselOptions.transitionToUse_SHRINK:
				this.inTransition = true;
				this.opacity = 100;	//shring
				this.shrink();
				break;
			}
		}
	this.rolldown = function()
		{
		this.buildDisplay();
		var me = this;
		reveal(this.panelTag, function(){me.transitionComplete.call(me);});
		}
	this.fadeout = function()
		{
		this.opacity -= this.fadeSpeed;
		this.panelTag.style.filter = "alpha(opacity=" + this.opacity + ")";
		if (this.opacity > 50)
			{
			var me = this;
			window.setTimeout(function(){me.fadeout.call(me);}, 1);
			}
		else
			{
			this.buildDisplay();
			this.fadein();
			}
		}
	this.fadein = function()
		{
		this.opacity += this.fadeSpeed;
		if (this.opacity < 100)
			{
			this.panelTag.style.filter = "alpha(opacity=" + this.opacity + ")";
			var me = this;
			window.setTimeout(function(){me.fadein.call(me);}, 1);
			}
		else
			{
			this.panelTag.style.filter = "";
			this.transitionComplete();
			}
		}
	this.shrink = function()
		{
		this.opacity -= 1;
		this.panelTag.style.zoom = this.opacity + "%";
		if (this.opacity > 25)
			{
			var me = this;
			window.setTimeout(function(){me.shrink.call(me);}, 1);
			}
		else
			{
			this.buildDisplay();
			this.grow();
			}
		}
	this.grow = function()
		{
		this.opacity += 1;
		if (this.opacity < 100)
			{
			this.panelTag.style.zoom = this.opacity + "%";
			var me = this;
			window.setTimeout(function(){me.grow.call(me);}, 1);
			}
		else
			{
			this.panelTag.style.zoom = "";
			this.transitionComplete();
			}
		}
	this.transitionComplete = function()
		{
		this.inTransition = false;
		this.hovering = false;
		this.events.panelChange(this.panelChangeMethod, this.previousPanel, this.currentPanel);
		this.setPanelTimer();
		}
	this.buildDisplay = function()
		{
		this.buildTabBar();
		this.buildControls();
		this.buildInterior();
		}
	this.buildTabBar = function()
		{
		if (this.showTabs == true)
			{
			this.tabBarTag.style.display = "";
			this.buildGraphicTabBar();
			}
		}
	this.buildGraphicTabBar = function()
		{
		this.tabBarTag.innerHTML = "";

		// <div class="carouselTabs">
		//                         <div class="tabText"         style="width: 99px;"><img class="ulc" src="ulcns.bmp"><img class="urc" src="urcns.bmp"><a href="javascript:;">Harrison's  <br>Practice     </a></div>
		// <div class=tabSep></div><div class="tabText tabCurr" style="width:120px;"><img class="ulc" src="ulc.bmp"  ><img class="urc" src="urc.bmp"  ><a href="javascript:;">Merck Manual<br>Prof. Edition</a></div>
		// <div class=tabSep></div><div class="tabText"         style="width:111px;"><img class="ulc" src="ulcns.bmp"><img class="urc" src="urcns.bmp"><a href="javascript:;">Braunwald's <br>Atlas        </a></div>
		// <div class="tabFiller"></div>
		// </div>

		var totalWidth	= this.width;	//start with total width and remove what we use
		var tabs	= document.createElement("div");
		tabs.className	= "carouselTabs";
		tabs.style.width= this.width + "px";
		this.tabBarTag.appendChild(tabs);

		for (var x = 0; x < this.panels.length; x++)
			{
			var currentTab = (x == this.currentPanel);
			if (x > 0)
				{
				//add the inner-tab separation
				var sep		= document.createElement("div");
				sep.className	= "tabSep";
				tabs.appendChild(sep);
				totalWidth -= 1;
				}
			var panel	= this.panels[x];
			var tab		= document.createElement("div");
			tab.className	= (currentTab)?"tabText tabCurr":"tabText";

			//if the panel asks for a width, use it
			//if not give it an "average" tag width
			//(deduct 100 from the availoable width and divide what's left among the panels)
			var width	= ((panel.tabWidth)?panel.tabWidth:(this.width - 100) / this.panels.length);

			tab.title	= panel.hoverText;
			tab.style.width = width + "px";
			totalWidth 	-= width;
			//for ForeFox only, also subtract the width of the left and right borders
			if (!document.all) totalWidth -= 2;
			tabs.appendChild(tab);

			if (this.ulcImageCurrent)
				{
				var ulc		= document.createElement("img");
				ulc.className	= "ulc";
				ulc.src		= (currentTab?this.ulcImageCurrent:this.ulcImage);
				tab.appendChild(ulc);
				}

			if (this.urcImageCurrent)
				{
				var urc		= document.createElement("img");
				urc.className	= "urc";
				urc.src		= (currentTab?this.urcImageCurrent:this.urcImage);
				tab.appendChild(urc);
				}

			var shell = (currentTab)?document.createElement("div"):document.createElement("a");
			shell.innerHTML	= (panel.tabText == "")?("Tab " + (x + 1)):panel.tabText;
			if (panel.tabText2 != "")
				{
				shell.innerHTML += "<br>" + panel.tabText2;
				shell.className = "twoLines";
				}
			else
				shell.className = "oneLine";
			if (!currentTab)
				{
				shell.href	= "javascript:;";
				shell.me		= this;
				shell.tabNumber	= x;
				shell.onclick	= function(){this.me.showPanel.call(this.me, this.tabNumber);};
				}
			tab.appendChild(shell);
			}
		var tabFiller		= document.createElement("div");
		tabFiller.className	= "tabFiller";
		tabFiller.style.width	= (totalWidth - this.tabBarExcessWidth) + "px";
		tabs.appendChild(tabFiller);
		}
	this.buildControls = function()
		{
		if (this.showCountdown)		this.buildTimerControl(this.controlsTag);
		if (this.showPageOf)		this.buildPageOfControl(this.controlsTag);
		if (this.showNavigation)	this.buildPrevControl(this.controlsTag);
		if (this.showOnOff)		this.buildStartStopControl(this.controlsTag);
		if (this.showNavigation)	this.buildNextControl(this.controlsTag);

		if	(	this.showCountdown
			||	this.showNavigation
			||	this.showOnOff
			||	this.showPageOf
			)
			this.controlsTag.style.display = "";
		else
			this.controlsTag.style.display = "none";
		}
	this.buildInterior = function()
		{
		this.panelTag.innerHTML = this.panels[this.currentPanel].tag.innerHTML;
		}
	//================================
	//overwritable composition methods
	//================================
	this.buildPrevControl = function(parent)
		{
		if (this.prevControl == null)
			{
			this.prevControl		= document.createElement("a");
			this.prevControl.me		= this;
			this.prevControl.className	= "carouselControl carouselPrev";
			this.prevControl.href		= "javascript:;";
			this.prevControl.onclick	= function(){this.me.prev.call(this.me);};
			this.prevControl.innerHTML	= (this.prevImage)?"<img src='" + this.prevImage + "'>":"&laquo; Previous";
			parent.appendChild(this.prevControl);
			}
		}
	this.buildNextControl = function(parent)
		{
		if (this.nextControl == null)
			{
			this.nextControl		= document.createElement("a");
			this.nextControl.me		= this;
			this.nextControl.className	= "carouselControl carouselNext";
			this.nextControl.href		= "javascript:;";
			this.nextControl.onclick	= function(){this.me.next.call(this.me);};
			this.nextControl.innerHTML	= (this.nextImage)?"<img src='" + this.nextImage + "'>":"Next &raquo;";
			parent.appendChild(this.nextControl);
			}
		}
	this.buildStartStopControl = function(parent)
		{
		if (this.onOffControl == null)
			{
			this.onOffControl		= document.createElement("a");
			this.onOffControl.me		= this;
			this.onOffControl.className	= "carouselControl carouselOnOff";
			this.onOffControl.href		= "javascript:;";
			parent.appendChild(this.onOffControl);
			}
		if (this.running == true)
			{
			this.onOffControl.onclick	= function(){this.me.stop.call(this.me);};
			this.onOffControl.innerHTML	= (this.stopImage)?"<img src='" + this.stopImage + "'>":"|";
			}
		else
			{
			this.onOffControl.onclick	= function(){this.me.start.call(this.me);};
			this.onOffControl.innerHTML	= (this.startImage)?"<img src='" + this.startImage + "'>":"|";
			}
		}
	this.buildPageOfControl = function(parent)
		{
		if (this.pageOfControl == null)
			{
			this.pageOfControl		= document.createElement("span");
			this.pageOfControl.className	= "carouselControl carouselPgOf";
			parent.appendChild(this.pageOfControl);
			}
		var stuffToShow			= this.pageOfFormat.replace(/%1/, this.currentPanel + 1);
		stuffToShow			= stuffToShow.replace(/%2/,this.panels.length);
		this.pageOfControl.innerHTML	= stuffToShow;
		}
	this.buildTimerControl = function (parent)
		{
		if (this.countdownImageCount)
			{
			if (this.timerControl1 == null)
				{
				this.timerControl1		= document.createElement("img");
				this.timerControl1.me		= this;
				this.timerControl1.style.cursor	= "hand";
				parent.appendChild(this.timerControl1);
				}
			this.timerControl1.src			= this.countdownImageFormat.replace(/%1/,this.expiredWidth);
			if (this.running)
				{
				this.timerControl1.onclick	= function(){this.me.stop.call(this.me);};
				this.timerControl1.title	= this.countdownStopPrompt;
				}
			else
				{
				this.timerControl1.onclick	= function(){this.me.start.call(this.me);};
				this.timerControl1.title	= this.countdownStartPrompt;
				}
			}
		else
			{
			if (this.timerControl1 == null)
				{
				this.timerControl1		= document.createElement("span");
				this.timerControl1.className	= "carouselTimer";

				this.timerControl2		= document.createElement("span");
				this.timerControl2.className	= "carouselExpired";
				this.timerControl1.appendChild(this.timerControl2);

				this.timerControl3		= document.createElement("span");
				this.timerControl3.className	= "carouselRemaining";
				this.timerControl1.appendChild(this.timerControl3);

				parent.appendChild(this.timerControl1);
				}
			this.timerControl2.style.width	= this.expiredWidth + "px";
			this.timerControl3.style.width	= (this.countdownWidth - this.expiredWidth) + "px";
			}
		}
	this.tagPanelItem = function(panelElement, bodyTags, subContentGroup)
		{
		var combinedTags = bodyTags;	//start by copying the body's tags
		var elementType = panelElement.tagName.toUpperCase();
		if (elementType == "A" || elementType == "FORM")
			{
			var needCG	= true;
			var needSCG	= true;
			if (panelElement.sdcTags)	//if element's already tagged, check to see what it's missing
				{
				if (panelElement.sdcTags.indexOf("WT.cg_n") > -1)	needCG = false;
				if (panelElement.sdcTags.indexOf("WT.cg_s") > -1)	needSCG = false;
				combinedTags += "," + panelElement.sdcTags;	//add the element's tags
				}
			if (needCG == true)
				combinedTags += ",'WT.cg_n':'Carousel'";
			if (needSCG == true)
				combinedTags += ",'WT.cg_s':'" + escape(subContentGroup) + "'";
			panelElement.sdcTags = combinedTags;
			}

		if (elementType == "FORM")
			//may also need to add the submit handler
			if (panelElement.onsubmit)
				panelElement.onsubmit = "sdcCollector.recordFormTags(this);" + panelElement.onsubmit + "anonymous();";
			else
				panelElement.onsubmit = "sdcCollector.recordFormTags(this);";

		for (var x = 0; x < panelElement.childNodes.length; x++)
			{
			var node = panelElement.childNodes[x];
			if (node.tagName)
				this.tagPanelItem(node, bodyTags, subContentGroup);
			}
		}

	this.homeTag.className = "carousel";
	this.homeTag.style.width = this.width + "px";

	if (this.countdownImageCount)
		{
		this.countdownWidth = this.countdownImageCount;
		for (var x = 0; x <= this.countdownImageCount; x++)
			{
			var src = this.countdownImageFormat.replace(/%1/, x);
			preloadImage(src);
			}
		}
	if (this.prevImage)		preloadImage(this.prevImage);
	if (this.nextImage)		preloadImage(this.nextImage);
	if (this.stopImage)		preloadImage(this.stopImage);
	if (this.startImage)		preloadImage(this.startImage);
	if (this.ulcImageCurrent)	preloadImage(this.ulcImageCurrent);
	if (this.urcImageCurrent)	preloadImage(this.urcImageCurrent);
	if (this.ulcImage)		preloadImage(this.ulcImage);
	if (this.ulcImage)		preloadImage(this.ulcImage);

	if(typeof sdcCollector=='object')			//if we're tagging
		{
		//find the body tag and capture its sdcTags
		var bodyTags = "";
		var bodyElement = document.getElementsByTagName("body")[0];
		if (bodyElement)
			{
			sdcCollector.elevateAttribute(bodyElement, "sdcTags");
			bodyTags = bodyElement.sdcTags;
			}

		for (var x = 0; x < this.panels.length; x++)	//iterate through the panels
			{
			var panel = this.panels[x].tag;

			//the subContent Group is one of the following
			//1) the tab text
			var subContentGroup = "";
			if (panel.tabText)
				subContentGroup += panel.tabText;
			if (panel.tabText2)
				subContentGroup += " " + panel.tabText2;
			subContentGroup = subContentGroup.trim();

			//2) the hover text
			if (subContentGroup == "" && panel.hoverText)
				subContentGroup = panel.hoverText.trim();

			//3) the panel's "title" (stuff in the 1st <div>) for MerckSource
			if (subContentGroup == "")
				{
				//try to isolate the panel's "title"
				if (panel.childNodes.length > 0)
					{
					var child =  panel.childNodes[0];
					if (child.childNodes.length > 0)
						{
						child = child.childNodes[0];
						if (child.tagName.toUpperCase() == "DIV");
							subContentGroup = sdcCollector.innerText(child).trim();
						}
					}
				}

			//4) the panel's text
			if (subContentGroup == "")
				subContentGroup = sdcCollector.innerText(panel).trim();

			//5) "unknown"
			if (subContentGroup == "")
				subContentGroup == "unknown";

			//max of 50 characters
			if (subContentGroup.length > 50)
				subContentGroup = subContentGroup.substr(0,50) + " ...";

			this.tagPanelItem(panel, bodyTags, subContentGroup);	//tag each one of them
			}
		}

	this.reset();
	this.start();
	}

function showAllAttributes(item)
		{
		var info = "";
		for (var attr in item)
			info += attr + " = " + item[attr] + "<br>";
		var win = window.open("","");
		win.document.write(info);
		win.document.close();
		}
