function addLoadEvent ( func ) {
	var oldonload = window.onload;
	if ( typeof window.onload != 'function' ) {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

var home = {
	preload : function ( ) {
		var col = document.getElementById("col_right");
		var links = document.getElementsByTagName("a");
		for ( i=0; i<links.length; i++ ) {
			if ( links[i].className == "def" ) {
				links[i].onclick = new Function ( "window.open(this.href,'definition','width=400,height=300,scrollbars=yes');return false;" );
			}
		}
	}
}

var map_detail = {
	preload : function ( ) {
		var col = document.getElementById("col_right");
		var links = document.getElementsByTagName("a");
		for ( i=0; i<links.length; i++ ) {
			if ( links[i].className == "def" ) {
				links[i].onclick = new Function ( "window.open(this.href,'definition','width=400,height=300,scrollbars=yes');return false;" );
			}
		}
	}
}

var property = {
	curPic : String("item_0"),
	maxHeight : Number(0),
	preload : function () {
		var photosList = document.getElementById("photos");
		var photos = photosList.getElementsByTagName("a");
		var items = photosList.getElementsByTagName("li");
		for ( i=0; i<photos.length; i++ ) {
			photos[i].onclick = new Function ( "property.l ( 'larger.php?img=' + this.href ); return false;" );
			property.maxHeight = ((property.maxHeight<Element.getHeight(items[i]))?(Element.getHeight(items[i])):(property.maxHeight));
		}
		photosList.style.height = property.maxHeight + "px";
		var thumbsList = document.getElementById("thumbs");
		var thumbs = thumbsList.getElementsByTagName("a");
		for ( i=0; i<thumbs.length; i++ ) {
			thumbs[i].onclick = new Function ( "if (property.curPic != 'item_" + i + "') {new Effect.Fade(property.curPic,{duration: 0.5, queue: 'parallel'});new Effect.Appear('item_" + i + "',{duration: 0.5, queue: 'parallel'});property.curPic = 'item_" + i + "';}return false;" );
			thumbs[i].onmouseover = new Function( "self.status = this.title;return true;" );
		}
		var contact = document.getElementById("contact");
		var agent = contact.getElementsByTagName("a");
		agent[0].onclick = new Function ( "window.open(this.href,'agent','width=450,height=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no,titlebar=no,status=no');return false;" );
	},
	l : function ( iid ) {
		// iid is the full URL, including the image URl in a http://currentsite/larger.php?img=IMGURL
		window.open( iid, "larger", "width=150,height=150,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no,titlebar=no,status=no" );
		return false;
	}
}

var properties = {
	preload : function () {
		if ( document.getElementById("props") ) {
			var props = document.getElementById("props");
			var list = props.getElementsByTagName("li");
			for ( i=0; i<list.length; i++ ) {
				if ( Element.getHeight(list[i]) < 135 ) {
					list[i].style.height = "135px";
				}
			}
		}
	}
}

var about = {
	preload : function () {
		if ( document.getElementById("images") ) {
			var imgs = document.getElementById("images");
			var photos = imgs.getElementsByTagName("a");
			for ( i=0; i<photos.length; i++ ) {
				photos[i].onclick = new Function ( "about.l ( 'larger.php?img=' + this.href ); return false;" );
			}
		}
		var agents = document.getElementById("agents");
		var list = agents.getElementsByTagName("li");
		for ( i=0; i<list.length; i++ ) {
			var div = list[i].getElementsByTagName("div");
			if ( Element.getHeight(div[1]) < Element.getHeight(div[0]) ) {
				list[i].style.height = (Element.getHeight(div[0])) + "px";
			} else {
				list[i].style.height = (Element.getHeight(div[0])) + "px";
			}
			var links = list[i].getElementsByTagName("a");
			links[0].onclick = links[1].onclick = new Function ( "window.open(this.href,'agent','width=450,height=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no,titlebar=no,status=no');return false;" );
		}
		var col = document.getElementById("col_right");
		var links = document.getElementsByTagName("a");
		for ( i=0; i<links.length; i++ ) {
			if ( links[i].className == "def" ) {
				links[i].onclick = new Function ( "window.open(this.href,'definition','width=400,height=300,scrollbars=yes');return false;" );
			}
		}
	},
	l : function ( iid ) {
		// iid is the full URL, including the image URl in a http://currentsite/larger.php?img=IMGURL
		window.open( iid, "larger", "width=150,height=150,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no,titlebar=no,status=no" );
		return false;
	},
	profilePreload : function () {
		var photo = document.getElementById("headshot");
			photo.onclick = new Function ( "about.l ( 'larger.php?img=' + this.href ); return false;" );
	}
}

var article = {
	preload : function () {
		var col = document.getElementById("col_right");
		var imgas = col.getElementsByTagName("a");
		for ( i=0; i<imgas.length; i++ ) {
			var imgs = imgas[i].getElementsByTagName("img");
			if ( imgs.length ) {
				imgas[i].onclick = new Function ( "about.l ( 'larger.php?img=' + this.href ); return false;" );
			} else {
				imgas[i].onclick = new Function ( "window.open(this.href,'definition','width=400,height=300,scrollbars=yes');return false;" );
			}
		}
	}
}

var map = {
	preload : function () {
		el = document.getElementById("areas");
		lis = el.getElementsByTagName("a");
		for ( i=0; i < lis.length; i++ ) {
			lis[i].onclick = new Function( "map.si(" + (i+1) + ");return false;" );
			lis[i].onmouseover = new Function( "map.sw(" + (i+1) + ");" );
			lis[i].onmouseout = new Function( "map.sw(0);" );
		}
		aimg = document.getElementById("sc-map");
//		Effect.Appear(aimg,{duration: 2.0, queue: 'parallel'});
		aimg = document.getElementById("sc-map");
		aimg.onclick = new Function("map.fastMap();");
		var mapFade = setTimeout("map.slowMap()",5000);
	},
	sw : function ( offs ) {
		var el = document.getElementById("areas");
		var ainfo = document.getElementById("area_info");
		el.style.backgroundPosition = "0 -" + (offs*271) + "px";
	},
	si : function ( lid ) {
		var ainfo = document.getElementById("area_info");
		var lis = ainfo.getElementsByTagName("li");
		for ( i=0; i<lis.length; i++ ) {
			if ( lis[i].parentNode.id == "area_info" ) {
				lis[i].style.display = "none";
			}
		}
		Effect.Appear("info_"+lid,{duration: 0.5, queue: 'parallel'});
//		var el = document.getElementById("info_" + lid);
//		el.style.display = "block";
	},
	slowMap : function () {
		aimg = document.getElementById("sc-map");
		Effect.Fade(aimg,{duration: 2.0, queue: 'parallel'});
	},
	fastMap : function () {
		aimg = document.getElementById("sc-map");
		Effect.Fade(aimg,{duration: 0.5, queue: 'parallel'});
	}
}

var pl = {
	checkBody : function ( ) {
		bd = document.body;
		if ( bd.id == "home" ) {
			home.preload();
		}
		if ( bd.id == "map_detail" ) {
			map_detail.preload();
		}
		if ( bd.id == "property" ) {
			property.preload();
		}
		if ( bd.id == "properties" ) {
			properties.preload();
		}
		if ( bd.id == "about" ) {
			about.preload();
		}
		if ( bd.id == "agent_profile" ) {
			about.profilePreload();
		}
		if ( bd.id == "article" ) {
			article.preload();
		}
		if ( bd.id == "map" ) {
			map.preload();
		}
	}
}

if ( document.getElementById && document.getElementsByTagName ) { 
	addLoadEvent(pl.checkBody);
}
