var imgIntervalId = 0;
var curImg = 0;


/*
imglst format:
image, delay (not currently used), alt text, link, open in new window (1=open in new window, 0=same window)
*/
/*
var imglst=[
['assets/images/slider/Slider1.jpg',5,'alt text 1 lorem','/test1.asp',0],
['assets/images/slider/Slider2.jpg',5,'alt text 2 ipsum','http://www.yahoo.com',1],
['assets/images/slider/Slider3.jpg',5,'alt text 3 dolor','',0],
['assets/images/slider/Slider4.jpg',5,'alt text 4 sit','/test4.asp',0],
['assets/images/slider/Slider5.jpg',5,'alt text 5 amet','http://www.getfirefox.com',1],
['assets/images/slider/Slider6.jpg',5,'alt text 6 adipiscing','/test5.asp',0]
]

*/
function switchX(typ, elid, num)
{
	var oncur = '';
	if (typ == 't')
	{
		curImg++;
		if (curImg == imglst.length)
		{
			curImg = 0;
		}
		num = curImg;
		oncur = num;
	}
	else if (typ == 'c')
	{
		clearInterval(imgIntervalId);
		curImg = num;
		oncur = curImg;
	}
	
	
	
	if (typ == 't')
	{
		gebid(elid+'Imgfo').src=gebid(elid+'Img').src;
		Element.show('imgwrapperfo');
		gebid(elid+'Img').src=imglst[curImg][0];
		new Effect.Fade('imgwrapperfo', { duration: 1.5 });
		new Effect.Appear('imgwrapper', { duration: 1.5 });
	}
	else if (typ == 'c')
	{
		gebid(elid+'Img').src='images/photoGallery/photo'+num+'.jpg';
		gebid(elid+'Imgfo').src='images/photoGallery/photo'+num+'.jpg';
	}

	updateimg()
	
	
	//gebid('p_of').innerHTML=oncur+' of '+totalimg;
}

function updateimg()
{
	gebid('xImg').alt=imglst[curImg][2]
	gebid('xImgfo').alt=imglst[curImg][2]
	
	gebid('xImg').title=imglst[curImg][2]
	gebid('xImgfo').title=imglst[curImg][2]

	if(imglst[curImg][3] !='')
	{
		//link
		if(imglst[curImg][4]==0)
		{
			gebid('headerimagewrapper').onclick=function(){window.location=imglst[curImg][3]}
			//gebid('xImgfo').onclick=function(){window.location=imglst[curImg][3]}
		}
		else if(imglst[curImg][4]==1)
		{
			gebid('headerimagewrapper').onclick=function(){window.open(imglst[curImg][3],'newwin','controls,status')}
			//gebid('xImgfo').onclick=function(){window.open(imglst[curImg][3],'newwin','controls,status')}
		}
		gebid('headerimagewrapper').style.cursor='pointer'
		//gebid('imgwrapper').style.cursor='pointer'
	}
	else
	{
		//no link
		gebid('headerimagewrapper').onclick=''
		//gebid('xImgfo').onclick=''
		gebid('headerimagewrapper').style.cursor='default'
		//gebid('imgwrapper').style.cursor='default'
	}

}

function libhomepageinit()
{
	var imgp=document.createElement('img')
	imgp.src=imglst[curImg][0]
	imgp.style.display='none'
	document.body.appendChild(imgp)


	gebid('xImg').src=imglst[curImg][0]
	gebid('xImgfo').src=imglst[curImg][0]
	
	updateimg()
	
	imgIntervalId=setInterval(function(){switchX('t', 'x', 1)},5000)
}


if (window.addEventListener)
{
	//alert('changing bg color')
	window.addEventListener("load", libhomepageinit, false)
}

if (window.attachEvent)
{
	window.attachEvent("onload", libhomepageinit)
}

