//	This team's JavaScript - Copyright (C) 2003-2009 Charles A Upsdell, All Rights Reserved; www.upsdell.com

var oPageStyle = new cPageStyle( 'mmba', 'Style 2008', 'Style 2004', 'Style 2007'  );


//	OnLoad Function
function myOnLoad( nTimeLimit )
  {
	oPageStyle.setActiveStylesheet();
	// Enable hovers over LI's (IE workaround)
	startList( "hormenu" );
	if ( typeof(myFilms) !== typeof(noSuchFunction) )
		myFilms();
	myGetPhoto();
	if ( typeof(cal) == 'object' )
	  {
		var myCalendarType = 'grid';
		if ( typeof(myPrintOnLoad) !== typeof(noSuchFunction) )
			myCalendarType = myPrintOnLoad();
		if ( typeof(cal.toNewsHTML) !== typeof(noSuchFunction) )
			cal.toNewsHTML();
		if ( typeof(cal.toCheckHTML) !== typeof(noSuchFunction) )
			cal.toCheckHTML();
		if ( typeof(cal.toCalendarHTML) !== typeof(noSuchFunction) )
			cal.toCalendarHTML( myCalendarType, 'ins_calendar_dump', window.location.hash );
		if ( typeof(cal.toGamesHTML) !== typeof(noSuchFunction) )
			cal.toGamesHTML();
		if ( typeof(calendarTournament) !== typeof(noSuchData) )
			cal.toTournamentGamesHTML( calendarTournamentID, calendarTournament );
	  }
	if ( typeof(mySponsorList) !== typeof(noSuchData) )
		mySponsorList.insertHTML();
	myMarkAnchor();
	if ( typeof(myReportAnyBrowserUpdate) !== typeof(noSuchFunction) )
		myReportAnyBrowserUpdate( '../../../BrowserNews/', getElement('ins_BrowserUpdate') );
  }

// cRandomizedList Class
function cRandomizedList ( length )
{
	if ( arguments.length < 1 )
		length = 52;
	this.length = length;		// Length of list of integers
	this.index = length;		// Index into list of integers
	this.list = new Array();	// List of integers
	return;
}

// Method to randomize the list in a cRandomizedList object
cRandomizedList.prototype.randomize = function ()
{
	var i, j, randomInteger;
	for ( i = 0; i < this.length; ++i )
		this.list[i] = i;
	for ( i = 0; i < this.length; ++i )
	  {
		j = i + Math.floor( (this.length-i)*Math.random() );
		randomInteger = this.list[j];
		this.list[j] = this.list[i];
		this.list[i] = randomInteger;
	  }
	return;
}

// Method to get next random number from cRandomizedList object
cRandomizedList.prototype.getNumber = function ()
{
	if ( this.length == this.index )
	  {
		this.randomize();
		this.index = 0;
	  }
	var value = this.list[this.index++];
	return( value );
}

// Function to write code to display a randomly-selected photo for home page. myRandomPhoto[] has ID and list of photos.
function myGetPhoto ( nOldImage )
{
	if ( typeof(myRandomPhoto) != typeof(noSuchArray) )
	  {
		var o = getElement( myRandomPhoto[0] );
		if ( o == null )
			return;
		if ( arguments.length < 1 )
			nOldImage = 0;
		var nImage;
		do { nImage = 1 + myRandomizedList.getNumber() }
			while (nImage == nOldImage);
		var sPhoto = myRandomPhoto[nImage];
		var photo, title;
		var photo_length = sPhoto.indexOf(' ');
		if ( photo_length == -1 )
		  {
			photo = sPhoto;
			title = '';
		  }
		else
		  {
			photo = sPhoto.substring(0,photo_length);
			title = sPhoto.substring(photo_length+1);
		  }
		var sHTML = '<p class="tiny">';
		sHTML += '<img src="img/' + photo + '" onclick="myGetPhoto(' + nImage + ');" alt="Baseball photo" />';
		if ( title != '' )
			sHTML += '<br />' + title;
		sHTML += '</p>';
		o.innerHTML = sHTML;
	  }
}


