function launchImageGallery(collID){
	var IGwin=window.open("/imageGallery/default.asp?CollectionID=" + collID,"BGEAIGWIN","width=650,height=520,scrollbars=0,status=0,menubar=0,toolbar=0,resizeable=1,location=0"); 
	IGwin.focus(); 
}

var xgallery=new Array()
var curimg
var sl

function grabgallery(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 = updateGallery
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
	request.send(sel)
}

function updateGallery()
{
	//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)
				showbgeagal(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 showbgeagal(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", "bgeagallerywrapper")

	newgalwrapper.innerHTML='<div id="bgeagalimgbox" class="bgeagalimgbox"></div>'
	newgalwrapper.innerHTML+='<div id="bgeagalbar" class="bgeagalbar">'
	newgalwrapper.innerHTML+='</div>'
	
	document.body.insertBefore(newgalwrapper, document.body.firstChild)
	document.getElementById('bgeagallerywrapper').className='bgeagallerywrapper'



	if(!((navigator.appName=='Microsoft Internet Explorer') && (navigator.appVersion.indexOf('MSIE 6.0')>0)))
	{
		var newgalmask=document.createElement("div")
		
		newgalmask.setAttribute("id", "bgeagallerymask")
		newgalmask.setAttribute("class", "bgeagallerymask")
		
		document.body.insertBefore(newgalmask, document.body.firstChild)
		document.getElementById('bgeagallerymask').className='bgeagallerymask'
	}

	document.getElementById('bgeagallerywrapper').style.width=document.body.clientWidth

	var imghtml=''
	var barhtml=''
	
	imghtml+='<img src="'+unescape(xgallery[curimg][1])+'" id="bgeagalimg" onload="centerbgeaimg();document.getElementById(\'bgeagalimgbox\').style.visibility=\'visible\';">'



	barhtml+='<div style="display:table;width:900px;background-color:transparent;">'
	
	barhtml+='<div id="bgeacaption" class="baritem" style="width:390px;text-align:left;">'+unescape(xgallery[curimg][0])+'</div>'
	
	barhtml+='<div id="barofwrapper" class="baritem" style="width:140px;">'
	//barhtml+='<div id="barnav" style="position:relative;width:120px;background-color:orange;">' //position:absolute;left:50%;
	barhtml+='<div class="baritemarrow" id="bararrow"><a href="javascript:showimg(false,-1)"><img src="/images/bgeaslideshow/arrowleft.png" style="border:0px;"></a></div>'
	barhtml+='<div id="barof" style="position:relative;bottom:0px;float:left;margin:0px;padding:0px;width:70px;text-align:center;">'+(curimg+1)+' / '+xgallery.length+'</div>'
	barhtml+='<div class="baritemarrow"><a href="javascript:showimg(false,1)"><img src="/images/bgeaslideshow/arrowright.png" style="border:0px;"></a></div>'
	//barhtml+='blah'
	//barhtml+='</div>'
	barhtml+='</div>'
	
	barhtml+='<div id="closebutton" class="baritem" style="text-align:right;width:310px;"><a href="javascript:closebgeagal()"><img src="/images/bgeaslideshow/close.png" style="border:0px;width:25px;position:relative;right:3px;"></a></div>'
	
	barhtml+='</div>'
//alert(document.getElementById('barofwrapper').clientWidth+' '+document.getElementById('barofwrapper').style.width)
	
	if(!((navigator.appName=='Microsoft Internet Explorer') && (navigator.appVersion.indexOf('MSIE 6.0')>0)))
	{
		barhtml+='<div id="bgeagalsliderwrapper" class="bgeagalsliderwrapper"><div id="bgeagalslider"><div id="bgeagalhandle"></div></div></div>'
	}


	document.getElementById('bgeagalimgbox').innerHTML=imghtml
	document.getElementById('bgeagalbar').innerHTML=barhtml

	var vals='['
	for(var x=0;x<xgallery.length;x++)
	{
		vals+=x+', '
	}
	vals=vals.substr(0,vals.length-2)
	vals+=']'
	//alert(vals)
	if(!((navigator.appName=='Microsoft Internet Explorer') && (navigator.appVersion.indexOf('MSIE 6.0')>0)))
	{
		//alert($R(0,xgallery.length)+'\n ' + xgallery.length+'\n '+vals)
		sl = new Control.Slider('bgeagalhandle','bgeagalslider',{axis:'horizontal',alignX: 0,alignY: 0,minimum:0,maximum:xgallery.length,range: $R(0,(xgallery.length-1)),values:eval(vals),sliderValue: 0,increment:5,onSlide:function(value){;showimg(true,value)},onChange:function(value){showimg(true,value)}});
	}

	showimg(true,0)
}

function showimg(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
		}
		if(!((navigator.appName=='Microsoft Internet Explorer') && (navigator.appVersion.indexOf('MSIE 6.0')>0)))
		{
			sl.setValue(curimg)
		}
	}

	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=''
	document.getElementById('barof').innerHTML=(curimg+1)+' / '+xgallery.length

	/*document.getElementById('barnav').style.width=(document.getElementById('bararrow').clientWidth*2)+25+document.getElementById('barof').clientWidth+'px'
	var newmargin='0px 0px 0px -'+(document.getElementById('barnav').clientWidth/2)+'px'
	document.getElementById('barnav').style.margin=newmargin*/
	
	/*document.getElementById('barnav').style.width='180px'
	document.getElementById('barnav').style.margin='0px 0px 0px 100px'*/

	centerbgeaimg()
}

function centerbgeaimg()
{

	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'
		//document.getElementById('bgeagalimgbox').style.left=(document.body.clientWidth/2)-(document.getElementById('bgeagalimgbox').clientWidth/2)+'px'
		/*document.getElementById('bgeagalimgbox').style.top=((document.body.clientHeight-50)/2)-(document.getElementById('bgeagalimgbox').clientHeight/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'

		//document.getElementById('bgeagalimgbox').style.left=(document.body.clientWidth/2)-(document.getElementById('bgeagalimgbox').clientWidth/2)+'px'
		/*document.getElementById('bgeagalimgbox').style.top=((window.innerHeight-50)/2)-(document.getElementById('bgeagalimgbox').clientHeight/2)+'px'*/
	}
	
}

function closebgeagal()
{
	var childnode=document.getElementById("bgeagallerywrapper")
	var removednode=document.body.removeChild(childnode)

	childnode=document.getElementById("bgeagallerymask")
	removednode=document.body.removeChild(childnode)
}