/* 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 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' );
	}
}

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