/********************************
 * site-specific settings       *
 ********************************/

var showRolloverMenuEffect = Effect.BlindDown;
var showRolloverMenuEffectOptions = { duration: 0.2 };
var hideRolloverDelay = 150;
var hideRolloverMenuEffect = Effect.BlindUp;
var hideRolloverMenuEffectOptions = { duration: 0.2 };

/********************************
 * site-specific functions      *
 ********************************/
/* homepage side dropdowns */
var DDSPEED = 10;
var DDTIMER = 15;
var OFFSET = -2;
var ZINT = 100;

function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    c.style.display = 'block';
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.left = (h.offsetWidth + OFFSET) + 'px';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    ZINT = ZINT + 1;
    c.style.zIndex = ZINT;
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = Math.round((c.maxh - currh) / DDSPEED);
  }else{
    dist = Math.round(currh / DDSPEED);
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if(currh > (c.maxh - 2) && d == 1){
    clearInterval(c.timer);
  }else if(dist < 1 && d != 1){
    clearInterval(c.timer);
    c.style.display = 'none';
  }
}

/* 2nd level pages dropdown */
var PDDSPEED = 10;
var PDDTIMER = 15;

// main function to handle the mouse events //
function pddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){pddSlide(c,1)},PDDTIMER);
  }else{
    h.timer = setTimeout(function(){pddCollapse(c)},50);
  }
}

// collapse the menu //
function pddCollapse(c){
  c.timer = setInterval(function(){pddSlide(c,-1)},PDDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){pddSlide(c,1)},PDDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function pddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / PDDSPEED));
  }else{
    dist = (Math.round(currh / PDDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}

// homepage banner rotation
function nexthomephoto() {
	var no = window.currentno;
	var maxno = window.maxno;
	if(no < maxno) {
		var objid = 'homephoto' + no;
		clearInterval(skipinterval);
		skipinterval = window.setInterval('nexthomephoto()',4000);
		window.skipinterval = skipinterval;
		Effect.Appear(objid);
		window.currentno = no+1;
	} else {
// start again
		clearInterval(skipinterval);
		var clearobjid = '';
		for (i=1;i < maxno;i++) {
			var clearobjid = 'homephoto' + i;
			if(i < maxno-1) {
				$(clearobjid).hide();
			} else {
				Effect.Fade(clearobjid);
			}
		}
		window.currentno = 1;
		playhomephotos();
	}
}
function playhomephotos() {
var skipinterval = window.setInterval('nexthomephoto()',4000);
window.skipinterval = skipinterval;
}

// hovering stuff for menu
function hover(i,l) {
	var img = document.getElementById(i);
	var link = document.getElementById(l);
	img.src="/images/home/arrowDown.gif";
	link.style.color="#ffffff";
}
function unhover(i,l) {
	var img = document.getElementById(i);
	var link = document.getElementById(l);
	img.src="/images/home/arrow.gif";
	link.style.color="#000099";
}
function phover(i,l) {
	var img = document.getElementById(i);
	var link = document.getElementById(l);
	img.src="/images/pages/arrowDown.gif";
	link.style.color="#ffffff";
}
function punhover(i,l) {
	var img = document.getElementById(i);
	var link = document.getElementById(l);
	img.src="/images/pages/arrow.gif";
	link.style.color="#000099";
}


// google maps
var map = null;
var geocoder = null;
var address = null;

   // function initialize() {
   //   if (GBrowserIsCompatible()) {
   //     map = new GMap2(document.getElementById("map_canvas"));
		//map.setUIToDefault();
//        geocoder = new GClientGeocoder();
//		address = document.getElementById("property_address");
//		showAddress(address.innerHTML);
//      }
//    }

    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
            }
          }
        );
      }
    }

