window.addEvent('domready',function(){
	
	$('showWorkoutsFadeWrapper').fade('hide');
	$('showWorkoutsFadeWrapper').removeClass('hide');
	 

});

function FadeInShowWorkouts()
{
	$('showWorkoutsFadeWrapper').fade('in'); 
	
}

function FadeOutShowWorkouts()
{
	$('showWorkoutsFadeWrapper').fade('out');
	
	SetShowWorkoutsPopupShown();
}

function SetShowWorkoutsPopupShown()
{
	Set_Cookie("popupShowWorkoutsShown",'1',0, '/','','');
}

var elapsedShowWorkoutsTime = 0;//this will hold the elapsed time;
var initialShowWorkoutsTimerLength = 7 * 1000;
var timerShowWorkoutsObject;

window.onunload = function()
{
    //elapsed value gets pushed to a cookie here
    //Set_Cookie("elapsedShowWorkoutsTime",elapsedShowWorkoutsTime,0, '/','','');
}

//Run this on page load.
function startTimerCounter()
{	
	popupShowWorkoutsShown = null;
	popupShowWorkoutsShown = Get_Cookie('popupShowWorkoutsShown');
   	//elapsedShowWorkoutsTime = Get_Cookie('elapsedShowWorkoutsTime');
	
	if(elapsedShowWorkoutsTime == null || elapsedShowWorkoutsTime == "NaN")
	{
		elapsedShowWorkoutsTime = 0;
	}
	else
	{
		//alert("Previous time is " + elapsedTime);
	}
	//TESTING
	//popupShown = null;
	
	if (popupShowWorkoutsShown==null)
 	{
		timerShowWorkoutsObject = setTimeout("timerShowWorkoutsTick()", 1000);
  	}
}

//Executes every second and checks to see if the timer has hit threshold
function timerShowWorkoutsTick()
{
	//alert(elapsedTime);
	
	elapsedShowWorkoutsTime = (elapsedShowWorkoutsTime * 1) + 1000;
	
	if(elapsedShowWorkoutsTime > initialShowWorkoutsTimerLength)
	{
		try
		{
			FadeInShowWorkouts();
		}
		catch(err)
		{
			//popup code not loaded yet
			setTimeout("timerShowWorkoutsTick()",1000);
		}
		
	}
	else
	{
		setTimeout("timerShowWorkoutsTick()",1000);
	}
}