/* Set the target and class attributes for all <a> tags that have rel="external"  */
function SetupExternalLinks() {
	var elems = getElementsByTagAndClassName( "A", "" );
	for ( var i = 0; i < elems.length; i++ ) {
		var elem = elems[ i ];
		// if ( elem.getAttribute( "href" ) && elem.getAttribute( "rel" ) == "external" ) {
		var _href = getNodeAttribute( elem, "href" );
		var _rel = getNodeAttribute( elem, "rel" );
		var _class = "external";
		var _target = "_blank";
		if ( _href && _rel == "external" ) {
			setNodeAttribute( elem, "target", _target );
			setNodeAttribute( elem, "class", "external" );
		}
	}
};

/* Add class "rowodd" to all tables that have "zebra" as a class attribute value (for striping) */
function ZebraTable() {
	var TableList = getElementsByTagAndClassName( "TABLE", "zebra" );
	for ( var i = 0; i < TableList.length; i++ ) {
		var Table = TableList[ i ];
		for ( var j = 0; j < Table.rows.length; j += 2 ) {
			addElementClass( Table.rows[ j ], "rowodd" );
		}
	}
};

/* Launch flash swf objects */
function LaunchFlashSWFObjects() {
	var FlashObjectList = getElementsByTagAndClassName( "DIV", "flash" );
	for ( var i =0; i < FlashObjectList.length; i++ ) {
		FlashObjectList[ i ].SWFObject = new SWFObject( 
			getNodeAttribute( FlashObjectList[ i ], "SWFfile" ),
			getNodeAttribute( FlashObjectList[ i ], "SWFid" ),
			getNodeAttribute( FlashObjectList[ i ], "SWFwidth" ),
			getNodeAttribute( FlashObjectList[ i ], "SWFheight" ),
			getNodeAttribute( FlashObjectList[ i ], "SWFversion" ),
			getNodeAttribute( FlashObjectList[ i ], "SWFbckgrnd" )
		);
		FlashObjectList[ i ].SWFObject.addParam( "allowScriptAccess", "always" );
		FlashObjectList[ i ].SWFObject.addParam( "wmode", getNodeAttribute( FlashObjectList[ i ], "SWFwmode" ) );
		FlashObjectList[ i ].SWFObject.addParam( "flashVars", getNodeAttribute( FlashObjectList[ i ], "flashVars" ) );
		FlashObjectList[ i ].SWFObject.write( getNodeAttribute( FlashObjectList[ i ], "id" ) );
	}
}

/* Launch silverlight objects */
function LaunchSilverlightObjects() {
	var SilverlightObjectList = getElementsByTagAndClassName( "DIV", "silverlight" );
	for ( var i =0; i < SilverlightObjectList.length; i++ ) {
		SilverlightObjectList[ i ].SilverlightObject = new Silverlight.createObject(
			getNodeAttribute( SilverlightObjectList[ i ], "SLfile" ),
			SilverlightObjectList[ i ],
			getNodeAttribute( SilverlightObjectList[ i ], "SLid" ),
			{ width : getNodeAttribute( SilverlightObjectList[ i ], "SLwidth" ),
				height : getNodeAttribute( SilverlightObjectList[ i ], "SLheight" ),
				inplaceInstallPrompt : getNodeAttribute( SilverlightObjectList[ i ], "SLinstall" ),
				background : getNodeAttribute( SilverlightObjectList[ i ], "SLbckgrnd" ),
				isWindowless : getNodeAttribute( SilverlightObjectList[ i ], "SLwindowless" ),
				framerate : getNodeAttribute( SilverlightObjectList[ i ], "SLframerate" ),
				version : getNodeAttribute( SilverlightObjectList[ i ], "SLversion" )
			},
			{ onError : null,
				onLoad : null
			},
			null
		);
	}
}

/* Launch calendar objects */
function LaunchCalendarObjects() {
	var CalendarTableList = getElementsByTagAndClassName( "TABLE", "calendar" );
	for ( var i = 0; i < CalendarTableList.length; i++ ) {
		CalendarTableList[ i ].calendar = new calendar( CalendarTableList[ i ].id, new Date() );
		CalendarTableList[ i ].calendar.write();
	}
}

/* Make all parallel columns an equal height */
function EqualizeParallelColumns(){
	var ParallelColsParentsList = getElementsByTagAndClassName( "DIV", "parallelcols" );
	for ( var i = 0; i < ParallelColsParentsList.length; i++ ) {
		var ParallelColsList = getElementsByTagAndClassName( "DIV", "parcol", ParallelColsParentsList[ i ] );
		tallest = 0;
		for ( var j = 0; j < ParallelColsList.length; j++ ) {
			dims = getElementDimensions( ParallelColsList[ j ] );
			if ( dims.h > tallest ) { tallest = dims.h; }
		}
		for ( var j = 0; j < ParallelColsList.length; j++ ) {
			dims = getElementDimensions( ParallelColsList[ j ] );
			dims.h = tallest;
			setElementDimensions( ParallelColsList[ j ], dims, 'px' );
		}
		dims = getElementDimensions( ParallelColsParentsList[ i ] );
		dims.h = tallest;
		setElementDimensions( ParallelColsParentsList[ i ], dims, 'px' );
	}
}

/* Quick and easy redirect function to send browser to another location */
function redirect() {
	var _href = getNodeAttribute( this, 'href' );
	if (_href) { document.location.href = _href; }
}

/* Use calling HTML element's src, href, title, alt, and tgtimg attributes to cause the image element specified by tgtimg to load a particular image.  Used mostly for thumbnail rollovers. */
function setImgSrc() {
	var _src = getNodeAttribute( this, 'src' );
	var _href = getNodeAttribute( this, 'href' );
	var _tgtimg = getNodeAttribute( this, 'tgtimg' );
	var _title = getNodeAttribute( this, 'title' );
	var _alt = getNodeAttribute( this, 'alt' );
	var _img = $( _tgtimg );
	if (_src) {
		if ( _img ) {
			_img.src = _src;
			_img.title = _title;
			_img.alt = _alt;
			currentWindow().status = _href;
		}
	}
}

/* Go through DOM and set up onmouseover and onclick calls for an images of class "tbrollover" */
function Setuptbrollover() {
	var elems = getElementsByTagAndClassName( "img", "tbrollover" );
	for ( var i = 0; i < elems.length; i++ ) {
		var elem = elems[ i ];
		connect( elem, 'onmouseover', setImgSrc );
		connect( elem, 'onclick', redirect );
	}
};

/* Fire these functions at document load */
/* addLoadEvent( SetupExternalLinks ); */
/* addLoadEvent( ZebraTable ); */
addLoadEvent( LaunchFlashSWFObjects );
/* addLoadEvent( LaunchSilverlightObjects ); */
/* addLoadEvent( LaunchCalendarObjects ); */
/* addLoadEvent( EqualizeParallelColumns ); */
/* addLoadEvent( Setuptbrollover ); */
