// JavaScript Document

window.onresize = function(event)
{
	window.location.href = window.location.href;
}
var pacgalimg = new Array();
var pacgalwidth = new Array();
var pacgalheight = new Array();
var pacgalwidthr = new Array();
var pacgalheightr = new Array();
var pacgalartistr = new Array();
var pacgalartistidr = new Array();
var pacgalkeywordsr = new Array();
var pacgaldescriptionr = new Array();
var pacgalnamer = new Array();
var pacdivtop = new Array();
var pacdivleft = new Array();
playposition = 0;
playing=0;
shuffle=0;
blockerheight = 0;
pstate = 0;
showdesc = 1;
showkeywords = 1;
showartist = 1;
showbodylocation = 1;
showimgname = 1;
imgborder = 0;
captionheight = 125;
captionbgcolor = "#000000";
currentindex = 0;
zoomfactor = 150;
ctrltop = 100;
controlheight = 0;
//controlwidth = 125;
controlwidth = 0;
viewmargin = 30;
pacrows = 5;
paccols = 5;
pacgalwidth[22] = 150;
//zoom = 50;
pacgalheight[22] = 150;
maximg = 150;
sep = 15;
zoom = maximg*zoomfactor/100-maximg;
farborder = (maximg*5)+(sep*6);
zpreview = 0;

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0
var tempY = 0

var sWidth;
var sHeight;
function getWH()
{
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
		sWidth = window.innerWidth,
		sHeight = window.innerHeight
	}else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		sWidth = document.documentElement.clientWidth,
		sHeight = document.documentElement.clientHeight
	}else{
		// older versions of IE
		sWidth = document.getElementsByTagName('body')[0].clientWidth,
		sHeight = document.getElementsByTagName('body')[0].clientHeight
	}
}

getWH();

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function dreset(r,c,iIndex)
{
	if (document.getElementById("div"+r+c) && document.getElementById("img"+r+c))
	{
		objd1 = document.getElementById("div"+r+c);
		obji1 = document.getElementById("img"+r+c);
		obji1.width = pacgalwidth[iIndex];
		obji1.height = pacgalheight[iIndex];
		objd1.style.left = pacdivleft[iIndex]+"px";
		objd1.style.top = pacdivtop[iIndex]+"px";
		document.getElementById("div"+r+c).style.zIndex = 1;
	}
	return;
}

