///////////////////////// property thumnail manager
ScrollAmount = 506;
scrollvalue  = 0;
function scroll(scrollright)
{
  scrollvalue += 5;
  objDIV = document.getElementById('thumbs');
  if (scrollright == 1)
    objDIV.scrollLeft += 5;
  else 
    objDIV.scrollLeft -= 5;

  if (scrollvalue <= ScrollAmount)
    process = window.setTimeout("scroll('"+scrollright+"')",5);
  else
    scrollvalue = 0;
}


//////////////////////// property slideshow manager

slink  = [""];
sinfo  = ["images/propertyshow.jpg"];

var sc      = sinfo.length-1;				// set to length of description array -1 as counter used starts at 0 but length starts counting at 1
var t       = 0;					// timer
var pos     = 0;					// current position
var sdelay  = 3000;					// slideshow delay

function slidelink()  { if (slink[pos])   window.location="display-property.php?prid="+slink[pos];else return;}

//window.location="#";}

iwid = 1;						// increment width

var lastused = 0;					// keep track of last value for quick and dirty comparison
var newsrc   = 0;					// what image is coming up next.
var chkpause = 0;					// if paused don't allow pos to be incremented. test
var chkstatus = 0;					// check status of fade if 1 fading down existing image.
/////////////////////////////////////////
// function to show slideshow
/////////////////////////////////////////
function sshowold(status)
{
///////// for generic incrementation

  chkstatus = 1;
  if (sinfo.length <= 0) return;

  if (pos >= sinfo.length-1)
    pos = 0;
  else
    if (lastused) pos++;				// slideshow drops 0 on start, so if last used not assigned then don't inc pos.

  lastused = 1;
  if (sinfo[pos])
  {
    newsrc = "properties/"+sinfo[pos];
    document.images['prelo'].src = newsrc;
  }

  iwid = 1;
  t=setTimeout("switchpic()",sdelay);
}

/////////////////////////////////////////
// function to expand image
/////////////////////////////////////////
function growimg()
{
  document.images['sshowimg'].src = newsrc;
  document.images['sshowimg'].width = iwid;

 if (iwid <= 599)
 {
   iwid = iwid+50;
   if (iwid > 600) iwid=600;
   t = setTimeout("growimg()",1);
 }
 else
 {
   waitshow();
 }
}

/////////////////////////////////////////
// function to restart slideshow after pause
/////////////////////////////////////////
function waitshow(status)
{
 clearTimeout(t);
 if (status)
 {
   switch(chkstatus)
   {
     case 1:
     pos--;
     sshow();
     break;

     case 2:
     fadeit();
     break;

     case 3:
     fadeitup();
     break;

     case 4:
     default:
     checkimgstatus();
     break;
   }
 }
 else
  return;


// clearTimeout(t);
// if (status)
//   fadeitup();
// else
//  return;
//if (sinfo.length <= 0) return;
//if (iwid <= 599)				// trying this instead so if image not complete. continue.
// growimg();
//else
//  t = setTimeout("sshow()",sdelay);
}

//////////////////////////////////////
////////// for image fade in/out
/////////////////////////////////////
  var browser=navigator.appName;
  var b_version=navigator.appVersion;
  var bversion=parseFloat(b_version);
  if (browser=="Microsoft Internet Explorer")
  {
    if (bversion <= 4)
     isitie = 1;
    else
     isitie = 2;
  }
  else
    isitie = 0;

  var fn1 = 1;
  var fn2 = 100;

//////////////////////////////////////////////////////////////
function sshow(status)
{
  chkstatus = 1;
  if (sinfo.length <= 0) return;
  if (pos >= sinfo.length-1)
    pos = 0;
  else
    if (lastused) pos++;				// slideshow drops 0 on start, so if last used not assigned then don't inc pos. if paused don't inc
  lastused = 1;

  if (sinfo[pos])
  {
    newsrc = "properties/"+sinfo[pos];
    document.images['prelo'].src = newsrc;
  }

  if (fn1 < 1 || fn2 < 100)		//to ensure image is fully faded in if they mid click
   checkimgstatus();

  t=setTimeout("fadeit()",sdelay);
}

///////////////////////////////////////////////
function fadeit()
{
  delay = 50;
  fn1 = fn1 - 0.11;
  fn2 = fn2 - 10;

  chkstatus = 2;

  document.images['sshowimg'].style.opacity =fn1;
  if (isitie)
    document.images['sshowimg'].style.filter = 'alpha(opacity='+fn2+')';

// 100803 was just fn2 now trying force above 0 to ensure it doesn't revert to negative which yields no image
  if (fn2 >0)
    t=setTimeout("fadeit()",delay);
  else
  {
    document.images['sshowimg'].src = newsrc;

    var pic=new Image();

    if (isitie == 1)
    {
      pic.onload = function()  {t=setTimeout("fadeitup()",delay);};
      pic.onerror = function() {t=setTimeout("fadeitup()",delay);};
      pic.src= newsrc;
    }
    else
    {
     pic.src= newsrc;
     if(pic.complete) t=setTimeout("fadeitup()",delay);
      else t=setTimeout("checkimgstatus()",delay);
    }
  }
}

/////////////////////////////////////
function fadeitup()
{
  delay = 25;
  fn1 = fn1 + 0.11;
  fn2 = fn2 + 10;

  chkstatus = 3;

  document.images['sshowimg'].style.opacity =fn1;
  if (isitie)
    document.images['sshowimg'].style.filter = 'alpha(opacity='+fn2+')';

  if (fn2 < 100)
    t=setTimeout("fadeitup()",delay);
  else
    sshow();
}

/////////
function checkimgstatus()
{

  chkstatus = 4;
  delay = 100;
  var pic=new Image(600,450);
  pic.src= newsrc;
  if(pic.complete) fadeitup();
    else t=setTimeout("checkimgstatus()",delay);
}




/////////////////////////////////////////
//  FUNCTIONS to handle search form drop downs
/////////////////////////////////////////

//document.onclick = closecurrent; 
function inuse(currentsel)  { currentsel.style.backgroundColor="#aaaaaa"; }
function outuse(currentsel) { currentsel.style.backgroundColor="#888888"; }

var curlist = 0;		// keep track of which list is currently active

function showlist(id)
{
  var same = 0;
  if (curlist) { same = curlist;closecurrent();}	// if a list is active then it wasn't shutdown, ie no selection made, so now close it
  curlist = document.getElementById(id);		// assign current selection to current list variable
  if (curlist != same)					// is the current selection the same as the previous selection, if yes then this is to close the current list (ie double click)
    curlist.style.visibility='visible';
  else
   curlist = 0;
}

function makeselection(id,value,multiitem)
{
  if (multiitem)
  {
    if (document.getElementById(id).value == "Click to Select Suburbs, Default is All") document.getElementById(id).value="";

    if (document.getElementById(id).value.indexOf(value) == -1)		// check if postcode exists in value already. if -1 result is no
      document.getElementById(id).value += " "+value;
    else
      alert ("The selected suburbs postcode ( "+value+" ) is already selected. Some suburbs have the same postcode.");
  }
  else
    document.getElementById(id).value = value;
  if (curlist)						// selection has been made so close list.
    closecurrent();
}

function closecurrent()
{
  if (curlist)						// double check that curlist is valid, if yes then close it
    curlist.style.visibility='hidden';
  curlist = 0;
}

// -- END --
