function getImage(page,subPage) {
	switch(page) {
		case "index":
			document.write('<img src="img/appleGirl.jpg" alt="Girl Eating Apple" />');
			break;
		case "land":
			document.write('<img src="img/foreheads.jpg" alt="Smiling Father and Daughter" />');
			break;
		case "resales":
			document.write('<img src="img/appleGirl.jpg" alt="Happy Girl" />');
			break;
		case "resaleDetail":
			document.write('<img src="../img/appleGirl.jpg" alt="Happy Girl" />');
			break;
		case "vacantDetail":
			document.write('<img src="../img/appleGirl.jpg" alt="Happy Girl" />');
			break;
		case "bank-owned":
			document.write('<img src="img/appleGirl.jpg" alt="Happy Girl" />');
			break;
		case "bank-ownedDetail":
			document.write('<img src="../img/appleGirl.jpg" alt="Happy Girl" />');
			break;
		case "lot":
			document.write('<img src="../img/appleGirl.jpg" alt="Happy Girl" />');
			break;
		case "about":
			document.write('<img src="img/family2.jpg" alt="Happy Family" />');
			break;
		case "contact":
			document.write('<img src="img/dadnSon1.jpg" alt="Father and Son" />');
			break;
	}
	
}

function initialize() {
				
		if (GBrowserIsCompatible()) {
     	getIconsAndCoordinates();
  
		} else {
			document.getElementById('map_canvas').innerHTML = "<p>Sorry.  Your browser does not support Google Maps.</p>";	
		}
}

function createMap() {
	var map = new GMap2(document.getElementById("map_canvas"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(48.020000,-122.200000), 10);

	
	for(var x=0;x<icons.length;x++) {
		var marker = new GIcon();
		marker.image = "img/icons/"+icons[x].image;
		//marker.iconSize = new GSize(150, 70);
		if(x==2||x==0) {
			marker.iconAnchor = new GPoint(-37, 70);
		} else {
			marker.iconAnchor = new GPoint(37, 70);
		}
		marker.infoWindowAnchor = new GPoint(5, 1);
				
		eval('var this'+x+'Marker = new GMarker(new GLatLng(icons[x].lat,icons[x].lng), { icon:marker, title:x });');
		GEvent.addListener(eval('this'+x+'Marker'), "click", function() {
     		window.location=icons[this.getTitle()].url;
    });
      
    GEvent.addListener(eval('this'+x+'Marker'), "mouseover", function() {
   		getCommunityStats(icons[this.getTitle()].id);
   		document.getElementById('community_stats').style.display = "block";
    }); 
    GEvent.addListener(eval('this'+x+'Marker'), "mouseout", function() {
   		document.getElementById('community_stats').style.display = "none";
    }); 
        
		map.addOverlay(eval('this'+x+'Marker'));
	} 
}

function getCommunityStats(id) {
	var client = new HttpClient();
	
	client.callback = function(result) {
		document.getElementById('community_stats').innerHTML = result;
	}
	
	client.makeRequest('getCommunityStats.php?id='+id,null);
}

var icons = new Array();

function getIconsAndCoordinates() {
	 var client = new HttpClient();
	
	client.callback = function(result) {
		result = eval(result);
		for(i=0;i<result.length;i++) {
			icons.push(new Icon(result[i][0],result[i][1],result[i][2],result[i][3],result[i][4]))
		}
		createMap();
	}

	client.makeRequest('getMapCoordinates.php',null); 
}

function Icon(image,lat,lng,url,id) {
	this.image = image;
	this.lat = lat;
	this.lng = lng;
	this.url = url;
	this.id = id;
}

function toggle(what) {
	if(document.getElementById(what).style.display==""||
		document.getElementById(what).style.display=="none") {
		document.getElementById(what).style.display = "block";
		document.getElementById('viewTag').innerHTML = "Close Floor Plans and Other Images";
	} else {
		document.getElementById(what).style.display = "none";
		document.getElementById('viewTag').innerHTML = "View Floor Plans and Other Images";
	}
}

function printLot(which,id) {
	var wopts  = 'width=960,height=500,resizable=1,alwaysRaised=1,scrollbars=1';
	if(which=='lot') {
		var child = window.open('printLot.php?id='+id,'child',wopts);
	} else {
		var child = window.open('printHome.php?id='+id,'child',wopts);
	}	
}

function printNCHome(which,id) {
	var wopts  = 'width=960,height=500,resizable=1,alwaysRaised=1,scrollbars=1';
	var child = window.open('../printNCHome.php?id='+id,'child',wopts);	
}

var overrideId=null;
function overrideIframe() {
	if(overrideId!=null) {
		clearInterval(overrideId);
	}
	var contactForm = document.getElementById('contactForm');
	
	if(contactForm.innerHTML=='Loading...') {
	//	overrideId = setInterval('overrideIframe()',15);
	} else {
		alert(contactForm.innerHTML);
	}	
}