// JavaScript Document

window.onload = initAll;
window.onunload = function(){};
function initAll() {
	rolloverInit();
	choosePic();
	rotate();
}

/* -------------------- Nav Button Rollover FX -----------------------------*/
function rolloverInit() {
	/*Loop through all images and check if they are within
	"a" tags. If they are, set up for rollover fx */
	if (document.images){
		for (var i = 0; i<document.images.length; i++) {
			if (document.images[i].parentNode.tagName == "A") {
				setupRollover(document.images[i]);
			}
		}
	}
}

function setupRollover(thisImage) {
	// Create new image vars for rollover pix
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = rollOut;

		// Assign each button an id in the html
	thisImage.overImage = new Image();
	thisImage.overImage.src = "http://www.fat-alberts.com/images/buttons/" + thisImage.id + "_over.gif";
	thisImage.onmouseover = rollOver;
}

function rollOut() {
	this.src = this.outImage.src;
}

function rollOver() {
	this.src = this.overImage.src;
}
/* -------------------------------------------------------- */
/*------------------- Random Images on Load --------------- */
// Random picture loads when page opens

function choosePic() {
	// add desired images to myPix 
	var myPix = new Array("images/pie_banner.jpg", "images/corned_beef.jpg", "images/ital_salad.jpg", "images/sirloin.jpg");
	var randomNum = Math.floor((Math.random() * myPix.length));
	document.getElementById("randomPix").src = myPix[randomNum];
}

/* -------------------------------------------------------- */
function stPatsDay() {
// calculate number of days until St. Patrick's day
	var Today = new Date();
	var ThisDay = Today.getDate();
	var ThisMonth = Today.getMonth() + 1;
	var MonthName = MonthText(ThisMonth);
	var ThisYear = Today.getFullYear();
	var spDay = new Date("March, 17, 2011");
	spDay.setFullYear(ThisYear);
	if ((ThisMonth > 3) || (ThisMonth == 3 && ThisDay > 17)) // Set to calculate for next St. Pat's
	{														 // if this year's is past
		spDay.setFullYear(ThisYear + 1);
	} 
	var DaysLeftFraction = (spDay - Today)/(1000 * 60 * 60 *24);
	DaysLeft = Math.round(DaysLeftFraction);
	document.write("<h4>Today is "+MonthName + " " + ThisDay + ", " + ThisYear + "</h4>");
	if (DaysLeft > 1)
	{
		document.write("<h3>It's only " + DaysLeft + " days until St. Patrick's Day!!</h3>");
	}
	else
	{
		if (DaysLeftFraction <= 1 && DaysLeftFraction > 0)
		{
			document.write("<h2>Tomorrow is St. Patrick's Day!!</h2>");
		}
		else
		{
			document.write("<h2>Today is St. Patrick's Day!!<br><i>Come celebrate at Fat Alberts!</h2>");
		}
	}
		
}
function MonthText(MonthNumber)
{
	var Month = new Array();
	Month[1]="January";
	Month[2]="February";
	Month[3]="March";
	Month[4]="April";
	Month[5]="May";
	Month[6]="June";
	Month[7]="July";
	Month[8]="August";
	Month[9]="September";
	Month[10]="October";
	Month[11]="November";
	Month[12]="December";
	return Month[MonthNumber];
}
function rotate()
{
	if (document.images)
	{
		thisAd++;
		if (thisAd == imgCt)
		{
			thisAd = 0;
		}
		document.adBanner.src=adImages[thisAd];
		setTimeout("rotate()", 5 * 1000);
	}
}