var agendaSlideTimeBetweenSteps = 30;	// General speed variable (Lower = slower)

var objContainer = false;
var objContent = false;
var buttonUp = false;
var buttonDown = false;
var containerId;
var countSpeed;
var normalSpeed;

var agendaObjects = new Array();

var buttonEvent = false;

function slideAgendaContent()
{
	var topPos = agendaObjects[containerId]['objRef'].style.top.replace(/[^\-0-9]/g,'');

	if(agendaObjects[containerId]['slideSpeed'] != 0)
	{
		countSpeed++;

		topPos = topPos - agendaObjects[containerId]['slideSpeed'];

		if(agendaObjects[containerId]['slideSpeed'] > 0)
		{
			if(topPos/1 + agendaObjects[containerId]['contentHeight']/1 > 30)
				agendaObjects[containerId]['objRef'].style.top = topPos + 'px';
		}
		else
		{
			if(topPos/1 < 30)
				agendaObjects[containerId]['objRef'].style.top = topPos + 'px';
		}

		if(countSpeed%50 == 0)	/* 50*30ms = 1,5 segundos */
		{
			agendaObjects[containerId]['originalSpeed'] *= 2;
			if(agendaObjects[containerId]['slideSpeed'] > 0)
				agendaObjects[containerId]['slideSpeed'] = agendaObjects[containerId]['originalSpeed'];
			else
				agendaObjects[containerId]['slideSpeed'] = -1*agendaObjects[containerId]['originalSpeed'];
		}
	}	
	setTimeout('slideAgendaContent()',agendaSlideTimeBetweenSteps);
}

function stopAgendaSliding()
{
	countSpeed = 0;
	agendaObjects[containerId]['originalSpeed'] = normalSpeed;
	agendaObjects[containerId]['slideSpeed'] = 0;
}

function slideUp()
{
	agendaObjects[containerId]['slideSpeed'] = agendaObjects[containerId]['originalSpeed'];
}

function slideDown()
{
	agendaObjects[containerId]['slideSpeed'] = -1*agendaObjects[containerId]['originalSpeed'];
}

function changeAgendaContent()
{
	var i;
	var str = '';
	var imgComp = false;
	var containerComp = false;
	var compAgenda = false;
	objContent.style.top = '0px';
	
	if (agendaControl ==1)
	{
		for (i=0;i<nextEvents.length;i++)
		{
			str += nextEvents[i];
		}
		if (buttonEvent != null)
			buttonEvent.innerHTML = "<p>Eventos Anteriores</p>";
		
		agendaControl = 0;
		
		objContent.innerHTML = str;

		for (i=0;i<imgNextEvents.length;i++)
		{
			if(imgNextEvents[i] != "")
			{
				imgComp = document.getElementById("imgAgenda"+imgNextEvents[i]);
				if(imgComp != null)
					imgComp.style.backgroundImage = "url(../Figuras/Eventos/mini/"+imgNextEvents[i]+")";
			}
		}
	}
	else
	{
		for (i=0;i<lastEvents.length;i++)
		{
			str += lastEvents[i];
		}
		buttonEvent.innerHTML = "<p>Próximos Eventos</p>";
		agendaControl = 1;

		objContent.innerHTML = str;

		for (i=0;i<imgLastEvents.length;i++)
		{
			if(imgLastEvents[i] != "")
			{
				imgComp = document.getElementById("imgAgenda"+imgLastEvents[i]);
				if(imgComp != null)
					imgComp.style.backgroundImage = "url(../Figuras/Eventos/mini/"+imgLastEvents[i]+")";
			}
		}
	}

	agendaObjects[containerId]['contentHeight'] = objContent.offsetHeight;
	
	if (buttonEvent != null) /* It is true in case of Home agenda. */
	{
		jQuery('.popupConvite a').lightBox({fixedNavigation:true,txtImage: 'Evento', txtOf: 'de'});	//Initialize Lightbox for events
	}
	else
	{
		containerComp = document.getElementById("agendaContainer");
		if(containerComp != null)
			containerComp.style.height = objContent.offsetHeight + 'px';
		
		compAgenda = document.getElementById("agenda");
		if(compAgenda != null)
			compAgenda.style.height = objContent.offsetHeight + 'px';
	}
}

function showNote()
{
	var divulgaAgenda=document.getElementById('divulgaAgenda');
	if(divulgaAgenda != null)
	{
		divulgaAgenda.style.visibility='visible';
		divulgaAgenda.style.display='block';
	}
}

function hideNote()
{
	var divulgaAgenda=document.getElementById('divulgaAgenda');
	if(divulgaAgenda != null)
	{
		divulgaAgenda.style.visibility='hidden';
		divulgaAgenda.style.display='none';
	}
}
			
function initAgendaControl(objId,upButtonId,downButtonId,eventButtonId,slideSpeed)
{
	//Inicialization for increease speed feature
	countSpeed = 0;
	normalSpeed = slideSpeed;
	
	containerId = objId;
	
	/* Agenda content control */
	buttonEvent = document.getElementById(eventButtonId);
	if(buttonEvent != null) /* It is different in case of Home agenda. */
	{
		buttonEvent.onclick = function() { changeAgendaContent(); };
	}

	/* Container control */
	objContainer = document.getElementById(containerId);
	if(objContainer != null)
	{
		objContent = objContainer.getElementsByTagName('DIV')[0];

		objContainer.style.position = 'relative';
		objContainer.style.overflow = 'hidden';
		objContent.style.position = 'relative';
		
		agendaObjects[containerId] = new Array();
		agendaObjects[containerId]['objRef'] = objContent;
		agendaObjects[containerId]['containerHeight'] = objContainer.clientHeight;
		agendaObjects[containerId]['slideSpeed'] = 0;
		agendaObjects[containerId]['originalSpeed'] = normalSpeed;
	}
	
	/* Update agenda content */
	changeAgendaContent();

	/* Up and down buttons control */
	buttonUp = document.getElementById(upButtonId);
	if(buttonUp != null) /* It is different in case of Home agenda. */
	{
		buttonUp.onmouseover = function() { slideDown(); };
		buttonUp.onmouseout = function() { stopAgendaSliding(); };
	}

	/* Agenda content control */
	buttonDown = document.getElementById(downButtonId);
	if(buttonDown != null) /* It is different in case of Home agenda. */
	{
		buttonDown.onmouseover = function() { slideUp(); };
		buttonDown.onmouseout = function() { stopAgendaSliding(); };
	}	

	/* initialize slide control */
	slideAgendaContent(containerId);

	var divulgaClick = document.getElementById('divulgaClick');
	if(divulgaClick != null)
	{
		divulgaClick.onclick = function() { showNote(); };
	}
	
	var divulgaFechar = document.getElementById('divulgaFechar');
	if(divulgaFechar != null)
	{
		divulgaFechar.onclick = function() { hideNote(); };
	}
}

function defineConteudoHome()
{
	var homeContent = document.getElementById('siteHome');
	var agendaContent = document.getElementById('detalheAgenda');
	
	if(homeContent != null && agendaContent != null)
	{
		if(showAgendaDetail == true)
		{
			homeContent.style.display = 'none';
			agendaContent.style.display = 'block';
		}
	}
}




