/*
Script by FPMC at http://jsarchive.8m.com
Submitted to JavaScript Kit (http://javascriptkit.com)
For this and 400+ free scripts, visit http://javascriptkit.com
Edited 5-4-2007 by PH
*/

// Post quote of the day
var quotesno = 60;
var startday = 120;
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var jday = (month * 30) + day;
var currentQuote = 0;

if(jday < startday || jday > (startday + quotesno))
{
	currentQuote = Math.floor(Math.random() * quotesno);
}
else
{
	currentQuote = jday - startday;
}

var quotes = [
"'People ask me what I do in winter when there's no baseball. I'll tell you what I do. I stare out the window and wait for spring.' ~Rogers Hornsby", 
"'80 percent of the balls that don't reach the hole, don't go in.' - on golf  ~ Yogi Berra",
"'The wind always seems to blow against catchers when they are running.'  ~ Yogi Berra",
"'A good ball club.' - on what makes a good manager  ~ Yogi Berra",
"'If you can't imitate him, don't copy him.'  ~ Yogi Berra",
"'Baseball is 90 percent mental. The other half is physical.'  ~ Yogi Berra",
"'You can observe a lot by watching.'  ~ Yogi Berra",
"'In baseball, you don't know nothing.'  ~ Yogi Berra",
"'A nickel ain't worth a dime anymore.'  ~ Yogi Berra",
"'It's like deja vu all over again.'  ~ Yogi Berra",
"'If you come to a fork in the road, take it.'  ~ Yogi Berra",
"'I usually take a two-hour nap, from one o'clock to four.'  ~ Yogi Berra",
"'If the people don't want to come out to the park, nobody's going to stop them.'  ~ Yogi Berra",
"'Why buy good luggage? You only use it when you travel.'  ~ Yogi Berra",
"'Think! How the hell are you gonna think and hit at the same time?'  ~ Yogi Berra",
"'I didn't really say everthing I said.'  ~ Yogi Berra",
"'Bill Dickey is learning me his experience.'  ~ Yogi Berra",
"'You've got to be very careful if you don't know where you are going because you might not get there.'  ~ Yogi Berra",
"'If you don't know where you are going, you will wind up somewhere else.'  ~ Yogi Berra",
"'Nobody goes there anymore because it's too crowded.'  ~ Yogi Berra",
"'I'm not going to buy my kids an encyclopedia. Let them walk to school like I did.'  ~ Yogi Berra",
"'I think Little League is wonderful. It keeps the kids out of the house.'  ~ Yogi Berra",
"'Little League Baseball is a very good thing because it keeps the parents off the streets.'  ~ Yogi Berra",
"'It gets late early out there.'  ~ Yogi Berra",
"'He hits from both sides of the plate. He's amphibious.'  ~ Yogi Berra",
"'I don't know. They had bags over their heads.' - when asked if the fans that ran naked on the field were men or women  ~ Yogi Berra",
"'I want to thank you for making this day necessary.' - on Yogi Berra Appreciation Day in St. Louis in 1947  ~ Yogi Berra",
"'The other teams could make trouble for us if they win.' - on the American League situation  ~ Yogi Berra",
"After receiving a check made out to 'Bearer' for his appearance on Jack Buck's pregame show in St. Louis: 'How long have you known me, Jack? And you still don't know how to spell my name.'  ~ Yogi Berra",
"Asked if first baseman Don Mattingly had exceeded his expectations this season: 'I'd say he's done more than that.'  ~ Yogi Berra",
"On the aquisition of fleet Ricky Henderson: 'He can run anytime he wants. I'm giving him the red light.'  ~ Yogi Berra",
"On a fancy White House dinner he attended: 'It was hard to have a conversation with anyone, there were so many people talking.'  ~ Yogi Berra",
"Reminiscing during a TV interview about New York Yankee battery mate Don Larsen's perfect game in the 1956 World Series: 'It's never happened in the World Series competition, and it still hasn't.'  ~ Yogi Berra",
"'I don't see how he lost five games during the season.' - on Sandy Koufax during the 1963 World Series. Koufax's record during the regular season was 25-5.  ~ Yogi Berra",
"'So I'm ugly. So what? I never saw anyone hit with his face.'  ~ Yogi Berra",
"'You give 100 percent in the first half of the game, and if that isn't enough in the second half you give what's left.'  ~ Yogi Berra",
"'The game isn't over until it's over.'  ~ Yogi Berra",
"'You should always go to other people's funerals, otherwise, they won't come to yours.'  ~ Yogi Berra",
"Yogi's wife Carmen: 'Yogi, you are from St. Louis, we live in New Jersey, and you played ball in New York. If you go before I do, where would you like me to have you buried?' Yogi: 'Surprise me.'  ~ Yogi Berra",
"'It ain't the heat, it's the humility.'  ~ Yogi Berra",
"'I never blame myself when I'm not hitting. I just blame the bat and if it keeps up, I change bats. After all, if I know it isn't my fault that I'm not hitting, how can I get mad at myself?'  ~ Yogi Berra",
"'The towels were so thick there I could hardly close my suitcase.'  ~ Yogi Berra",
"When told by the New York mayor's wife that he looked cool in his new summer suit, Yogi said, 'You don't look so hot yourself.'  ~ Yogi Berra",
"'I always thought that record would stand until it was broken.'  ~ Yogi Berra",
"Dining at an italian restaurant, a waitress asked Berra how many slices she should cut his pizza, he replied, 'You better make it 4, I don't think I could eat 8.'  ~ Yogi Berra",
"'We made too many wrong mistakes.'  ~ Yogi Berra",
"'This is a game to be savored, not gulped. There's time to discuss everything between pitches or between innings.' ~ Bill Veeck",
"'Pitchers, like poets, are born not made.' ~ Cy Young",
"'There have been only two geniuses in the world: Willie Mays and Willie Shakespeare.' ~ Tallulah Bankhead",
"'No matter how good you are, you're going to lose one-third of your games. No matter how bad you are you're going to win one-third of your games. It's the other third that makes the difference.' ~ Tommy Lasorda",
"'The pitcher has got only a ball. I've got a bat. So the percentage of weapons is in my favor and I let the fellow with the ball do the fretting.' ~ Hank Aaron",
"'During my 18 years I came to bat almost 10,000 times. I struck out about 1,700 times and walked maybe 1,800 times. You figure a ballplayer will average about 500 at bats a season. That means I played seven years without ever hitting the ball.' ~ Mickey Mantle",
"'Sandy's fastball was so fast, some batters would start to swing as he was on his way to the mound.' ~ Jim Murray",
"'I became a good pitcher when I stopped trying to make them miss the ball and started trying to make them hit it.' ~ Sandy Koufax",
"'When we played softball, I'd steal second base, feel guilty and go back.' ~ Woody Allen",
"'I think about the cosmic snowball theory. A few million years from now the sun will burn out and lose its gravitational pull. The earth will turn into a giant snowball and be hurled through space. When that happens it won't matter if I get this guy out.' ~Bill Lee",
"'You have two hemispheres in your brain - a left and a right side. The left side controls the right side of your body and right controls the left half. It's a fact. Therefore, left-handers are the only people in their right minds.' ~Bill Lee",
"'It took me seventeen years to get 3,000 hits in baseball. I did it in one afternoon on the golf course.' ~Hank Aaron",
"'Good pitching will always stop good hitting and vice-versa' ~Casey Stengel",
"'The future ain't what it used to be.' ~Yogi Berra",
"'Poets are like baseball pitchers. Both have their moments. The intervals are the tough things.' ~Robert Frost",
"'A baseball fan is a spectator sitting 500 feet from home plate who can see better than an umpire standing five feet away.' ~Unknown",
"'If a woman has to choose between catching a fly ball and saving infant's life, she will choose to save the infant's life without even considering if there is a man on base.' ~Dave Barry",
"'Don't look back.  Something might be gaining on you.' ~Satchel Paige",
"'Looking at the ball going over the fence isn't going to help.' ~Hank Aaron",
"'There's one word that describes baseball -- 'You never know.' ~Yogi Berra",
"'Baseball is the only field of endeavor where a man can succeed three times out of ten and be considered a good performer.' ~Ted Williams"
];

