function initToggleContacts() {
  /* Create a container in which we can calculate the height of #outerContact
     without showing it */
  var hc = $(document.createElement("div"));
  hc.setStyle("height", "0");
  hc.setStyle("overflow", "hidden");
  var oc = $("outerContact");  
  oc.parentNode.insertBefore(hc, oc);
  
  // Temporarily move #outerContact into container
  oc.parentNode.removeChild(oc);
  hc.appendChild(oc);
  
  // Calculate #outerContact height
  oc.setStyle("display", "block");
  var ocHeight = oc.getStyle("height").toInt();
  oc.setStyle("height", 0);
  
  // Return DOM to original state
  hc.removeChild(oc);
  hc.parentNode.insertBefore(oc, hc);
  hc.parentNode.removeChild(hc);

  // Set initial states on other elements of the expand/collapse widget
  var footer = $('outerFooter');
  footer.className = 'footerClosed';

  var button = $('actionButton');
  button.href = '#';

  // Initialise toggle effect
  var fx = new Fx.Styles(oc, { duration: 400, wait: false });

  button.onclick = function() {
    if (oc.getStyle("height").toInt() == 0) {
      // expand
      fx.start({
        'height': ocHeight
      });
      footer.className = 'footerOpen';
    } else {
      // collapse
      fx.start({
        'height': 0
      });
      footer.className = 'footerClosed';
    }
    return false;
  };
}

function togglePanel(panelType, activate, id) {
  var option = document.getElementById('options');
  var textPane = document.getElementById('hideText');
  if (activate == 'yes') {
    drawFlashURL(id);
    minifeature.write("content");
  }
  if (panelType == 'enlargedPhoto' && activate == 'yes') {
    option.className = 'showPhotos';      
  } else if (panelType == 'enlargedMap') {
    option.className = 'showMaps';
    setTimeout("initialise()", 500);
  } else {
    option.className = 'showOverview';
  }

  textPane.className = option.className;
}

function closePanel() {
  var option = document.getElementById('options');
  var textPane = document.getElementById('hideText');
  option.className = 'showOverview';
  textPane.className = option.className;
  
  return false;
}

function newWindow(url, name, width, height) {
  if (ieToolHeight) {
    height += ieToolHeight;
  }
  photoWindow = window.open(url, name,"location=no,directories=no,menubar=no,status=no,toolbar=no,scrollbars=no,height=" +height+ ",width=" +width+ ",resizable=no");
  photoWindow.resizeTo(width,height);
  photoWindow.focus();
  return false;
}

function sortHover(skin,position,elm) {
  var el = document.getElementById(elm);
  if(position == 'up') {
    el.className = skin + ' currentUp';
  } else {
    el.className = skin + ' currentDown';
  }
}

function sortHoverOut(skin,elm,currentStatus) {
  var el = document.getElementById(elm);
  if (currentStatus == '') {
    el.className = skin;
  } else {
    el.className = skin + ' ' + currentStatus;
  }
}

function hideField (status, inputField) {
  var field = document.getElementById(inputField);
  
    if(status == 'yes') {
      field.style.display = "block";
    } else {
      field.style.display = "none";
    }

}

function hideMultiField(status, list1, list2) {
  var listItem1 = document.getElementById(list1);
  var listItem2 = document.getElementById(list2);
  
  if(status == 'yes') {
    listItem1.style.display = "block";
    listItem2.style.display = "none";
  } else {
    listItem1.style.display = "none";
    listItem2.style.display = "block";
  }
}
function showFloorPlan(aID, baseHref) {
  width = 600;
  height = 500;
  fpWin = window.open(baseHref+'display.jspx?flArticleID='+aID+'&showFP=true', 'floorPlan',"location=no,directories=no,menubar=no,status=no,toolbar=no,scrollbars=no,height=" +height+ ",width=" +width+ ",resizable=yes");
  fpWin.resizeTo(width,height);
  fpWin.focus();
  return false;
}

function submitSearch(frm) {
  //frm.street.value = frm.street.value.replace(/\d/g,''); //strip numbers
  frm.street.value = frm.street.value.replace(/^\s/,''); //strip leading spaces
  frm.submit();
  return false;
}

var map = null;
var geocoder = null;
  
/**
 * Init Google Map.
 */
function initialise() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(-42.882743, 147.330234), 16); // init at Hobart,Tasmania,Australia
        
    geocoder = new GClientGeocoder();

    addMarkers();
  }
}

/**
 * Put markers on Google Map using lookup of property address (callback for Geocode).
 * doCentre is deprecated.
 */
var centred = false;
function showAddress(propId, address, doCentre, doClick) {
  if (geocoder) {
    geocoder.getLatLng(
      address.fullAddress,
      function(point) {
        if (!point) {
          window.status = address.fullAddress + " not found";
        } else {
          var marker = new PdMarker(point, {title: address.title});
          map.addOverlay(marker);
          marker.setImage(BASE_HREF + 'images/pin_standalone.png');
                              
          map.setCenter(point);

          if (address.showStreetView) {
            document.getElementById("streetView").style.display = 'block';
            panoramaOptions = { latlng:point };
            myPano = new GStreetviewPanorama(document.getElementById("streetView"), panoramaOptions);
            GEvent.addListener(myPano, "error", handleError);
          }
        }
      }
    );
  }
}

function handleError(errorCode) {
  document.getElementById("streetView").style.display = 'none';
  return;
}

// property location object
function propertyLocation(title, url, showStreetView) {
  this.title = title;
  this.url = url;
  this.showStreetView = showStreetView;
  this.fullAddress = this.title + ", Tasmania, Australia";
}

var lastAnch = null;

/**
 * Update the Google Map view-type button status.
 */
function setMap(anch, type) {
  map.setMapType(type);
  anch.className = 'current';
  
  if (lastAnch == null) {
    lastAnch = document.getElementById('defaultMapType');
  }
  lastAnch.className = '';
  lastAnch = anch;
  
  return false;
}
