/**************************************************************************************************/
/***
/***	GRATES AND GRILLS JAVASCRIPT DOCUMENT
/***	-----------------------------------------------------------------------
/***	Written by Matthew Praetzel. Copyright (c) 2007 Matthew Praetzel.
/***	-----------------------------------------------------------------------
/***	All Rights Reserved. Any use of these functions & scripts without written consent is prohibited.
/***
/**************************************************************************************************/

/*-----------------------
	INITIALIZE
-----------------------*/
ternVENTS.addEvent(window,init,"load",false);
var g,m,map,address = " 105 S. Main Street Dublin, PA 18917",timer;
/*-----------------------
	ROCK
-----------------------*/
function init() {
	if(document.getElementById("map")) {
		gmap();
		ternVENTS.addEvent("gdr",dir,"click",false);
		ternVENTS.addEvent("cd",closeDir,"click",false);
	}
}
function openWindow(u,n,w,h,x,y) {
	var f = 'width='+w+',height='+h+',scrollbars=yes,resizable=yes';
	if(wn = window.open(u,n,f)) {
		wn.moveTo((screen.availWidth-w)/2,0);
		return wn;
	}
	else {
		alert('There has been an error opening this window. Is your browser blocking pop-ups?');
		return false;
	}
}
function gmap() {
	if(GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		var geocoder = new GClientGeocoder();
		geocoder.getLatLng(address,function(point) {
			if (!point) {
				alert(address + " not found");
			}
			else {
				map.setCenter(point,13);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml("<b>Grates and Grills</b><br />" + address);
			}
		});
	}
}
function dir() {
	var d = ternStyle("dcn").getDimensions();
	if(d[1] > 0) {
		ternStyle("dcn").grow("medium","y",0).removeClass("dcnv");
	}
	else {
		ternStyle("dcn").addClass("dcnv").grow("medium","y",180);
	}
}
function directions() {
	var add1 = document.getElementById("add1").value;
	var add2 = document.getElementById("add2").value;
	var c = document.getElementById("city").value;
	var s = document.getElementById("state").value;
	var z = document.getElementById("zip").value;
	var dp = document.getElementById("directions");
	var dir = new GDirections(map,dp);
	GEvent.addListener(dir,"error",function () { 
		clearInterval(timer);
		ternStyle(document.body).hideElapsor();
		alert("Your address does not seem to be valid.");
	});
	ternStyle("dcn").grow("medium","y",0).removeClass("dcnv");
	ternStyle(document.body).elapsor("http://www.rockvilleroseinn.com/","#000000",65,function () {
		timer = setInterval(setDir,300);
		dir.load(add1+" "+add2+", "+c+", "+s+", "+z+" to "+address);
	});
}
function setDir() {
	var dp = document.getElementById("directions");
	if(dp.childNodes && dp.childNodes.length > 0) {
		clearInterval(timer);
		var h = document.getElementById("directions").getElementsByTagName("table");
		h = h[h.length-2].getElementsByTagName("td")[1];
		h.innerHTML = h.innerHTML.replace("Hurricane","Rockville").replace("84737","84763");
		//
		ternStyle("gdcn").setStyle("visibility","visible");
		ternStyle("map").setStyle("z-index",60);
		ternStyle(document.body).hideElapsor(false);
	}
}
function closeDir() {
	ternStyle("gdcn").setStyle("visibility","hidden");
	ternStyle("directions").removeChildren();
	ternStyle(document.body).hideElapsor();
	ternStyle("map").setStyle("z-index",0);
}