/* Regenerated Cache */
var allVisible = false;
var shownSrc = '/images/icons/more.gif';
var hiddenSrc = '/images/icons/less.gif';
var shownClass = 'show';
var hiddenClass = 'hide';
var fadeSpeed = 5;
/*************************************************************************
DO NOT CHANGE ANYTHING BELOW THIS LINE!
*************************************************************************/
var Get = function (field)
{
	// check if the field supplied is not already an object
	try { return (field.getAttribute('id') ? field : field); } catch( e )
	{
		if( document.getElementById )
			return document.getElementById(field);
		else if ( document.all )
			return document.all[field];
		else return document.field;
	}
}
/**
* Hides a block-level element
* @param String field
* @return false
*/
function Hide( field )
{
	var tmp = Get(field);
	if( tmp )
	{
		if( !tmp.className ) tmp.className = shownClass;
		tmp.className = tmp.className.replace(new RegExp("\\b"+shownClass+"\\b"), (" "+hiddenClass) );
		try { SwitchImage( field, 'm_'+field, shownSrc, hiddenSrc ); } catch (e) {}
	}
	return false;
}
/**
* Displays a block-level element
* @param String field
* @return false
*/
function Show( field )
{
	var tmp = Get(field);
	if( tmp )
	{
		if( !tmp.className ) tmp.className = "hide";
		tmp.className=tmp.className.replace(new RegExp("\\b"+hiddenClass+"\\b"), (" "+shownClass) );
		try { fadeIn( field, 0 ); } catch( e ) {} // let the user see space before displaying contents
		try { SwitchImage( field, 'm_'+field, shownSrc, hiddenSrc ); } catch (e) {}
	}
	return false;
}

/**
* Determines if a field is expanded.
* @param Field field
* @return bool
*/
function IsShown( field )
{
	var tmp = Get(field);
	if( tmp )
		return !tmp.className ? true : 
			( tmp.className.match(new RegExp("\\b"+shownClass+"\\b")) ? 
				true : 
				false );
	return false;
}

/**
* Expands all hidden text areas
* @param String[] items	An array of ID's to expand
* @return false
*/
function ShowAll( items )
{
	for(var i=0; i<items.length; i++)
	{
		if(	!IsShown( items[i] ) )
			Show( items[i] );
	}
	allVisible=true;
	return false;
}

/**
* Hides all expanded text areas
* @param String[] items	An array of ID's to expand
* @return false
*/
function HideAll( items )
{
	for(var i=0; i<items.length; i++)
	{
		if( IsShown( items[i] ) )
			Hide( items[i] );
	}
	allVisible=false;
	return false;
}

/**
* Hides or shows the chosen field, if it exists
* @param String field
* @return false
*/
function HideShow( field )
{
	IsShown( field ) ?
		Hide( field ):
		Show( field );
	return false;
}

/**
* Toggles displaying all expanded text areas
* @param String[] items An array of ID's to expand
* @return bool
*/
function HideShowAll( items )
{
	return allVisible ?
		HideAll( items ):
		ShowAll( items );
}

function HideExcept( items, exception )
{
	HideAll( items );
	Show( exception );
	return false;
}

/**
* Switches the icon for 'expanded' and 'hidden' states
* @param Field id
* @param String shownSrc
* @param String hiddenSrc
* @return bool
*/
var SwitchImage = function(id, imgId, shownSrc, hiddenSrc)
{
	var tmp = Get(id);
	if( tmp )
	{
		imgId = Get(imgId);
		if( imgId )
			imgId.src = IsShown(id)?hiddenSrc:shownSrc;
		return true;
	}
	return false;
}

// The following functions were modified from: www.bmgadg.com
/**
* Fades an object into view from 0% opacity
* @param String elt
* @param int amt
*/
var fadeIn = function (elt, amt) {
	amt = !amt?0:amt;
	if(amt < 100) {
		setOpacity(elt, amt);
		amt += fadeSpeed;
		setTimeout("fadeIn( '"+elt+"', "+amt+" )", fadeSpeed);
    }
}
/**
* Fades an object out of view from 100% opacity
* @param String elt
* @param int amt
*/
var fadeOut = function (elt, amt) {
	amt = !amt?100:amt;
	if(amt > 0) {
		setOpacity(elt, amt);
		amt -= fadeSpeed;
		setTimeout("fadeIn( '"+elt+"', "+amt+" )", fadeSpeed);
    }
}

