/********************************************************************************
	This script is copyrighted by Orange Street Softare
		www.orangestreetsoftware.com
	
	It requires: 
		util.js

********************************************************************************/

// ================================== GLOBAL VARIABLES ====================================================
// gloabl variable containg object with all menu setup information, 
// needs to be global within this script for event handlers (sorry)
var the_right_bar_container;

// these constants are indexes into the image_urls array in the container
var CI_TOP_LEFT_IMAGE = 0;
var CI_TOP_BG_IMAGE = 1;
var CI_TOP_TILER = 2;

// ================================== UTITLITY FUNCTIONS ==================================================

// --------------------------------------------------------------------------------------------------------
// single point of call for all document writes (usefull for debuging etc.)
function right_bar_write ( s_text )
{

/*	debung stuff to show all tags as text
	s_text = s_text.replace ( /</g, "&lt;");
	s_text = s_text.replace ( />/g, "&gt;");
	document.writeln ( s_text + "<br>" );
*/
	if (the_right_bar_container.allow_render_caching)
	{
		if (!the_right_bar_container.is_cached)
			the_right_bar_container.render_cache = the_right_bar_container.render_cache + s_text;
	}
	else
		doc_write ( s_text );
}

// --------------------------------------------------------------------------------------------------------
// this is used to flush ot the cached right_bar_writes, 
// should be called afeter all other rendering code has finished, but before setup code
function right_bar_flush ()
{
	if (the_right_bar_container.allow_render_caching)
	{
		doc_write ( the_right_bar_container.render_cache );
		the_right_bar_container.is_cached = true;
	}
}

// ===================================== RENDERING FUNCTIONS ==============================================

// --------------------------------------------------------------------------------------------------------
// use this to draw the right bar, this will need to be called for each content page refresh
function render_right_bar ( the_container )
{
	// storing the menu setup object global to ease accessing metrics and urls
	//    er, sorry.
	the_right_bar_container = the_container;

	// make the right bar div tag, including banner image and redirection form	
	make_right_bar ();

	// flush the cached document writes if caching used
	right_bar_flush ();
}


// --------------------------------------------------------------------------------------------------------
// render out the right bar
function make_right_bar ()
{
var n_item_index;

	// open div / layer
	if ( document.layers )
		right_bar_write ( '<layer name="rightbar" pageY=127 pageX=615 width=165 z-index=1 visibility="show">' );
	else
		right_bar_write ( '<div id="rightbar" style="position: absolute; top: 127px; left: 615px; width: 165px; z-index: 1; visibility: visible;">' );

	// start table and dump out banner
	right_bar_write ( '<table width="165" border="0" cellspacing="0" cellpadding="0">' );
	right_bar_write ( '<tr><td width="165"><img src="' + the_right_bar_container.banner_image_url + '" alt=""></td></tr>' );
	
	// loop thru the items in the right bar and make appropriate item tags
	for ( n_item_index = 0 ; n_item_index < the_right_bar_container.item_count ; n_item_index++ )
	{
		// dump out the hyperlinked item
		right_bar_write ( '<tr><td><a href="javascript: the_right_bar_container.item_click (' + n_item_index + ');"><img src="' + the_right_bar_container.item_image_urls[n_item_index] + '" border="0"></a></td></tr>' );
	}

	// finish table
	right_bar_write ( '</table>' );

	// close div / layer
	if ( document.layers )
		right_bar_write ( '</layer>' );
	else
		right_bar_write ( '</div>' );
}

// --------------------------------------------------------------------------------------------------------