function pacbigpre()
{
	if (zpreview == 1)
	{
		document.getElementById("pplayer").style.visibility = "hidden";
		document.getElementById("divpreview").style.visibility = "hidden";
		document.getElementById("divclose").style.visibility = "hidden";
		document['bigpreview'].src = "../final/gallery/dot-transparent.gif";
		document.getElementById("divpreview2").style.visibility = "hidden";
		document['bigpreview2'].src = "../final/gallery/dot-transparent.gif";
		document.getElementById("controlback").style.visibility = "hidden";
		document.getElementById("controltext").style.visibility = "hidden";
		document.getElementById("controlset").style.visibility = "hidden";
		document.getElementById('blocker2').style.height=blockerheight+"px";
		zpreview = 0;
		objectOpacity = 1;
	}else{
		objectOpacity = .3;
		zpreview = 1;
		theheight = f_clientHeight();
		thewidth = f_clientWidth();
//		getWH();
		dbmarg = (viewmargin*2);
		availH = f_clientHeight()-dbmarg-controlheight-captionheight;
		availW = f_clientWidth()-dbmarg-controlwidth;
		iIndex = tRow*10+tCol;
		obj = document.getElementById("bigpreview");
//		document['bigpreview'].src = "images/"+pacgalimg[iIndex];
		document['bigpreview'].src = "gallery/"+pacgalimg[iIndex];
		document.getElementById("artist").innerHTML = '<a href="gallery.php?artist='+pacgalartistidr[iIndex]+'" class="bodytext"><strong>'+pacgalartistr[iIndex]+'</strong></a>';
		document.getElementById("descr").innerHTML = pacgaldescriptionr[iIndex];
		document.getElementById("imagename").innerHTML = pacgalnamer[iIndex];
		keywordpr = pacgalkeywordsr[iIndex].replace(/\W/gi, " ");
		divided = keywordpr.split(" ");
		resulter = "";
		for (z=0;z<divided.length;z++)
		{
			resulter = resulter+'<a href="gallery.php?keyword='+divided[z]+'" class="bodytext">'+divided[z]+'</a>&nbsp;';
		}
		document.getElementById("keyword").innerHTML = 'keywords: '+resulter; 
		newwidth = pacgalwidthr[iIndex];
		newheight = pacgalheightr[iIndex];
		if (pacgalwidthr[iIndex] > availW || pacgalheightr[iIndex] > availH)
		{
			if (pacgalwidthr[iIndex]/availW > pacgalheightr[iIndex]/availH)
			{
				newwidth=pacgalwidthr[iIndex]/(pacgalwidthr[iIndex]/availW);
				newheight=pacgalheightr[iIndex]/(pacgalwidthr[iIndex]/availW);
			}else{
				newwidth=pacgalwidthr[iIndex]/(pacgalheightr[iIndex]/availH);
				newheight=pacgalheightr[iIndex]/(pacgalheightr[iIndex]/availH);			
			}
			obj.width = newwidth;
			obj.height = newheight;
		}
		availH += controlheight;
		itop = (f_clientHeight()-newheight)/2+f_scrollTop()-(controlheight/2)-(captionheight/2);
		ileft = (f_clientWidth()-newwidth)/2+f_scrollLeft()+(controlwidth/2);
		iheight = newheight+(captionheight/2);
		bheight = newheight-yoffset;
		blockerheight = document.getElementById('blocker2').height;
		document.getElementById('blocker').style.height=bheight+"px";
		document.getElementById('blocker2').style.height=bheight+"px";
//alert(ileft+" = ("+f_clientWidth()+"-"+newwidth+")/2+"+f_scrollLeft()+"+("+controlwidth+")");		
		objd = document.getElementById("divpreview");
		objd.style.left = ileft+"px";
		objd.style.top = itop+"px";
//		objd.style.height = iheight+"px";
		objd.style.backgroundColor = captionbgcolor;
		objc = document.getElementById("divclose");
//==		objn = document.getElementById("pplayer");
		cleft = ileft-15;
		ctop = itop-15;
//==		ntop = ctrltop+f_scrollTop();
		objc.style.left = cleft+"px";
		objc.style.top = ctop+"px";
//==		objn.style.top = ntop+"px";
		objc.style.visibility = "visible";
		objd.style.visibility = "visible";
//==		objn.style.visibility = "visible";
//==		controlleft=(thewidth/2)-(controlwidth/2);
//==		controltop=theheight-controlheight-15+f_scrollTop();
		playposition= parseInt(position) + ((parseInt(tRow)*1 - 1)*5) + (parseInt(tCol)*1 - 1);
//		playartist=
//alert ("getnextimg.php?position="+playposition);

// THIS IS THE CONTROLSET CODE. IT SHOULD BE RE-ENABLED WHENEVER THE SIDE CONTROLS ARE AVAILABLE

/*		objcon=document.getElementById("controlback").style;
		objcon.visibility = "visible";
		objcon.left = controlleft+"px";;
		objcon.top = controltop+"px";;
		objcon=document.getElementById("controltext").style;
		objcon.visibility = "visible";
		objcon.left = controlleft+"px";;
		objcon.top = controltop+"px";;
		objcon=document.getElementById("controlset").style;
		objcon.visibility = "visible";
		controltop+=6;
		objcon.left = controlleft+"px";;
		objcon.top = controltop+"px";; */
	}
	for(r=1;r<=numRows;r++)
	{
		for(c=1;c<=numCols;c++)
		{
			objd1 = document.getElementById("div"+r+c);
			if (document.all)
			{
				objd1.filters.alpha.opacity = objectOpacity;
			}else if(!document.all && document.getElementById) {      
				objd1.style.MozOpacity = objectOpacity;
			}
		}  
	}
	
}

