
  var i=0;
  var imgArray = new Array();
  var imgs;
  var favs;
  var dir;
  var bound;
  var browserdetect;
  var isCount;


  document.onkeyup = function(){

	if(window.event && (window.event.keyCode==27))
	{restore();}

	 if(window.event.keyCode == 16 ||window.event.keyCode == 17 ||window.event.keyCode == 44 ){
                 copyRight();
                 window.clipboardData.clearData();
	  }


	  if(window.event && (window.event.keyCode==42 || window.event.keyCode==44))

	  { // Capture and remap F5
	  //alert('printscreen copyright protected');
	  window.clipboardData.clearData();
	  window.event.keyCode =0;
	  //document.test.src ="c:\test.jpg";
	  }
  }

  
  function clearData()
  {
  	window.clipboardData.clearData();
  }

  function initPics(fo, filist, favlist,indx)
  {

  	  favs = new Array();
  	  favSort = favlist.split(', ');
 	  for (z=0; z < favSort.length; z++)
  	  {
  	  	 favs[favSort[z]] = favSort[z];
  	  }
  	  imgs = new Array(filist);
  	  imgs = filist.split(', ');
  	  
  	  dir=fo;
      
      bound = imgs.length-1;

	  PreLoadImgs();
	  browserdetect=picframe.filters? "ie" : typeof picframe.style.MozOpacity=="string"? "mozilla" : typeof picframe.style.opacity=="string"? "Opera" : "other"
      
      if(indx!='')
      {setPicture(indx);}
      else
      {setPicture(0);}
      
  }

function PreLoadImgs()
{

	for(imgCount = 0;imgCount<=bound;imgCount++)
	{
		imgArray[imgCount] = new Image();
		imgArray[imgCount].src ='./images/'+dir+'/'+imgs[imgCount];
	}
	
	//while (true)
	//{
	//	if (t[0].complete)
	//	{	alert(t[0].complete);
			return;
	//	}
	//}



}


function setCount()
{
	isCount = 'true';
}

function copyRight()
{
	picframe.src='./images/notice.jpg';
}

function restore()
{
	picframe.src='./images/'+dir+'/'+imgs[i];
}

function saveFav(targ, dir)
{
	favs[i] = i;
	for (z=0; z < favs.length; z++)
	{
		if(favs[z]==z)
		{
		  document.fav.indx.value = document.fav.indx.value + ', '+z+':'+imgs[z];
		}
		else if(favs[z]=='d')
		{
		  document.fav.indx.value = document.fav.indx.value + ', d'+z;
	    }

	}
    //alert(document.fav.indx.value);
	document.fav.dir.value = dir;
	document.fav.indx.value = i;
	document.fav.action = targ;
	document.fav.submit();
}

function setFav()
{
	if(favs[i] == i)
	{
		favs[i] = 'd';
		//img_nav.src = "./images/image_nav.jpg"
	}
	else
	{
		favs[i] = i;
		//img_nav.src = "./images/image_nav_fav.jpg"
	}
}

function setPicture(indx)
{

	
	if(indx<0)
	  indx = 0;
	if(indx<=0)
	  img_nav.src = "./images/"+dir+"/images/nav0.jpg";
	if(indx>0 && indx<bound)
	  img_nav.src = "./images/"+dir+"/images/nav1.jpg";
	if(indx==bound)
	  img_nav.src = "./images/"+dir+"/images/nav2.jpg";

	if(indx>bound)
	{  indx=bound;
	   i = indx;
	}
	else
	{
		i = indx;
		slowlow();
	}
	
   if(isCount=='true')
   {
   		displayNum = indx + 1;
		t = displayNum.toString();
		num.src='./images/'+t.charAt(0)+'.jpg';
		if(t.length>1)
		{
		   num2.src='./images/'+t.charAt(1)+'.jpg';
		}
		else
		{num2.src='./images/space.jpg';}
   }
	//if(favs[i] == i)
	//{
		//img_nav.src = "./images/image_nav_fav.jpg"
	//}
	//else
	//{
		//img_nav.src = "./images/towimage_nav.jpg"
	//}
	//alert(picframe.src);
}

function slowhigh(){
	highlighting=setInterval("gradualfade()",30);
}

function slowlow(){
	cleartimer();
	highlighting=setInterval("gradualblack()",30);
}

function changePic()
{
	picframe.src='./images/'+dir+'/'+imgs[i];
	picframe.border=2;
	changing=setInterval("checkChange()",100);
	
}

function instantset(degree){
if (browserdetect=="mozilla")
picframe.style.MozOpacity=degree/100;
else if (browserdetect=="ie")
picframe.filters.alpha.opacity=degree;
}

function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}

function checkChange(){
	if(!imgArray[i].complete)
	{a=0;
	}
	else if(window.changing)
	{clearInterval(changing);
	 slowhigh();
	}

}
function gradualfade(){
//alert('HIGH'+cur2.filters.alpha.opacity);

if (browserdetect=="mozilla" && picframe.style.MozOpacity<1)
	picframe.style.MozOpacity=Math.min(parseFloat(picframe.style.MozOpacity)+0.03, 0.99);
else if (browserdetect=="ie" && picframe.filters.alpha.opacity<100)
	picframe.filters.alpha.opacity+=3;
else if (browserdetect=="Opera" && picframe.style.opacity<1)
{
picframe.style.opacity=Math.min(parseFloat(picframe.style.opacity)+0.03, 0.99);
}
else if (window.highlighting)
 {
	clearInterval(highlighting);

 }
}

function gradualblack(){
if (browserdetect=="mozilla" && picframe.style.MozOpacity>0)
{	picframe.style.MozOpacity=Math.max(parseFloat(picframe.style.MozOpacity)-0.03, 0.00);

}
else if (browserdetect=="ie" && picframe.filters.alpha.opacity>0)
	picframe.filters.alpha.opacity-=3;
else if (browserdetect=="Opera" && picframe.style.opacity>0)
	{
		picframe.style.opacity=Math.max(parseFloat(picframe.style.opacity)-0.03, 0.00);}
else if (window.highlighting)
	{	clearInterval(highlighting);
		changePic();}
}




