// ZIPCODE

function updateZip(zip) {

	document.getElementById('zipWait').style.display = "inline";

	$.ajax({
		type: "POST",
		url: "/ajax/update_zip.html",
		data: "zip=" + zip,
		success: function(msg){
			if (msg) {
				location = "http://www.teamap.com/states/state_"+msg+"_Distance.html";
			}
		}
	});
	
}


////////////////////////////////////////////////////////////////////////////////////
// GOOGLE MAPS

function pickState(stateAbbr) {
	if (stateAbbr) {
		if (stateAbbr.match( "UK_" )){
			location = "/United_Kingdom/"+stateAbbr+"_Reviews.html";
		} else if (stateAbbr.match( "CA_" )){
			location = "/Canada/"+stateAbbr+"_Reviews.html";
		} else {
			location = "/states/state_"+stateAbbr+"_Reviews.html";
		}
	}
}

var map = null;

function StartMap() {
	if (GBrowserIsCompatible()) {
		document.getElementById("mapWrapper").innerHTML="<div id='map' style='width: 707px; height: 400px; border: solid #a6a38b 1px;'></div>";
		document.getElementById("iconWrapper").innerHTML="<A HREF='#' ONCLICK='HideMap();return false'>hide map</A><BR>";
		initMap();
	}
}

function expand() {
	newHeight = newHeight + 10;
	if (newHeight > 400) {newHeight = 400;stop();}
	document.getElementById("map").style.height = newHeight;
	
	newWidth = newWidth + 18;
	if (newWidth > 707) {newWidth = 707;}
	document.getElementById("map").style.width = newWidth;
}

function stop() {
	clearInterval(googlemap);
	document.getElementById("map").style.height = 400;
	document.getElementById("map").style.width = 707;
}

function HideMap() {
	newHeight = 400;
	newWidth = 707;
	googlemap=setInterval('contract()',10);
	setTimeout('erase()',2500)
}

function contract() {
	newHeight = newHeight - 10;
	if (newHeight < 50) {newHeight = 50;erase();}
	document.getElementById("map").style.height = newHeight;
	
	newWidth = newWidth - 18;
	if (newWidth < 100) {newWidth = 100}
	document.getElementById("map").style.width = newWidth;
}

function erase() {
	clearInterval(googlemap);
	document.getElementById("mapWrapper").innerHTML="<IMG WIDTH='1' HEIGHT='1' BORDER='0' SRC='/images/blank.gif'><BR>";
	document.getElementById("iconWrapper").innerHTML="<A HREF='#' ONCLICK='StartMap();return false'><IMG WIDTH='100' HEIGHT='50' BORDER='0' SRC='/images2/google_map_icon_small.gif'><BR>show map<BR></A>";
}

function createTabbedMarker(point,htmls,labels) {
	  
	var marker = new GMarker(point);
	
	GEvent.addListener(marker, "click", function() {
		// adjust the width so that the info window is large enough for this many tabs
		if (htmls.length > 1) {
			htmls[0] = '<div style="min-width:'+htmls.length*88+'px;">' + htmls[0] + '</div>';
		}
		var tabs = [];
		for (var i=0; i<htmls.length; i++) {
			tabs.push(
				new GInfoWindowTab(
					labels[i],
					'<div class="width:300px;overflow:auto;text-align:left;">' + htmls[i] + '</div>'
					)
				);
		}
		marker.openInfoWindowTabsHtml(tabs);
		});
		
	return marker;

}



////////////////////////////////////////////////////////////////////////////////////
// ROLLOVER

function photosPreview(id, exteriorTest, interiorTest) {
	if (exteriorTest) {
		document.getElementById("previewExterior_"+id).src = "/images/exterior/exterior_"+id+".jpg";
	}
	if (interiorTest) {
		document.getElementById("previewInterior_"+id).src = "/images/interior/interior_"+id+".jpg";
	}
}