/************************************************************
//set image paths -- picnt = no of landscape pictures
************************************************************/
var counter = 0
var count = 0;
var picnt1 = 32; var picdir1 = "../Photo/2007/";
var picnt2 = 45; var picdir2 = "../Photo/2006/";
var picnt3 = 171; var picdir3 = "../Photo/Opener/";
var picnt4 = 34; var picdir4 = "../Photo/March/";
var picnt5 = 26; var picdir5 = "../Photo/State/";
var picnt6 = 20; var picdir6 = "../Photo/vadistrict/";
var picnt7 = 81; var picdir7 = "../Photo/AllStars2007/";
var picnt8 = 50; var picdir8 = "../Photo/2008Opener/";
var picnt9 = 48; var picdir9 = "../Photo/2008/";
var totpic = picnt1 + picnt2 + picnt3 + picnt4 + picnt5 + picnt6 + picnt7 + picnt8 + picnt9; 
var src = new Array(totpic);

var picno = picnt1;
var picdir = picdir1;
for(count = 0; count < picno; count++)
{
  src[counter++] = picdir + count + ".jpg";
}
picno = picnt2;
picdir = picdir2;
for(count = 0; count < picno; count++)
{
  src[counter++] = picdir + count + ".jpg";
}
picno = picnt3;
picdir = picdir3;
for(count = 0; count < picno; count++)
{
  src[counter++] = picdir + count + ".jpg";
}
picno = picnt4;
picdir = picdir4;
for(count = 0; count < picno; count++)
{
  src[counter++] = picdir + count + ".jpg";
}
picno = picnt5;
picdir = picdir5;
for(count = 0; count < picno; count++)
{
  src[counter++] = picdir + count + ".jpg";
}
picno = picnt6;
picdir = picdir6;
for(count = 0; count < picno; count++)
{
  src[counter++] = picdir + count + ".jpg";
}
picno = picnt7;
picdir = picdir7;
for(count = 0; count < picno; count++)
{
  src[counter++] = picdir + count + ".jpg";
}
picno = picnt8;
picdir = picdir8;
for(count = 0; count < picno; count++)
{
  src[counter++] = picdir + count + ".jpg";
}
picno = picnt9;
picdir = picdir9;
for(count = 0; count < picno; count++)
{
  src[counter++] = picdir + count + ".jpg";
}

