
var xgallery=new Array()
var curimg
var sl

function grabgallery2(idx)
{
	//calls getfiles.asp to retrieve filelist for creating a new gallery
	createRequest()
	
	var url='/imagegallery/create/grabgallery.asp'
	var sel=''
	sel='idx='+escape(idx)
	//alert(sel)
	request.open("POST",url,true)

	request.onreadystatechange = updateGallery2
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
	request.send(sel)
}

function updateGallery2()
{
	//alert('frmname='+frmname+'\nrequest.readyState='+request.readyState+'\nrequest.responseText='+request.responseText)
	
	if(request.readyState==4)
	{
		var resp=request.responseText
		//document.getElementById('results').innerHTML=resp
		//alert(resp.replace(/\]/g,']\n'))
		if(resp=='')
		{
			alert('An error has occurred.')
		}
		else
		{
			resp=unescape(resp)
		}
		//alert(resp)
		if (request.status==200)
		{
			if(resp.substr(1,6)=='Error:')
			{
				alert(resp)
			}
			else
			{
				resp=unescape(resp)
				xgallery=eval(resp)
				showbgeagal2(xgallery)
				//return GB_showImageSet(xgallery, 1)
			}
			//document.getElementById('files').innerHTML=resp.replace(/\+/g,' ')
		}
		else
		{
			alert("An error has occurred. The server said: "+request.status)
			//document.getElementById('files').innerHTML=resp.replace(/\+/g,' ') //'<span style="color:#FF0000">An error occurred</span>'
		}
	}
	//document.getElementById(ETFform+'linkbutton').innerHTML=rememberlinkbtn
}

function showbgeagal2(xgallery)
{
	curimg=0
	//alert(xgallery.length+'\n'+xgallery[1].length+'\n'+xgallery[1])

	var newgalwrapper=document.createElement("div")

	newgalwrapper.setAttribute("id", "bgeagallerywrapper")
	newgalwrapper.setAttribute("class", "bgeagallerywrapper2")

	newgalwrapper.innerHTML='<div id="bgeagalimgbox" class="bgeagalimgbox2"></div>'
	newgalwrapper.innerHTML+='<div id="bgeagalbar" class="bgeagalbar2">'
	newgalwrapper.innerHTML+='</div>'
	
	document.body.insertBefore(newgalwrapper, document.body.nextSibling)
	document.getElementById('bgeagallerywrapper').className='bgeagallerywrapper2'



	document.getElementById('bgeagallerywrapper').style.width=document.body.clientWidth

	var imghtml=''
	var barhtml=''
	
	imghtml+='<img src="'+unescape(xgallery[curimg][1])+'" id="bgeagalimg" onload="centerbgeaimg2();document.getElementById(\'bgeagalimgbox\').style.visibility=\'visible\';">'



	barhtml+='<div style="display:table;width:900px;background-color:transparent;text-align:center;">'
	
	barhtml+='<div id="barofwrapper" class="baritem2" style="width:140px;left:370px;">'
	//barhtml+='<div id="barnav" style="position:relative;width:120px;background-color:orange;">' //position:absolute;left:50%;
	barhtml+='<div class="baritemarrow2" id="bararrow"><a href="javascript:showimg2(false,-1)"><img src="/images/imagegalleries/YearInPics/LeftArrow.gif" style="border:0px;"></a></div>'
	barhtml+='<div id="barof" style="position:relative;top:5px;float:left;margin:0px;padding:0px;width:60px;text-align:center;">'+(curimg+1)+' / '+xgallery.length+'</div>'
	barhtml+='<div class="baritemarrow2"><a href="javascript:showimg2(false,1)"><img src="/images/imagegalleries/YearInPics/RightArrow.gif" style="border:0px;"></a></div>'
	//barhtml+='blah'
	//barhtml+='</div>'
	barhtml+='</div>'
	
	barhtml+='</div>'
//alert(document.getElementById('barofwrapper').clientWidth+' '+document.getElementById('barofwrapper').style.width)
	
	barhtml+='<div class="bgeacaption2" id="bgeacaption">'+unescape(xgallery[curimg][0])+'</div>'

	document.getElementById('bgeagalimgbox').innerHTML=imghtml
	document.getElementById('bgeagalbar').innerHTML=barhtml

	showimg2(true,0)
}

function showimg2(goto,direction)
{
	//alert(goto+' dir='+direction)

	if(goto==true)
	{
		curimg=direction
	}
	else
	{
		curimg+=direction
		if(curimg < 0)
		{
			curimg=xgallery.length-1
		}
		else if(curimg>(xgallery.length-1))
		{
			curimg=0
		}
	}

	document.getElementById('bgeagalimgbox').style.visibility='hidden'

	document.getElementById('bgeagalimg').src=unescape(xgallery[curimg][1])
	
	document.getElementById('bgeacaption').innerHTML=unescape(xgallery[curimg][0])

	document.getElementById('barof').innerHTML=(curimg+1)+' / '+xgallery.length

	centerbgeaimg2()
}

function centerbgeaimg2()
{

	if((navigator.appName=='Microsoft Internet Explorer') && (navigator.appVersion.indexOf('MSIE 6.0')>0))
	{
		//ie6

		//alert(document.documentElement.scrollTop)
		document.getElementById('bgeagalimgbox').style.position='absolute'
		document.getElementById('bgeagalimgbox').style.top=document.documentElement.scrollTop+120+'px'
		document.getElementById('bgeagalimgbox').style.left=(document.body.clientWidth/2)-(document.getElementById('bgeagalimgbox').clientWidth/2)+'px'

		/*document.getElementById('bgeagalbar').style.position='absolute'
		document.getElementById('bgeagalbar').style.top=document.documentElement.scrollTop+20+'px'*/
//		document.getElementById('bgeagalbar').style.left=(document.body.clientWidth/2)-(document.getElementById('bgeagalbar').clientWidth/2)+'px'

		//document.getElementById('closebutton').style.width='300px'
	}
	else if(navigator.appName=='Microsoft Internet Explorer')
	{
		document.getElementById('bgeagalimgbox').style.width=document.getElementById('bgeagalimg').clientWidth+'px'
		document.getElementById('bgeagalimgbox').style.left="50%"
		document.getElementById('bgeagalimgbox').style.marginLeft='-'+(document.getElementById('bgeagalimgbox').clientWidth/2)+'px'

	}
	else
	{
		document.getElementById('bgeagalimgbox').style.width=document.getElementById('bgeagalimg').style.width
		document.getElementById('bgeagalimgbox').style.left="50%"
		document.getElementById('bgeagalimgbox').style.marginLeft='-'+(document.getElementById('bgeagalimgbox').clientWidth/2)+'px'

	}
	
}

