ev.addListener(window, 'load', function(){ajax('weatherinfo', 'weather.php?f=getweather&location=Westfield+NJ+07090');})
ev.addListener(window, 'load', startPrs);
var prsarray;
var pauseprs  = false;

function initWeather(box)
{
	var address = document.getElementById('eventaddress').innerHTML;
	ajax('eventweather', 'weather.php?f=getweather&location='+address, box.alignVertical, box);
}

function showEvent(id)
{	
	var dialogbox = new dialogBox('430px', "calendar.php?f=show&options=false&id="+id, true);
	dialogbox.onLoadFinishedShow(initWeather);
	curid = id;
	dialogbox.onGone.subscribe(unPausePRs);
	//pausePRs();
}

function showVideo(id)
{	
	var d = new dialogBox("600px", 'videos.php?f=ajaxvid&id='+id, true);
	d.onLoadFinishedShow();
	d.onGone.subscribe(unPausePRs);
	//pausePRs();
}

function setVidTitle(title)
{
	document.getElementById('vidtitle').innerHTML = title;
}

function showBulletin(id)
{
	var changeColor = function(box)
	{
		box.setBorderColor('white');
		box.dialogDiv.style.background = box.dialogDiv.firstChild.firstChild.style.background;
	}
	
	var d = new dialogBox('75ex', 'news.php?f=single&fromhomepage=1&id='+id, true);
	d.onLoadFinishedShow(changeColor);
	d.onGone.subscribe(unPausePRs);
	//pausePRs();
}

function showListSignUp()
{
	var submitListForm = function(type, args)
	{
		function sent()
		{
			myAlert('A confirmation e-mail has been sent to your inbox. Remember to check for it in your spam folder.', '250px');
		}
		
		sendForm('mlistsignup', 'mlistsignup.php?f=signup', sent);
	}
	
	
	var initbutton = function(e)
	{
		ev.addListener('subscribebutton', 'click', submitListForm, e);
	}
	
	var d = new dialogBox("59ex", "mlistsignup.php?f=form", true);
	d.onLoadFinishedShow(initbutton);
	d.onGone.subscribe(unPausePRs);
	//pausePRs();
}


function pausePRs()
{
	pauseprs = true;
}

function unPausePRs()
{
	pauseprs = false;
}

function showPr(num, length)
{
	if(pauseprs)
		return;
	var disp = document.getElementById('prdisplay');
	var curr = prsarray[num];
	var anim = new YAHOO.util.Anim('prdisplay', {opacity:{from:1, to:0}}, .8);
	anim.onComplete.subscribe(fadeUp, curr);
	anim.animate();
	if(num == length) //went through all entries in the array fetched over JSON
	{
		setTimeout('startPrs()', 3000);
	}
	
	function fadeUp(type, args, curr)
	{
		var disp = document.getElementById('prdisplay');
		disp.innerHTML = "<div title = \"Click to view this athlete's Athlete History\" onclick = \"window.location = '?page=athletehistory#"+curr.athletename+"'\"style = 'font-size:14px; text-align:center; cursor:pointer;' id = 'prscontent'><span style = 'width:36%; margin-left:0px;'>"+ellipsis(curr.athletename, 17)+"</span><span style = 'width:32%'>"+curr.event+"</span><span style = 'width:25%; margin-right:0px;'>"+curr.performance+"</span></div>";
		var anim = new YAHOO.util.Anim('prdisplay', {opacity:{from:0, to:1}}, .8);
		anim.animate();
	}
	
}

function startPrs()
{
	var disp = document.getElementById('prdisplay');
	if(disp == null)
		return;
	
	function loadPrs(json)
	{
		prsarray = eval(json);
		for(var c = 0; c < prsarray.length; c++)
		{
			setTimeout('showPr('+c+', '+(prsarray.length-1)+')', 3000*c);
		}
	}
		
	ajaxGet('recentpr.php', loadPrs);
}