//set duration for each image
duration = 4;
var n = 0;
var sn = 0;
var counter = 0;
var arrlimit = 5;
ads=[]; 
function changePic()
{ 
 sn = Math.floor(Math.random() * (totpic)); 
 if (ads[counter] && (ads[counter].complete || ads[counter].complete==null)) 
 {
  document["baseball"].src = ads[counter].src; // Show only when load is complete
  n = Math.floor(Math.random() * (totpic)); // Change random number only after load
 }
 ads[counter] = new Image;
 ads[counter].height=320;
 ads[counter].width=450;
 if(n == 0) n = sn;
 ads[counter].src = src[n];
 setTimeout("changePic()", duration*1000);
 counter++;
 if(counter == arrlimit) counter = 0;
}

function changeQuote()
{
	document.write(quotes[currentQuote]);
}

//onload = function()
function startPics()
{
 if(document.images)
  changePic();
}

/************************************************************
* getAd -- Show sponsor ads
************************************************************/
function getAd(url, logo, name, contact, address1, address2, address3, phone1, phone2, phone3, status, height, width) 
{	
	document.write("<tr><td class='sponsor'>");
	if(url != "") document.write("<a href='http://" + url + "'>");
	{
		if(logo != "")
		{
			document.write("<img src='Sponsors/" + logo + "'");
			if(height > 0) document.write(" height='" + height + "'");
			if(width > 0) document.write(" width='" + width + "'");
			document.write(">");
		}
		document.write("</a><br />");
	}
	document.write(name);
	document.write("<p class='address'>");
	if(contact != "") document.write(contact + "<br />");
	if(address1 != "") document.write(address1 + "<br />");
	if(address2 != "") document.write(address2 + "<br />");
	if(address3 != "") document.write(address3 + "<br />");
	if(phone1 != "") document.write(phone1 + "<br />");
	if(phone2 != "") document.write(phone2 + "<br />");
	if(phone3 != "") document.write(phone3 + "<br />");
	if(status == 2) document.write("<img src='Sponsors/HOF.gif' height='175' width='200'></img>");
	if(status == 3) document.write("<img src='Sponsors/MTS.gif' height='175' width='200'></img>");
	document.write("</p>");
	document.write("<img src='Sponsors/line.jpg1' width='75%'></img>");
	document.write("</td></tr>");
}

