var fnarr=[
['main_franklin.png',4],
['main_girl.png',4],
['testimg.png',3]
]

var homepageimgloc='/assets/images/homepage/'

function scrollnews(typ,num)
{
	/*
	typ values:
	t=timer
	c=click

	num:
	number of the image to show if the user clicks. The timer uses the curfestnews var
	*/
	/*This function will fade out what's currently showing and fade in/scroll up the new items*/

	if(typ=='c')
	{
		//click
		clearTimeout(FNIntervalId)
		clearTimeout(slideupIntervalId)
		curfestnews=num

		//clear out image queue
		var queue = Effect.Queues.get('fnimgscope');
		queue.each(function(effect) { effect.cancel(); });
		//clear newsbox queue
		queue = Effect.Queues.get('fnmainscope');
		queue.each(function(effect) { effect.cancel(); });
		
		//switch image
		//gebid('curfestimg').src=homepageimgloc+fnarr[curfestnews-1][0];
		/*
		if(isie())
		{
			if(gebid('curfestimg'))
			{
				setieopacity('curfestimg',100)
			}
		}
		else
		{
			gebid('curfestimg').style.opacity='1.0'
		}
		*/
		
		//switch newsbox
		for(var x=1;x<=totfestnews;x++)
		{
			if(x==(curfestnews))
			{
				if(isie())
				{
					setieopacity('festnews'+x,100)
				}
				else
				{
					gebid('festnews'+x).style.opacity='1.0'
				}
				gebid('festnews'+x).style.top='40px'
				changedisplay('festnews'+x,'block')

			}
			else
			{
				changedisplay('festnews'+x,'none')
				gebid('festnews'+x).style.top='320px'
			}
		}
		
	}
	else if(typ=='t')
	{
		//timer
		
		//fade everything out
		Effect.Fade('festnews'+curfestnews, 
			{
				duration:.4,
				to:0,
				queue:{position:'end',scope:'fnmainscope'}
			});
			
		/*Effect.Fade('curfestimg', 
			{
				duration:.5,
				afterFinish: function(){gebid('curfestimg').src=homepageimgloc+fnarr[curfestnews-1][0];fadeinimg()},
				queue:{position:'end',scope:'fnimgscope'}
			});*/

		//reset the currently-displayed newsbox to original position
		//gebid('festnews'+curfestnews).style.top='320px'

		//change to the new festnewsbox
		curfestnews++
		if(curfestnews>(totfestnews))
		{
			curfestnews=1
		}
		
		Effect.Appear('festnews'+curfestnews, {duration:.4,queue:{position:'end',scope:'fnmainscope'}});

		//gebid('curfestimg').src=homepageimgloc+fnarr[curfestnews-1][0];		
			
		//slideup('festnews'+curfestnews,275)
		
		var nextfn
		nextfn=curfestnews+1
		if(nextfn>totfestnews)
		{
			nextfn=1
		}
		FNIntervalId = setTimeout(function(){scrollnews('t',2)}, (fnarr[nextfn-1][1]*1000))
	}	

	createnav()

}

function fadeinimg()
{
	Effect.Appear('curfestimg',
	{
		duration:.5,
		afterFinish: function(){},
		queue:{position:'end',scope:'fnimgscope'}
	});
}

function createnav()
{
	var ih=''
	var col=''
	for(var x=0;x<totfestnews;x++)
	{
	
		if(x==(curfestnews-1))
		{
			col='#ffffff'
		}
		else
		{
			col='#000000'
		}
		ih+='<div class="festnewsnavitem" id="festnewsnav'+(x+1)+'" style="color:'+col+';" onclick="scrollnews(\'c\','+(x+1)+')">&bull;</div>'
		
	}
	gebid('festnewsnav').innerHTML=ih
}

function slideup(idx,pixels)
{
	var newpixels=0
	//console.log('idx='+idx)
	if(pixels>0)
	{
		gebid(idx).style.top=parseInt(getstyle(idx,'top'))-5+'px'
		newpixels=pixels-5
		slideupIntervalId=setTimeout(function(){slideup(idx,newpixels)},20)
	}
}


var totfestnews=2 //total festival news items
var curfestnews=1 //current festival news item being shown. The first one in most cases is referred to as 1, not 0. 
var FNIntervalId=null
var slideupIntervalId=null

function pageinit()
{
	//slideup('festnews1',275)
	//gebid('curfestimg').src=homepageimgloc+fnarr[0][0]
	gebid('curfestimg').src=homepageimgloc+'main_franklin.png'
	//new Effect.Appear('curfestimg', {duration:1.0,queue:{position:'end',scope:'fnimgscope'}});
	changedisplay('curfestimg','block')
	createnav()
	FNIntervalId = setTimeout(function(){scrollnews('t',2)}, (fnarr[1][1]*1000))
}

if (window.addEventListener || window.attachEvent)
{
	if (window.attachEvent)
	{
		//ie
		window.attachEvent("onload", pageinit)
	}
	else if(window.addEventListener)
	{
		//everyone else
		window.addEventListener("load", pageinit, false) //invoke function
	}
}


