ev.addListener(window, 'load', function(){ajax('weatherinfo', 'weather.php?f=getweather&location=Westfield+NJ+07090');})//get the weather feed
ev.addListener(window, 'load', startPrs);//start the pr fader
var prsarray;//array of prs for widget
var newsslide = false;//whether the news is in the slided position

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

//show the event with the given id in a dialog box
function showEvent(id)
{	
	var dialogbox = new dialogBox('430px', "calendar.php?f=show&options=false&id="+id, true);
	dialogbox.onLoadFinishedShow(initWeather);
	curid = id;
}

//show the video with the given id in a dialog box
function showVideo(id)
{	
	var d = new dialogBox("600px", 'videos.php?f=ajaxvid&id='+id, true);
	d.onLoadFinishedShow();
}

//set the title to display on the videos widget
function setVidTitle(title)
{
	document.getElementById('vidtitle').innerHTML = title;
}

//show the bulletin with the given id in a dialog box
function showBulletin(id)
{
	var changeColor = function(box)
	{
		box.setBorderColor('white');
	    dom.setStyle(box.dialogDiv, 'background-color', dom.getStyle(box.dialogDiv.firstChild.firstChild, 'background-color'));
	    //alert(dom.getStyle(box.dialogDiv, "background"));
	}
	
	var d = new dialogBox('85ex', 'news.php?f=single&fromhomepage=true&id='+id, true);
	d.onLoadFinishedShow(changeColor);
}

//show the signup form for the mailing list
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', 'm_list_signup.php?f=signup', sent);
	}
	
	
	var initbutton = function(e)
	{
		ev.addListener('subscribebutton', 'click', submitListForm, e);
	}
	
	var d = new dialogBox("55ex", "m_list_signup.php?f=form", true);
	d.onLoadFinishedShow(initbutton);
}

//infinitely recursing function to display prs slideshow
function showPr(num, length)
{
	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, 15)+"</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();
	}
	
}

//start the infinite recent pr's slideshow
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);
}

//slide the news to reveal the hidden set of stories
function newsSlide() {
    if(!newsslide) {
        var anim = new YAHOO.util.Anim('newsslider', {"margin-top" : {from:0, to:-26, unit:"em"}}, .7, YAHOO.util.Easing.easeBothStrong);
    	anim.animate();
        anim.onComplete.subscribe(changeNewsText);
    }
    else {
         var anim = new YAHOO.util.Anim('newsslider', {"margin-top" : {from:-26, to:0, unit:"em" }}, .7, YAHOO.util.Easing.easeBothStrong);
        anim.animate();
        anim.onComplete.subscribe(changeNewsText);
        
        
    }
    
    newsslide = !newsslide;
}

//change the text of the link at the bottom of the news widget
function changeNewsText() {
    if(newsslide) {
        document.getElementById('newsview').innerHTML = "View Most Recent Bulletins";
    }
    else {
        document.getElementById('newsview').innerHTML =  "View More Bulletins";
    }
}