/************************************************************
* getPictures - Create picture page automatically
************************************************************/
function getPictures(indicator)
{
	var subdir;
	var counter, tcounter;
	
	switch(indicator)
	{
	case "2006":
		subdir = pic2dir
		counter = pic2no
		tcounter = tpic2no
		break;
	case "2007":
		subdir = picdir;
		counter = picno;
		tcounter = tpicno
		break;
	case "Opener":
		subdir = pic3dir;
		counter = pic3no;
		tcounter = tpic3no
		break;
	default:
		subdir = picdir;
		counter = picno;
		tcounter = tpicno
		break;
	}		
	
	document.write("<tr>");
	
	for(count = 0; count <= counter; count++)
	{
		document.write("<td>");
		document.write("<a href='http://www.woodlawnlittleleague.org/experiment/" + subdir + count + ".jpg'>");
		document.write("<img src='" + subdir + "thumbs/" + count + "_small.jpg' border='0' ");
		if(count < tcounter)
		{
			document.write("height='120' width='180'"); // Landscape
		}
		else
		{
			document.write("height='180' width='120'"); // Portrait
		}
		document.write("></a>");
		document.write("</td>");
		var num = (count + 1)%3;
		if(num%3 == 0)
		{
			document.write("</tr>");
			if(count != counter)
			{
				document.write("<tr>");
			}
		}
	}
	document.write("</tr>");
}

/************************************************************
* Generate Row for Standings
************************************************************/
function Row(team, wins, loses, ties) 
{
  var avg, games;
  games = wins + loses + ties;

  if (games == 0)
  {
    avg = 0;
  }
  else
  {
    avg = wins/games;
  }

  var percentage
  if(avg == 0) percentage = ".000";
  if(avg == 1)
  {
    percentage = "1.000";
  }
  else
  {
    percentage = "." + String(Math.round(avg * 100)%100 + '00').substring(0,3);
  }

  document.write("<td class='team'>" + team + "</td><td>" + wins + 
	"</td><td>" + loses + "</td><td>" + ties + "</td><td>" + percentage +"</td>");
}

/************************************************************
* score -- Generate score and standings
************************************************************/
var teams;
var teamno = 0;
var records;
var games;
var gameno = 100; // To start
var gamecount = 0;

//************************************************************
// loadTeam
//************************************************************
function loadTeam(t)
{
	var tempteams = new Array(teamno);
	for(var c = 0; c < teamno; c++)
	{
		tempteams[c] = teams[c];
	}
	teams = new Array(teamno + 1);
	for(var c = 0; c < teamno; c++)
	{
		teams[c] = tempteams[c];
	}
	teams[teamno++] = t;
}

//************************************************************
// Put zeros is records array
//************************************************************
function sinit()
{
	var arrcount = 0;
	var arrsize = teams.length * 3;
	records = new Array(arrsize);
	for(var c = 0; c < teams.length; c++)
	{
		records[arrcount++] = 0;
		records[arrcount++] = 0;
		records[arrcount++] = 0;
	}
	games = new Array(gameno);
	gamecount = 0;
}

//************************************************************
// game -- Game object
//************************************************************
function game()
{
	this.gdate = "";
	this.home = "";
	this.hscore = 0;
	this.away = "";
	this.ascore = 0;
}

//************************************************************
// score -- Stores dates and scores
//************************************************************
function score(gdate, home, hscore, away, ascore)
{
	var hteam, ateam;
	var htno, atno;
	
	var g = new game();
	g.gdate = gdate;
	g.home = home;
	g.hscore = hscore;
	g.away = away;
	g.ascore = ascore;
	games[gamecount++] = g; // Put game in array
	
	for(var c = 0; c < teams.length; c++)
	{
		if(home == teams[c])
		{
			hteam = home;
			htno = c;
		}
		if(away == teams[c])
		{
		    ateam = away;
		    atno = c;
		}
	}
	
	if(hteam == "" || ateam == "") document.write("<strong>Error -- " + gdate + " " + home + " " + hscore + " " + away + " " + ascore + "</strong>");

	if(hscore > ascore)
	{
		records[htno * 3] = records[htno * 3] + 1; // 1 in the win column
		records[((atno * 3) + 1)] = records[(atno * 3 + 1)] + 1; // 1 in the lose column
	}
	if(hscore < ascore)
	{
		records[atno * 3] = records[atno * 3] + 1; // 1 in the win column
		records[((htno * 3) + 1)] = records[(htno * 3 + 1)] + 1; // 1 in the lose column
	}
	if(hscore == ascore)
	{
		records[(atno * 3) + 2] = records[(atno * 3) + 2] + 1; // 1 in the tie column
		records[((htno * 3) + 2)] = records[((htno * 3) + 2)] + 1; // 1 in the tie column
	}
	
	// Update games
	games[gamecount]
}

