// JavaScript Document

function findObj(n, d) {
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
       x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById)
       x=d.getElementById(n);
  return x;
}

function showLayers() {   //only supports two arguments, first is active layer, and 2nd (if present) is which layer is te,[on.
  var i,args=showLayers.arguments;
  var tempLayer;
  if(args.length>0) {
    tempLayer = args[0];
  } else {
  	tempLayer = activeLayer;
  }
  for (i=0; i<=6; i++) {
  	if(tempLayer == i) {
		showLayer('subSection_' + i);
	} else {
		hideLayer('subSection_' + i);
	}
  }
/*  
  if(currentSub != i) {
	  clearTimeout(timer);
	  timer = setTimeout("showLayers(" + currentNav + ")",5000);
  } else {
	  clearTimeout(timer);
  }*/
}

function showLayer() {
  var i,v,obj,args=showLayer.arguments;
  if ((obj=findObj(args[0]))!=null){
    if (obj.style) {
         obj=obj.style;
		 display = obj.display;
         v='visible';
    }
    obj.visibility=v;
	obj.display = "block";
  }
  lastLayer = obj;
}

function hideLayer() {
  var i,v,obj,args=hideLayer.arguments;
  if ((obj=findObj(args[0]))!=null){
    if (obj.style) {
         obj=obj.style;
		 display = obj.display;
         v='hidden';
    }
    obj.visibility=v;
	obj.display = "none";
  }
  lastLayer = obj;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
/*	
	if(currentSub != i) {
		clearTimeout(timer);
//		timer = setTimeout("showLayers(" + currentNav + ")",5000);
	} else {
		clearTimeout(timer);
	}
	*/
}

var preloadFlag = false;
function preloadImages() {
	var i,args=preloadImages.arguments;
//	clearTimeout(timer);
	// define the main nav rollovers
	var nav_commercial_over,nav_investments_over,nav_communities_over,nav_hotel_over,nav_residential_over,nav_company_over,nav_news_over,nav_req_info_over,nav_contact_over;
	// now defined the sub nav rollovers
	var sub_profile_over,sub_pres_message_over,sub_focus_over,sub_team_over;
	var sub_business_centre_over,sub_floorplans_over,sub_leasing_info_over,sub_comm_contact_over;
		
	var navTitles = "commercial,investments,communities,hotel,residential,company,news,req_info,contact".split(",");
	var subNavTitles = "business_centre,floorplans,leasing_info,comm_contact,profile,pres_message,focus,team".split(",");
//	alert(document.currentSub);
	if (document.images) {
		for(i=0;i < navTitles.length;i++) {
			varPointer = eval('nav_' + navTitles[i] + '_over');
			varPointer = newImage("/images/nav_" + navTitles[i] + "-over.gif");
			var aLink = document.getElementById("a_" + navTitles[i]);
//			alert(document.getElementById("a_" + navTitles[i]));
			aLink.reftitle = navTitles[i];
			aLink.i = i;
			if(aLink) {
				if(i != args[0]) {
					aLink.onmouseover=function() {
						changeImages(('nav_' + this.reftitle), ('/images/nav_' + this.reftitle + '-over.gif'));
	//					showLayers(this.i);
						return(true);
					}
					aLink.onmouseout=function() {
						changeImages(('nav_' + this.reftitle), ('/images/nav_' + this.reftitle + '.gif'));
						return(true);
					}
				} else {
	//				showLayers(this.i,true);
					aLink.onmouseover=function() {
	//					showLayers(this.i);
						return(true);
					}
				}
			}
		}
		
		for(i=0;i <  subNavTitles.length;i++) {
			varPointer = eval('sub_' + subNavTitles[i] + '_over');
			varPointer = newImage("/images/sub_" + subNavTitles[i] + "-over.gif");
			var aLink = document.getElementById("a_" + subNavTitles[i]);
			if(aLink) {
				aLink.reftitle = subNavTitles[i];
				aLink.i = i;
				
				if(i != args[1]) {
					aLink.onmouseover=function() {
						changeImages(('sub_' + this.reftitle), ('/images/sub_' + this.reftitle + '-over.gif'));
						return(true);
					}
					aLink.onmouseout=function() {
						changeImages(('sub_' + this.reftitle), ('/images/sub_' + this.reftitle + '.gif'));
						return(true);
					}
				}
			}
		}
		preloadFlag = true;
	}

	// turn on the nav if defined
	if(args.length > 0) {
		changeImages(('nav_' + navTitles[args[0]]), ('/images/nav_' + navTitles[args[0]] + '-over.gif'));
//		showLayers(args[0]);
		// now turn on the subnav if defined
		if(args.length > 1) {
			changeImages(('sub_' + subNavTitles[args[1]]), ('/images/sub_' + subNavTitles[args[1]] + '-over.gif'));
		}
	}
}