function getMouseXY(e) {
  if (IE) {
	tempX = event.clientX + f_scrollLeft();
    tempY = event.clientY + f_scrollTop();
//	tempX = event.clientX + document.body.scrollLeft
//    tempY = event.clientY + document.body.scrollTop
  } else {
    tempX = e.pageX
    tempY = e.pageY
  }  
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
// ===============================================
//  document.Show.MouseX.value = tempX
//  document.Show.MouseY.value = tempY
//  document.Show.zoomX2.value = document.body.scrollLeft.value;
//  document.Show.zoomX3.value = document.body.scrollTop.value;

// ===============================================
  xstat = (tempX-xoffset-sep)/(sep+maximg);
  ystat = (tempY-yoffset-sep)/(sep+maximg);
  tRow = Math.floor(ystat)+1;
  tCol = Math.floor(xstat)+1;
  X1 = tCol-1;
  X2 = tCol;
  X3 = tCol+1;
  Y1 = tRow-1;
  Y2 = tRow;
  Y3 = tRow+1;
  X2zoom = 1-(Math.abs((xstat)-X2+0.5));
  Y2zoom = 1-(Math.abs((ystat)-Y2+0.5));
  if (X1 < 1 || X1 > numCols) { X1=0; }
  if (X3 < 1 || X3 > numCols) { X3=0;}  
  if (X2 < 1 || X2 > numCols) { X2=0; X2zoom = 0; } 
  if (Y1 < 1 || Y1 > numCols) { Y1=0; }
  if (Y3 < 1 || Y3 > numCols) { Y3=0;}  
  if (Y2 < 1 || Y2 > numCols) { Y2=0; Y2zoom = 0; } 
  if (X3) 
  {
  	X3zoom = (100-(Math.abs(xstat-X3+0.5)*100))/100;
  	if (X3zoom < 0)	{ X3zoom = 0; }
  }else{
    X3zoom = 0;
  }
  if (Y3) 
  {
  	Y3zoom = (100-(Math.abs(ystat-Y3+0.5)*100))/100;
  	if (Y3zoom < 0)	{ Y3zoom = 0; }
  }else{
    Y3zoom = 0;
  }
  if (X1) 
  {
  	zoomer = (Math.abs(xstat-X1+0.5)*100)-100;
  	if (zoomer < 0)
	{
	  X1zoom = Math.abs(zoomer)/100;
	}else{
	  X1zoom = 0;
	}
  }else{
    X1zoom = 0;
  }
  if (Y1) 
  {
  	zoomer = (Math.abs(ystat-Y1+0.5)*100)-100;
  	if (zoomer < 0)
	{
	  Y1zoom = Math.abs(zoomer)/100;
	}else{
	  Y1zoom = 0;
	}
  }else{
    Y1zoom = 0;
  }
/*  document.Show.zoomX1.value = Y1;
  document.Show.zoomX2.value = Y2;
  document.Show.zoomX3.value = Y3;
  document.Show.zoomerX1.value = X1zoom;
  document.Show.zoomerX2.value = X2zoom;
  document.Show.zoomerX3.value = X3zoom;
//  document.Show.zoomY1.value = Y1;
//  document.Show.zoomY2.value = Y2;
//  document.Show.zoomY3.value = Y3;
  document.Show.zoomerY1.value = Y1zoom;
  document.Show.zoomerY2.value = Y2zoom;
  document.Show.zoomerY3.value = Y3zoom;
  document.Show.iRow.value = tRow;
  document.Show.iCol.value = tCol;
*/

  for(r=1;r<=numRows;r++)
  {
	for(c=1;c<=numCols;c++)
	{
	  iIndex = r*10+c;
	  if (r==Y1 || r==Y2 || r==Y3)
	  {
	  	if (c!=X1 && c!=X2 && c!=X3)
		{
			dreset(r,c,iIndex);
		}
	  }else{
		dreset(r,c,iIndex);
	  }
	}  
  }
  if (Y3 != 0 && X1 != 0)
  {
//	thediv = "div"+Y3+X1;
//	theimg = "img"+Y3+X1;
	iIndex = Y3*10+X1;
	iMath = zoom*2*X1zoom*Y3zoom;
	ratioi = pacgalwidth[iIndex]/pacgalheight[iIndex];
	newleft = pacdivleft[iIndex]-iMath/2;
	if (newleft < 0) { newleft = 0; }
	if (newleft+pacgalwidth[iIndex]+iMath > sWidth) { newleft = sWidth-(pacgalwidth[iIndex]+iMath); }
	newtop = pacdivtop[iIndex]-iMath/2;
	if (newtop < 0) { newtop = 0; }
	objd1 = document.getElementById("div"+Y3+X1);
	obji1 = document.getElementById("img"+Y3+X1);
	if (objd1 && obji1)
	{
		obji1.width = pacgalwidth[iIndex]+iMath;
		objd1.style.left = newleft+"px";
		obji1.height = pacgalheight[iIndex]+iMath;
		objd1.style.top = newtop+"px";
	}
	if (document.getElementById("div"+Y3+X1))
	{
		document.getElementById("div"+Y3+X1).style.zIndex = 25;
	}
  }
  if (Y3 != 0 && X3 != 0)
  {
//	thediv = "div"+Y3+X3;
//	theimg = "img"+Y3+X3;
	iIndex = Y3*10+X3;
	iMath = zoom*2*X3zoom*Y3zoom;
	ratioi = pacgalwidth[iIndex]/pacgalheight[iIndex];
	newleft = pacdivleft[iIndex]-iMath/2;
	if (newleft < 0) { newleft = 0; }
	if (newleft+pacgalwidth[iIndex]+iMath > sWidth) { newleft = sWidth-(pacgalwidth[iIndex]+iMath); }
	newtop = pacdivtop[iIndex]-iMath/2;
	if (newtop < 0) { newtop = 0; }
	objd1 = document.getElementById("div"+Y3+X3);
	obji1 = document.getElementById("img"+Y3+X3);
	if (objd1 && obji1)
	{
		obji1.width = pacgalwidth[iIndex]+iMath;
		objd1.style.left = newleft+"px";
		obji1.height = pacgalheight[iIndex]+iMath;
		objd1.style.top = newtop+"px";
	}
	if (document.getElementById("div"+Y3+X3))
	{
		document.getElementById("div"+Y3+X3).style.zIndex = 25;
	}
  }
  if (Y1 != 0 && X1 != 0)
  {
//	thediv = "div"+Y1+X1;
//	theimg = "img"+Y1+X1;
	iIndex = Y1*10+X1;
	iMath = zoom*2*X1zoom*Y1zoom;
	ratioi = pacgalwidth[iIndex]/pacgalheight[iIndex];
	newleft = pacdivleft[iIndex]-iMath/2;
	if (newleft < 0) { newleft = 0; }
	if (newleft+pacgalwidth[iIndex]+iMath > sWidth) { newleft = sWidth-(pacgalwidth[iIndex]+iMath); }
	newtop = pacdivtop[iIndex]-iMath/2;
	if (newtop < 0) { newtop = 0; }
	objd1 = document.getElementById("div"+Y1+X1);
	obji1 = document.getElementById("img"+Y1+X1);
	if (objd1 && obji1)
	{
		obji1.width = pacgalwidth[iIndex]+iMath;
		objd1.style.left = newleft+"px";
		obji1.height = pacgalheight[iIndex]+iMath;
		objd1.style.top = newtop+"px";
	}
	if (document.getElementById("div"+Y1+X1))
	{
		document.getElementById("div"+Y1+X1).style.zIndex = 25;
	}
  }
  if (Y1 != 0 && X3 != 0)
  {
//	thediv = "div"+Y1+X3;
//	theimg = "img"+Y1+X3;
	iIndex = Y1*10+X3;
	iMath = zoom*2*X3zoom*Y1zoom;
	ratioi = pacgalwidth[iIndex]/pacgalheight[iIndex];
	newleft = pacdivleft[iIndex]-iMath/2;
	if (newleft < 0) { newleft = 0; }
	if (newleft+pacgalwidth[iIndex]+iMath > sWidth) { newleft = sWidth-(pacgalwidth[iIndex]+iMath); }
	newtop = pacdivtop[iIndex]-iMath/2;
	if (newtop < 0) { newtop = 0; }
	objd1 = document.getElementById("div"+Y1+X3);
	obji1 = document.getElementById("img"+Y1+X3);
	if (objd1 && obji1)
	{
		obji1.width = pacgalwidth[iIndex]+iMath;
		objd1.style.left = newleft+"px";
		obji1.height = pacgalheight[iIndex]+iMath;
		objd1.style.top = newtop+"px";
	}
	if (document.getElementById("div"+Y1+X3))
	{
		document.getElementById("div"+Y1+X3).style.zIndex = 25;
	}
  }
  if (Y1 != 0 && X2 != 0)
  {
//	thediv = "div"+Y1+tCol;
//	theimg = "img"+Y1+tCol;
	iIndex = Y1*10+tCol;
	iMath = zoom*2*X2zoom*Y1zoom;
	ratioi = pacgalwidth[iIndex]/pacgalheight[iIndex];
	newleft = pacdivleft[iIndex]-iMath/2;
	if (newleft < 0) { newleft = 0; }
	if (newleft+pacgalwidth[iIndex]+iMath > sWidth) { newleft = sWidth-(pacgalwidth[iIndex]+iMath); }
	newtop = pacdivtop[iIndex]-iMath/2;
	if (newtop < 0) { newtop = 0; }
	objd1 = document.getElementById("div"+Y1+tCol);
	obji1 = document.getElementById("img"+Y1+tCol);
	if (objd1 && obji1)
	{
		obji1.width = pacgalwidth[iIndex]+iMath;
		objd1.style.left = newleft+"px";
		obji1.height = pacgalheight[iIndex]+iMath;
		objd1.style.top = newtop+"px";
	}
	if (document.getElementById("div"+Y1+tCol))
	{
		document.getElementById("div"+Y1+tCol).style.zIndex = 50;
	}
  }
  if (Y2 != 0 && X1 != 0)
  {
//	thediv = "div"+tRow+X1;
//	theimg = "img"+tRow+X1;
	iIndex = Y2*10+X1;
	iMath = zoom*2*X1zoom*Y2zoom;
	ratioi = pacgalwidth[iIndex]/pacgalheight[iIndex];
	newleft = pacdivleft[iIndex]-iMath/2;
	if (newleft < 0) { newleft = 0; }
	if (newleft+pacgalwidth[iIndex]+iMath > sWidth) { newleft = sWidth-(pacgalwidth[iIndex]+iMath); }
	newtop = pacdivtop[iIndex]-iMath/2;
	if (newtop < 0) { newtop = 0; }
	objd1 = document.getElementById("div"+tRow+X1);
	obji1 = document.getElementById("img"+tRow+X1);
	if (objd1 && obji1)
	{
		obji1.width = pacgalwidth[iIndex]+iMath;
		objd1.style.left = newleft+"px";
		obji1.height = pacgalheight[iIndex]+iMath;
		objd1.style.top = newtop+"px";
	}
	if (document.getElementById("div"+tRow+X1))
	{
		document.getElementById("div"+tRow+X1).style.zIndex = 50;
	}
  }
  if (Y2 != 0 && X2 != 0)
  {
	iIndex = Y2*10+X2;
	objd2 = document.getElementById("div"+tRow+X2);
	obji2 = document.getElementById("img"+tRow+X2);
	iMath = zoom*2*X2zoom*Y2zoom;
	ratioi = pacgalwidth[iIndex]/pacgalheight[iIndex];
	newleft = pacdivleft[iIndex]-iMath/2;
	if (newleft < 0) { newleft = 0; }
	if (newleft+pacgalwidth[iIndex]+iMath > sWidth) { newleft = sWidth-(pacgalwidth[iIndex]+iMath); }
	newtop = pacdivtop[iIndex]-iMath/2;
	if (newtop < 0) { newtop = 0; }
	if (obji2 && objd2)
	{
		obji2.width = pacgalwidth[iIndex]+iMath;
		objd2.style.left = newleft+"px";
		obji2.height = pacgalheight[iIndex]+iMath;
		objd2.style.top = newtop+"px";
	}
	if (document.getElementById("div"+tRow+X2))
	{
		document.getElementById("div"+tRow+X2).style.zIndex = 100;
	}
	
/*    if (currentindex)
	{
		if (!iMath)
		{
			document.getElementById("div"+currentindex).style.zIndex = 1;
		}else{
			document.getElementById("div"+currentindex).style.zIndex = 50;
		}
	}
	currentindex = tRow*10+X2;
	objd2.style.zIndex = 100;*/
  }
  if (Y2 != 0 && X3 != 0)
  {
	iIndex = Y2*10+X3;
	iMath = zoom*2*X3zoom*Y2zoom;
	objd3 = document.getElementById("div"+tRow+X3);
	obji3 = document.getElementById("img"+tRow+X3);
	ratioi = pacgalwidth[iIndex]/pacgalheight[iIndex];
	newleft = pacdivleft[iIndex]-iMath/2;
	if (newleft < 0) { newleft = 0; }
	if (newleft+pacgalwidth[iIndex]+iMath > sWidth) { newleft = sWidth-(pacgalwidth[iIndex]+iMath); }
	newtop = pacdivtop[iIndex]-iMath/2;
	if (newtop < 0) { newtop = 0; }
	if (objd3 && obji3)
	{
		obji3.width = pacgalwidth[iIndex]+iMath;
		objd3.style.left = newleft+"px";
		obji3.height = pacgalheight[iIndex]+iMath;
		objd3.style.top = newtop+"px";
	}
	if (document.getElementById("div"+tRow+X3))
	{
		document.getElementById("div"+tRow+X3).style.zIndex = 50;
	}
  }	
  if (Y3 != 0 && X2 != 0)
  {
	iIndex = Y3*10+tCol;
	iMath = zoom*2*X2zoom*Y3zoom;
	objd3 = document.getElementById("div"+Y3+tCol);
	obji3 = document.getElementById("img"+Y3+tCol);
	ratioi = pacgalwidth[iIndex]/pacgalheight[iIndex];
	newleft = pacdivleft[iIndex]-iMath/2;
	if (newleft < 0) { newleft = 0; }
	if (newleft+pacgalwidth[iIndex]+iMath > sWidth) { newleft = sWidth-(pacgalwidth[iIndex]+iMath); }
	newtop = pacdivtop[iIndex]-iMath/2;
	if (newtop < 0) { newtop = 0; }
	if (objd3 && obji3)
	{
		obji3.width = pacgalwidth[iIndex]+iMath;
		objd3.style.left = newleft+"px";
		obji3.height = pacgalheight[iIndex]+iMath;
		objd3.style.top = newtop+"px";
	}
	if (document.getElementById("div"+Y3+tCol))
	{
		document.getElementById("div"+Y3+tCol).style.zIndex = 50;
	}
  }	
//	obji.height = pacgalheight[pacgalitem]+((zoom*2)/ratioi);

  return true
}

