var sliderout = false;
var slidertype = false;
var sliderteam = 'home';
var tipsUrl = "tips.php";
var flagforchange = false;

function toggleSlider(e, type, matchid, team){
	var tipsdiv = document.getElementById(e + '_container');	
	if (!team)
	{
		team = 'home';
	}
	
	var handleTipsSuccess = function(o){
		if(o.responseText !== undefined){
			tipsdiv.innerHTML = o.responseText;
		}
	}
	
	var handleTipsFailure = function(o){
		if(o.responseText !== undefined){
			tipsdiv.innerHTML = "Error";
		}
	}
	
	var callback =
	{
	  success:handleTipsSuccess,
	  failure: handleTipsFailure,
	};

	if (sliderout != false) //Slider is out
	{
		if ((sliderout == e) && (slidertype == type)) //Slider is exactly the same, so hide it
		{
			if (sliderteam == team)
			{
				var anim = new YAHOO.util.Anim(sliderout,{height:{to:0}},1,YAHOO.util.Easing.easeIn);
				anim.animate();
				sliderout = false;
				slidertype = false;
				sliderteam = 'home';				
			} else {
				var request = YAHOO.util.Connect.asyncRequest('POST', tipsUrl, callback, 'ajax=1&mode=' + type + '&matchid=' + matchid + '&team=' + team);
				sliderteam = team;
			}
		} else if ((sliderout != e)) //Slider is not the same as the current one, so put it away and bring out the new one
		{
			var anim = new YAHOO.util.Anim(sliderout,{height:{to:0}},1,YAHOO.util.Easing.easeIn);
			anim.animate();
			sliderout = e;
			slidertype = type;
			sliderteam = team;
			var request = YAHOO.util.Connect.asyncRequest('POST', tipsUrl, callback, 'ajax=1&mode=' + type + '&matchid=' + matchid + '&team=' + team);
			var anim = new YAHOO.util.Anim(sliderout,{height:{to:265}},1,YAHOO.util.Easing.easeOut);
			anim.animate();
		} else if (slidertype != type) //Slider is not of the correct type, so change the type
		{
			var request = YAHOO.util.Connect.asyncRequest('POST', tipsUrl, callback, 'ajax=1&mode=' + type + '&matchid=' + matchid + '&team=' + team);
		}
	} else { //Slider is in
		sliderout = e;
		slidertype = type;
		sliderteam = team;
		var request = YAHOO.util.Connect.asyncRequest('POST', tipsUrl, callback, 'ajax=1&mode=' + type + '&matchid=' + matchid + '&team=' + team);
		var anim = new YAHOO.util.Anim(sliderout,{height:{to:265}},1,YAHOO.util.Easing.easeOut);
		anim.animate();
	}
}


var sliderUrl = "portal.php";
function newsSlider(e, newsid){
	var sliderdiv = document.getElementById(e + '_container');	
	
	var handleSliderSuccess = function(o){
		if(o.responseText !== undefined){
			sliderdiv.innerHTML = o.responseText;
		}
	}
	
	var handleSliderFailure = function(o){
		if(o.responseText !== undefined){
			sliderdiv.innerHTML = "Error";
		}
	}
	
	var callback =
	{
	  success:handleSliderSuccess,
	  failure: handleSliderFailure,
	};

	if (sliderout != false)
	{
		if (sliderout == e)
		{
			var anim = new YAHOO.util.Anim(sliderout,{height:{to:16}},1,YAHOO.util.Easing.easeIn);
			anim.animate();
			sliderdiv.innerHTML = oldtext;			
			sliderout = false;
		}
	} else { //Slider is in
		sliderout = e;
		oldtext = sliderdiv.innerHTML;
		var request = YAHOO.util.Connect.asyncRequest('POST', sliderUrl, callback, '&mode=shownews&newsid=' + newsid);
		var anim = new YAHOO.util.Anim(sliderout,{height:{to:100}},1,YAHOO.util.Easing.easeOut);
		anim.animate();
	}
}

var baseURL = "profile.php";
function showprofile(userid, mode, competitionid, seasonid){
	var profilediv = document.getElementById('profilecontent');	
	
	var handleSliderSuccess = function(o){
		if(o.responseText !== undefined){
			profilediv.innerHTML = o.responseText;
		}
	}
	
	var handleSliderFailure = function(o){
		if(o.responseText !== undefined){
			profilediv.innerHTML = "Error";
		}
	}
	
	var callback =
	{
	  success:handleSliderSuccess,
	  failure: handleSliderFailure,
	};

	var request = YAHOO.util.Connect.asyncRequest('POST', baseURL, callback, 'userid='+ userid +'&mode='+ mode +'&seasonid='+ seasonid +'&competitionid=' + competitionid + '&ajax=1');
}