//************************************************************
// showStandings - Make standings grid for current age group
//************************************************************
function showStandings()
{
	var wins, loses, ties;
	var avg, games;
	var arrcount = 0;

	// Write header line
	document.write("<tr><th class='steam'>&nbsp</th><th class='record'>W</th><th class='record'>" +
		"L</th><th class='record'>T</th><th class='record'>PCT</th></tr>");

	// Order by winning team
	for(var c = 0; c < teams.length - 1; c++)
	{
		for(var c2 = c + 1; c2 < teams.length; c2++)
		{
			if(records[c2 * 3] > records[c * 3])
			{
				var temp = teams[c];
				teams[c] = teams[c2];
				teams[c2] = temp;
				var temp2 = records[c * 3];
				records[c * 3] = records[c2 * 3];
				records[c2 * 3] = temp2;
				var temp3 = records[(c * 3) + 1];
				records[(c * 3) + 1] = records[(c2 * 3) + 1];
				records[(c2 * 3) + 1] = temp3;
				var temp4 = records[(c * 3) + 2];
				records[(c * 3) + 2] = records[(c2 * 3) + 2];
				records[(c2 * 3) + 2] = temp4;
			}
		}
	}

	for(var c = 0; c < teams.length; c++)
	{
		wins = records[(c * 3)];
		loses = records[(c * 3) + 1];
		ties = records[(c * 3) + 2];

		games = wins + loses + ties;
		if (games == 0)
		{
			avg = 0;
		}
		else
		{
			avg = wins/games;
		}

		var percentage
		if(avg == 0) percentage = ".000";
		if(avg == 1)
		{
			percentage = "1.000";
		}
		else
		{
			percentage = "." + String(Math.round(avg * 100)%100 + '00').substring(0,3);
		}

		document.write("<tr><td class='steam'>" + teams[c] + "</td><td class='record'>" + wins + 
		"</td><td class='record'>" + loses + "</td><td class='record'>" + ties + "</td><td class='record'>" + 
		percentage +"</td></tr>");

		// Initialize
		wins = 0;
		loses = 0;
		ties = 0;
	}
}

//************************************************************
// List results for current age group
//************************************************************
function showGames()
{
	var prevdate;
	for(var c = 0; c < games.length; c++)
	{
		if(games[c].gdate != prevdate)
		{
			document.write("<tr><td><table>");
			document.write("<tr class='date'><td colspan='2' class='steam'>" + games[c].gdate + "</td></tr>");
			document.write("<tr><td><table border='1'><tr><td class='steam'>" + games[c].home + "</td>");
			document.write("<td class='score'>" + games[c].hscore + "</td></tr>");
			document.write("<tr><td class='steam'>" + games[c].away + "</td>");
			document.write("<td class='score'>" + games[c].ascore + "</td></tr></table></td></tr></table></td>");
		}
		else
		{
			document.write("<td><table>");
			document.write("<tr class='date'><td colspan='2' class='steam'>&nbsp;</td></tr>");
			document.write("<tr><td><table border='1'><tr><td class='steam'>" + games[c].home + "</td>");
			document.write("<td class='score'>" + games[c].hscore + "</td></tr>");
			document.write("<tr><td class='steam'>" + games[c].away + "</td>");
			document.write("<td class='score'>" + games[c].ascore + "</td></tr></table></td></tr></table></td>");
		}
		prevdate = games[c].gdate;
	}
	document.write("</tr>");

}


//************************************************************
// Pitch Count Line
//************************************************************
function pitchCount(team, name, count)
{
	document.write("<tr><td class='pitch'>" + team + " -- " + name + " - </td>");
	document.write("<td class='pitch'>" + count + "</td></tr>");
}

//************************************************************
// ScoreBox
//************************************************************
function ScoreBox(home, hscore, away, ascore)
{
	document.write("<td><table border='1' width='160'><tr><td width='100'>");
	document.write(home);
	document.write("</td><td width='60' align='right'>");
	document.write(hscore);
	document.write("</td></tr><tr><td>");
	document.write(away);
	document.write("</td><td align='right'>");
	document.write(ascore);
	document.write("</td></tr></table></td>");
}


//************************************************************
// DateLine
//************************************************************
function DateLine(gamedate)
{
	document.write("<tr><td><table width='100%'><tr bgcolor='#BFE2F9'><td class='date'>");
	document.write(gamedate);
	document.write("</td></tr></table></td></tr>");
}