/**
* Sets the opacity of an id'ed element.
* @param String elt
* @param Int amt
*/
function setOpacity(elt, amt) {
	var obj = Get(elt);
	
	amt = (amt <= 0)?0:amt;
	amt = (amt >= 100)?100:amt;
	var val = amt/100;
	
	obj.style.filter = val>.95?null:"alpha(opacity:"+amt+")";  	// IE
	obj.style.KHTMLOpacity = val>=.95?null:val;  			// Safari<1.2, Konqueror
	obj.style.MozOpacity = val>=.95?null:val;  				// Mozilla and Firefox
	obj.style.opacity = val>=.95?null:val;					// Safari 1.2, newer Firefox and Mozilla, CSS3
}

/*** CAROUSEL ***/
/**
* Javascript Carousel
* @param Int timeout
* @return Carousel
*/
function Carousel( timeout )
{
	this.timeout = timeout?timeout:5; // in seconds
	this.elements = null;
	this.timer = null;
}
/**
* Sets the html items to rotate through
* @param Array elts
* @note: The elements MUST be assigned using the div className carouselItem
* @return Array
*/
Carousel.prototype.SetElements = function(elts) { this.elements = elts; return this.GetElements(); }
/**
* Returns the elements assigned
* @return Array
*/
Carousel.prototype.GetElements = function() { return this.elements; }
/**
* Returns the timeout object assigned by setTimeout
* @return timeout
*/
Carousel.prototype.GetTimer = function() { return this.timer; }
/**
* Assigns the timeout object for re-use
* @return timeout
*/
Carousel.prototype.SetTimer = function( timer ) { this.timer=timer; return this.GetTimer(); }
/**
* Returns the timer timeout assigned by the Carousel constructor
* Note: this will return the amount in milliseconds. Therefore, 5 (5 seconds) is equivalent to 5000m.
* @return Int
*/
Carousel.prototype.GetTimeout = function() { return this.timeout*1000; }
/**
* Halts the carousel. Provides user control if they see something they want,
* or the carousel is causing their browser to drag.
* @return false
*/
Carousel.prototype.Stop = function() { clearTimeout( this.GetTimer() ); return false; }
/**
* Rotates through the carousel items
* @return timeout
*/
Carousel.prototype.Rotate = function()
{
	var index=0;
	var elts = this.GetElements();
	for( var i=0;i<elts.length;i++ )
	{
		if( IsShown(elts[i].getAttribute('id')) )
		{
			index = (i+1)>=elts.length?0:i+1;
			HideExcept( this.GetElements(), this.GetElements()[index].getAttribute('id') );
			return this.SetTimer( setTimeout( "Carousel.Rotate()", this.GetTimeout() ) );
		}
	}
	// technically, we should never reach this code, but in case we do...
	return false;
}
/**
* Jumps to the element hit by the user
* @param String id -- The element id assigned by Carousel.DrawControls()
* @return false
*/
Carousel.prototype.Display = function( id )
{
	HideExcept( this.GetElements(), id );
	return this.Stop();
}
/**
* Renders anchors on the page within the block assigned to id 'carouselControls'.
*/
Carousel.prototype.DrawControls = function()
{
	var controls = Get('carouselControls');
	if( controls ) {
		// get all the items we need to rotate through
		var elts = Get('carousel').getElementsByTagName('div');
		// create a container for the ids
		var items = new Array;
		// as much of a pain this is to sort out, 
		// we'll just use a class name to assign our items
		for( var i=0; i<elts.length; i++ )
		{
			if ( elts[i].className.match(new RegExp("\\bcarouselItem\\b")) )
			{ items[i] = elts[i]; }
		}
		// assign the elements to our Carousel
		elts = this.SetElements( items );
		// begin rendering the controls
		var htm = "";
		// loop through the elements of our carousel
		for( var i=0; i<elts.length; i++)
		{
			var tId = 'cItem_'+i;
			this.elements[i].setAttribute('id', tId );
			htm += '<a href="#" onclick="return Carousel.Display(\''+tId+'\');">'+ (i+1) +'</a>'+"\n";
		}
		// add a Stop(); button so users don't go crazy
		htm += '<a href="#" onclick="return Carousel.Stop();">Stop</a>';
		document.write( htm );
		document.close(); // NEVAR forget this!
		// kick-off the carousel
		this.SetTimer( setTimeout('Carousel.Rotate()', this.GetTimeout()) );
	}
}