function centergal()
{
//	alert(zoomfactor+","+paccols+","+sep);
	twidth=f_clientWidth();
	xoffset = (twidth/2)-((zoomfactor*paccols)/2)-(((paccols-1)*sep)/2);
	document.getElementById("blocker").style.left=xoffset+"px";
	for(r=1;r<=numRows;r++)
	{
		for(c=1;c<=numCols;c++)
		{
			pIndex=r*10+c;
			cc=c-1;
			pacdivleft[pIndex]=xoffset+(cc*(zoomfactor+sep));
//alert(pacdivleft[pIndex]);
//alert(r+c+","+pacdivleft[pIndex]);	
			dreset(r,c,pIndex);
		}
	}
//	xoffset = (f_clientWidth()/2)-(zoomfactor*paccols)-((paccols-1)*sep);
}

function changeplaystate()
{
	if (pstate == 1)
	{
	    obj = document.getElementById('Play');
		obj.style.background = 'url('+alpaca[imagepos]+')';  


		pstate=0;	
	}else{
		pstate=1;			
	}
}

function fader()
{
  if (!pcycle)
  {
    setTimeout("opacity('bigpreview', 120, 0, 1000)", delay);
    setTimeout("opacity('bigpreview2', 0, 120, 1000)", delay);
	pcycle = 1;
  }else{	
    setTimeout("opacity('bigpreview', 0, 120, 1000)", delay);
    setTimeout("opacity('bigpreview2', 120, 0, 1000)", delay);
	pcycle = 0;
  }
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
  switchimages();	
  fader();
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function startplay()
{
	if (playing == 1)
	{
		playing=0;
	}else{
		playing=1;
		playposition+=1;
		getnext();	
	}
	return;
}

function stopplay()
{
	playing=0;
}

function backplay()
{
		playposition-=1;
		getnext();	
}

function forwardplay()
{
		playposition+=1;
		getnext();	
}

function homeplay()
{
		playposition=0;
		getnext();	
}

function getnext()
{
	var xhr;
	if(window.XMLHttpRequest && !(window.ActiveXObject))
	{
		xhr = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		alert("AJAX not supportted");
		return;
	}
	var url = 'getnextimage.php?position='+playposition+navextra;
alert(url);	
	xhr.open('GET', url ,true);
	xhr.send('');
	xhr.onreadystatechange = function()
	{
		var ready = xhr.readyState;
		// Did the request complete
		if (ready == 4)
		{
			var status = xhr.status;
			// If the response request was a success
			if (status >= 200 && status < 300)
			{
				thedata.length = 0;
				records = xhr.responseText.split("<|>");
				
/*				
		objectOpacity = .3;
		zpreview = 1;
		theheight = f_clientHeight();
		thewidth = f_clientWidth();
//		getWH();
		dbmarg = (viewmargin*2);
		availH = f_clientHeight()-dbmarg-controlheight-captionheight;
		availW = f_clientWidth()-dbmarg-controlwidth;
		iIndex = tRow*10+tCol;
		if (shuffle == 0)
		{
			shuffle =1;
			bigpre="bigpreview"+2;
			divpre="divpreview"+2;
			bigprec="bigpreview";
			divprec="divpreview";
		}else{
			shuffle =0;
			bigpre="bigpreview";
			divpre="divpreview";
			bigprec="bigpreview"+2;
			divprec="divpreview"+2;
		}
		obj = document.getElementById(bigpre);
//		document['bigpreview'].src = "images/"+pacgalimg[iIndex];
		document['bigpreview'].src = "gallery/"+pacgalimg[iIndex];
		document.getElementById("artist").innerHTML = '<a href="gallery.php?artist='+pacgalartistidr[iIndex]+'" class="bodytext"><strong>'+pacgalartistr[iIndex]+'</strong></a>';
		document.getElementById("descr").innerHTML = pacgaldescriptionr[iIndex];
		document.getElementById("imagename").innerHTML = pacgalnamer[iIndex];
		keywordpr = pacgalkeywordsr[iIndex].replace(/\W/gi, " ");
		divided = keywordpr.split(" ");
		resulter = "";
		for (z=0;z<divided.length;z++)
		{
			resulter = resulter+'<a href="gallery.php?keyword='+divided[z]+'" class="bodytext">'+divided[z]+'</a>&nbsp;';
		}
		document.getElementById("keyword").innerHTML = 'keywords: '+resulter; 
		newwidth = pacgalwidthr[iIndex];
		newheight = pacgalheightr[iIndex];
		if (pacgalwidthr[iIndex] > availW || pacgalheightr[iIndex] > availH)
		{
			if (pacgalwidthr[iIndex]/availW > pacgalheightr[iIndex]/availH)
			{
				newwidth=pacgalwidthr[iIndex]/(pacgalwidthr[iIndex]/availW);
				newheight=pacgalheightr[iIndex]/(pacgalwidthr[iIndex]/availW);
			}else{
				newwidth=pacgalwidthr[iIndex]/(pacgalheightr[iIndex]/availH);
				newheight=pacgalheightr[iIndex]/(pacgalheightr[iIndex]/availH);			
			}
			obj.width = newwidth;
			obj.height = newheight;
		}
		availH += controlheight;
		itop = (f_clientHeight()-newheight)/2+f_scrollTop()-(controlheight/2)-(captionheight/2);
		ileft = (f_clientWidth()-newwidth)/2+f_scrollLeft()+(controlwidth/2);
		iheight = newheight+(captionheight/2);
		bheight = newheight-yoffset;
		blockerheight = document.getElementById('blocker2').height;
		document.getElementById('blocker').style.height=bheight+"px";
		document.getElementById('blocker2').style.height=bheight+"px";
//alert(ileft+" = ("+f_clientWidth()+"-"+newwidth+")/2+"+f_scrollLeft()+"+("+controlwidth+")");		
		objd = document.getElementById(divpre);
		objd = document.getElementById(divprec).style.visibility="hidden";
		objd.style.left = ileft+"px";
		objd.style.top = itop+"px";
//		objd.style.height = iheight+"px";
		objd.style.backgroundColor = captionbgcolor;
		objc = document.getElementById("divclose");
		cleft = ileft-15;
		ctop = itop-15;
		objc.style.left = cleft+"px";
		objc.style.top = ctop+"px";
		objc.style.visibility = "visible";
		objd.style.visibility = "visible";
	}
	for(r=1;r<=numRows;r++)
	{
		for(c=1;c<=numCols;c++)
		{
			objd1 = document.getElementById("div"+r+c);
			if (document.all)
			{
				objd1.filters.alpha.opacity = objectOpacity;
			}else if(!document.all && document.getElementById) {      
				objd1.style.MozOpacity = objectOpacity;
			}
		}  
	}
	
}
	*/			
				
				
			}else{
				alert('An error occurred, Error Code: AJ-00005-002. Please call Pace Computing and Design at (717) 264-1637.'); 
			}
		}
	}
	return;
}



