var theGallery=new Array();
var loadingImg=0;
function displayGallery(srcObj,fileatt,titleatt) {
	theGallery=new Array();
	gindex=-1;
	cont=srcObj.parentNode;
	imgs=cont.getElementsByTagName(srcObj.tagName);
	ix=-1;
	for(i=0;i<imgs.length;i++) {
		if (imgs[i].className==srcObj.className) {
			if (src=imgs[i].getAttribute(fileatt)) {
				tit=imgs[i].getAttribute(titleatt);
				theGallery.push([src,tit]);
				ix++;
				if (imgs[i]==srcObj) gindex=ix;
			}
		}
	}
	if (gindex>=0) {
		con='<div id="picloader" style="display:block;visibility:hidden;position:absolute"></div><table><tr><td style="text-align:center;vertical-align:middle;min-width:200px;min-height:200px;background:url(/skin/loading.gif) center center no-repeat"><div id="picholder"></div>';
		con+="</td></tr></table>";
		con+="<div id='arrows' style='height:20px;margin:1px auto'></div>";
		con+="<table cellpadding=0 cellspacing=0 id='bubble'><tr><td class='bubl'></td><td class='bub' id='bubbletext'>bubble</td><td class='bubr'></td></tr><tr><td colspan=3 class='bubp'></td></tr></table>";
		startFadeUp();
		ins=returnRoundedBox('dialogBox','<div id="phototitle">Loading...</div>',con,true,5,null,null,true,true);
		pasteRawHTML(ins,document.body);
		db=objid("dialogBox");
		fader(db,0);
		centerObject(objid("dialogBox"));
		loadingImg=gindex;
		fadeObject(db,0,100,5,loadImage);
	}
}
function loadImage() {
	objid("arrows").innerHTML="";
	hideBubble();
	fadeObject(objid("picholder"),100,0,10,null);
	objid("phototitle").innerHTML=theGallery[loadingImg][1];
	objid("picloader").innerHTML='<img id="imgloading" src="'+theGallery[loadingImg][0]+'" onload="setTimeout(\'picLoaded()\',200)" />';
}
function picLoaded() {
	p=objid("imgloading");
	t=objid("picholder");
	resizeObject(t,true,true,t.clientWidth,t.clientHeight,p.clientWidth,p.clientHeight,objid("dialogBox"),20,2,false,displayPic);
	objid("picloader").innerHTML="";
}
function displayPic() {
	t=objid("picholder");
	im="<table cellpadding=0 cellspacing=0 style='background:url("+theGallery[loadingImg][0]+") no-repeat;width:"+t.clientWidth+"px;height:"+t.clientHeight+"px' />";
	im+="<tr><td";
	if (loadingImg>0) {
		im+=" class='imgButton' onclick='prepareImage("+(loadingImg-1)+")'><div id='tdprev'>prev</div>";
	}else{
		im+=" class='noimgButton'>";
	}
	im+="</td><td class='imgButton' onclick='removeTheNode(\"dialogBox\");startFadeDown();'><div id='tdclose'>close</div></td><td";
	if (loadingImg<theGallery.length-1) {
		im+=" class='imgButton' onclick='prepareImage("+(loadingImg+1)+")'><div id='tdnext'>next</div>";
	}else{
		im+=" class='noimgButton'>";
	}
	im+="</td></tr></table>";
	t.innerHTML=im;
	fadeObject(objid("picholder"),0,100,10,null);
	if (loadingImg>0) fader(objid('tdprev'),50);
	fader(objid('tdclose'),50);
	if (loadingImg<theGallery.length-1) fader(objid('tdnext'),50);
	picArrows();
}
function picArrows() {
	ins="";
	if (loadingImg>0) ins+="<div class='prev' showimg="+(loadingImg-1)+" onmousemove='setBubble(this,event)' onmouseout='hideBubble()' onclick='prepareImage("+(loadingImg-1)+")'></div>";
	for(ai=0;ai<theGallery.length;ai++) {
		if (loadingImg==ai) {
			ins+="<div class='picCur' ></div>";
		}else{
			ins+="<div class='picSel' showimg="+ai+" onmousemove='setBubble(this,event)' onmouseout='hideBubble()' onclick='prepareImage("+ai+")'></div>";
		}
	}
	if (loadingImg<theGallery.length-1) ins+="<div class='next' showimg="+(loadingImg+1)+" onmousemove='setBubble(this,event)' onmouseout='hideBubble()' onclick='prepareImage("+(loadingImg+1)+")'></div>";
	ar=objid("arrows");
	w=(theGallery.length*12)+44;
	ar.style.width=w+"px";
	ar.innerHTML=ins;
}
function prepareImage(i) {
	loadingImg=i;
	loadImage();
}
var currentbubbletext="";
function setBubble(srcObj,e) {
	loc=eventLocation(e,false);
	b=objid("bubble");
	b.style.display="block";
	if (srcObj.getAttribute("showimg")!=currentbubbletext) {
		currentbubbletext=srcObj.getAttribute("showimg");
		objid("bubbletext").innerHTML=theGallery[currentbubbletext][1];
	}
	b.style.left=(loc[0]-(b.clientWidth/2))+"px";
	b.style.top=(loc[1]-b.clientHeight-5)+"px";
}
function hideBubble() {
	objid("bubble").style.display="none";
}
	
	