function Sidebar( id )
{
	// This is the parent tabPanel's id
	//			It has the form 'Tab-x'
	this.tabId = id;
	
	// Let's make these all base 0
	this.images = [];
	this.links = [];
	this.linkPaths = [];
	this.banners = [];
	this.linkedHtml = [];
}

// The sidebar consists of scrolling images each with a link to some html that is presented in the main_content
Sidebar.prototype.LoadInto = function( divId, xml )
{
	// First load all of the items
	var items = xml.getElementsByTagName( 'item' );

	// Here are the scroll arrows actions
	var text = '<div class="actions"><a class="nextPage browse down"></a><a class="prevPage browse up"></a></div>';
	
	// Here is the wrapper for the scrollables
	text += '<div class="scrollable vertical"><div class="items">';
	
	// Now the images and the links associated with each of the items
	this.images = xml.getElementsByTagName( 'image' );
	this.captions = xml.getElementsByTagName( 'caption' );
	this.links = xml.getElementsByTagName( 'link' );
	this.linkPaths = xml.getElementsByTagName( 'linkPath' );
	this.banners = xml.getElementsByTagName( 'banner' );

	var len = this.images.length;
	for( var i=0; i<len; i++)
	{
		var image = '';
		var caption = '';
		try
		{
			image = this.images[i].childNodes[0].nodeValue;
			caption = this.captions[i].childNodes[0].nodeValue;
		}
		catch(e)
		{}
		
		text += '<div class="sidebar_' + this.tabId + '" style="text-align:center; color: #FF9933; font-size: 14px;">' + caption + '<img id="sidebar_' + this.tabId + '_' + i + '"src="' + image + '" /></div>';
	}
	
	text += '</div></div>';
	
	// Load into the div
	$('#' + divId).html( text );
	
	// Now load the click function for each image
	//		tabId has the form 'Tab-x'
	$('.sidebar_' + this.tabId + ' img').click( function() 
		{
//alert( 1);
			// Get the image id, since it has the tabPanel id and the ctr into the html list
			// imgId has the form 'sidebar_Tab-x_y' where 'y' is the link number
			var imgId = $(this).attr("id");

			var first = imgId.indexOf( '_' );
			var second = imgId.indexOf( '_', first + 1 );
			
			// tabId has the form 'Tab-x'
			var tabId = imgId.slice( first + 1, second );
			
			// These should be equal
			if( gCurrTab != tabId )
			{
				// we are hosed
				location.hash = '#Tab-0_link-0';
				return;
			}
			
			// Now get the link number
			var linkIndex = imgId.substr( second + 1 );

			// Get the tab  corresponding to this sidebar and tell it to load link index number 'linkIndex'.
			// Also change the banner
			gTabs.LoadHtml( tabId, linkIndex );
//alert( tabId + ', ' +  linkIndex);
		   
			// Now change the location
			//		gCurrLink has the form 'link-y'
			var link = '#' + tabId + '_' + 'link-' + linkIndex;
			
			if( gCurrInfo.length > 0 )
				link += '_info=' + gCurrInfo;
//alert( link );

			try
			{
				gPageTracker._trackPageview( '/' + link);
			} catch(err) {}
			
			if( location.hash != link )
			   location.hash = link;
		}
	);
}

Sidebar.prototype.LoadBanner = function( linkCtr )
{
	// If it doesn't exist, bypass it.
	var bannerImg;
	try
	{
		bannerImg = this.banners[ linkCtr ].childNodes[0].nodeValue;
		gBanner.LoadPanelImage( bannerImg );
	} catch(e)
	{}
}

Sidebar.prototype.GetContent = function( linkCtr )
{
	return( this.linkedHtml[ linkCtr ] );
}

// This is any set of chars
Sidebar.prototype.GetLinkPath = function( linkCtr )
{
	// If it doesn't exist send back null
	var linkPath;
	try
	{	
		return (this.linkPaths[ linkCtr ].childNodes[0].nodeValue);
	} catch(e)
	{}
	
	return null;
}

// This is in the form 'Tab-x_link-y'
Sidebar.prototype.GetLink = function( linkCtr )
{
	// If it doesn't exist send back null
	var link;
	try
	{	
		link = this.links[ linkCtr ].childNodes[0].nodeValue;
		return link;
	} catch(e)
	{}
	
	return null;
}


Sidebar.prototype.AddPathHtml = function( path, content )
{
	var linkCtr = this.FindCtrFromPath( path );	
	if( linkCtr != -1 )
	   this.linkedHtml[ linkCtr ] = content;
}

Sidebar.prototype.FindCtrFromPath = function( linkPath )
{
	var len = this.linkPaths.length;
	var linkPaths = this.linkPaths;
	for( var i=0; i<len; i++ )
	{
		var checkPath = linkPaths[i].childNodes[0].nodeValue;
		if(  checkPath == linkPath )
			return i;
	}
	
	return -1;
}

Sidebar.prototype.FindLink = function( linkPath )
{
	var ctr = this.FindCtrFromPath( linkPath );
	if( ctr == -1 )
		return -1;
		
	return( this.links[ ctr ].childNodes[0].nodeValue );
}
