//lib functions


//improve use toggle
//and sort out widths
function showInfo() {

if ($('#infobox').css('display') == 'none' ) {

vleft = $('#photo').offset().left;
vtop = ($('#photo').offset().top + $('#photo').height()) - 220; 
vwidth = $('#photo').get(0).clientWidth - 20;
$('#infobox').css('top',vtop + 'px');

$('#infobox').width(vwidth + 'px');
$('#infobox').css('left',vleft + 'px');
$('#infobox').show();
$('#infoboxbutton').html('Close more information');
}
else
{

$('#infobox').hide();
$('#infoboxbutton').html('Click for more information');
}



}











String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}




slideshowCurrent=1;
function goLeft(show,max)
{
if (slideshowCurrent == 1) {
slideshowCurrent = max;
}
else
{
slideshowCurrent--;
}


src="slideshows/"+show+"/"+slideshowCurrent+".jpg";
obj=document.getElementById('slideshow');
obj.src=src;

}

function goRight(show,max)
{

if (slideshowCurrent == max) {
slideshowCurrent = 1;
}
else
{
slideshowCurrent++;
}


src="slideshows/"+show+"/"+slideshowCurrent+".jpg";
obj=document.getElementById('slideshow');
obj.src=src;


}

function slideshow()
{

//get option value of select 'slideshows'

val = 'goose';

//close window if open

win = window.open(val+'.html','win','width=700,height=500,menubar=0,resizable=0');
}

function goCat()
{
//var cat = document.forms[0].cats.options[documenet.forms[0].cats.selectedIndex].value;
document.forms[0].submit();


}

function showPhoto(ref,ori)
{

if (ori == 'landscape')
specs = "width=700,height=550,menubar=no,status=no,resizable=yes)";
else 
specs = "width=500,height=750,menubar=no,status=no,resizable=yes)";

url = "getphotoPop.php?keyid=" + ref;
win = window.open(url,"_blank",specs);

}

function forgot()
{
user = document.forms[0].action="forgot.php";
document.forms[0].submit();
}

function reminder()
{
document.forms[0].caller.value="1";
document.forms[0].submit();

}

function showError(err)
{
obj = document.getElementById('error');
obj.innerHTML = err;
obj.style.display='block';

}

function explain(st)
{
obj = document.getElementById('explain');
if (st) 
obj.style.display="block";
else
obj.style.display="none";

}





function showStatus(st)
{

obj = document.getElementById('status');



switch (st) {
case '0':
vtxt = 'You must be logged in to use the Lightbox. ';
break;

case '1':
vtxt = 'The image has been added to your lightbox';
break;

case '2':
vtxt = 'This image is already in your lightbox';

break;

case '3':
vtxt = 'Sorry. An error occurred. Please try again later.';
break;

case '4':
vtxt = 'Image not stored. You can only store 20 images in your lightbox. You can remove some items by going to the <a href="lightbox.php" title="Lightbox">Lightbox page</a> and deleting them.';
break;


} //end switch

obj.innerHTML= vtxt;

}

function deleteLightbox(ref)
{

if (confirm("Are you sure you want to remove this image from your light-box?" ))
{

url = "lightbox.php?ref=" + ref + '&del=on' ;
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {   //lose trailing \n!!
          var res=xmlHttp.responseText.rtrim();
          
          
      // return codes
      //0 = user is not logged in
      //1 = image added to lightbox
      //2 = image already in lightbox
     //3 error
     //4 = lightbox full
     if (res=='1') //ok the image was deleted from the lb clear it from the screen
     {
    // obj = document.getElementById('pic_' + ref);
   //  obj.style.display='none';
	location.reload();	
     }
      }
    }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);

}

}



function addToLightbox(ref)
{

url = "lightbox.php?ref=" + ref;
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {   //lose trailing \n!!
          var res=xmlHttp.responseText.rtrim();
          
          
      // return codes
      //0 = user is not logged in
      //1 = image added to lightbox
      //2 = image already in lightbox
     //3 error
     //4 = lightbox full
     showStatus(res);
      }
    }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }


