var cache = [];
var $j = jQuery.noConflict();

$j(document).ready(function($)
{
var addressone = "13831 Northwest Freeway, Suite 575 Houston, Texas 77040";
var addressonedisplay = "<p><strong>Corporate Headquarters</strong><br />13831 Northwest Freeway<br />Suite 575<br />Houston, Texas 77040<br /><a href=\"http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=13831+Northwest+Freeway,+Houston,+Texas+77040&amp;aq=&amp;sll=29.856724,-95.514793&amp;sspn=0.210512,0.308647&amp;ie=UTF8&amp;hq=&amp;hnear=13831+Northwest+Fwy,+Houston,+Harris,+Texas+77040&amp;ll=29.852993,-95.514911&amp;spn=0.006811,0.009645&amp;z=17&amp;iwloc=r9\" target=\"_blank\">Get Directions</a></p>";
var addresstwo = "14505 Torrey Chase Boulevard Houston, TX 77014";
var addresstwodisplay = "<p><strong>Tax Division</strong><br />14505 Torrey Chase Boulevard<br />Suite 101<br />Houston, TX 77014<br /><a href=\"http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=14505+Torrey+Chase+Boulevard+Houston,+TX+77014&amp;aq=&amp;sll=29.985801,-95.492939&amp;sspn=0.006802,0.009645&amp;ie=UTF8&amp;hq=&amp;hnear=14505+Torrey+Chase+Blvd,+Houston,+Harris,+Texas+77014&amp;ll=29.985801,-95.492939&amp;spn=0.006802,0.009645&amp;z=17&amp;iwloc=A\" target=\"_blank\">Get Directions</a></p>";
$('#map').gMap({maptype: G_NORMAL_MAP,markers: [{address:''+ addressone + '', html:'' + addressonedisplay + '',icon: { image: "images/locationone.png",
                                      iconsize: [26, 46],
                                      iconanchor: [12,46],
                                      infowindowanchor: [12, 0] }}, {address:''+ addresstwo + '', html:'' + addresstwodisplay + '',icon: { image: "images/locationtwo.png",
                                      iconsize: [26, 46],
                                      iconanchor: [12,46],
                                      infowindowanchor: [12, 0] }}],zoom:10});
	enterFunction = function(){
                    $(this).html('ACTIVE');
                }
                leaveFunction = function(){
                    $(this).html('inactive');
                }
                $('.accordion2').hSlides({
                    totalWidth: 928, 
                    totalHeight: 350, 
                    minPanelWidth: 162, 
                    maxPanelWidth: 600,
                    activeClass: 'active',
                    eventHandler: 'hover',
                    speed: 500
                });
	try
	{
		$j("#nav li").hover(
			function()
			{
				var childUl = $j(this).find("ul");
				childUl[0].show(1);
			},
			function()
			{
				var childUl = $j(this).find("ul");
				childUl[0].hide(1);
			}
		);
	}
	catch(e){}
	
	//Build list items and points
	var directoryItem;
	var i=0;
	var highlightCircle = null;
	var currentMarker = null;
	
	// Check to see if this browser can run the Google API
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.open("GET",'lease.xml',false);
	xmlhttp.send();
	xmlDoc = xmlhttp.responseXML;
});

//DirectoryItem object
function DirectoryItem()
{
	var prevmark = null;
	this.name = '';
	this.address = '';
	this.phone = '';
	this.html = '';
	this.street = '';
	this.city = '';
	this.state = '';
	this.zip = ''
	this.buildMarker = function(map,bounds,geocoder,num)
	{
		var infowindowLevel = 0;
		var name = this.name;
		var phone = this.phone;
		var address = this.address;
		var street = this.street;
		var city = this.city;
		var state = this.state;
		var zip = this.zip;
		geocoder.geocode(
		{'address': this.address},
		function(results, status)
		{
			if (status != google.maps.GeocoderStatus.OK) 
			{
				//alert('Sorry, we were unable to geocode that address.');
			} 
			else 
			{
				point = results[0].geometry.location;
				var image = 'images/map marker/map-marker-' + num + '.png';
				var marker = new google.maps.Marker({
					position: point, 
					map: map,
					icon: image
				});
				bounds.extend(point);
				map.setCenter(bounds.getCenter());
				map.fitBounds(bounds);
				var contentString = 
					'<div id="mapcontent">' +
					name + '<br />' +
					street + '<br />' +
					city + ', ' +
					state + ' ' +
					zip + '<br />' +
					'P: ' + phone.substr(0,3) + '-' + phone.substr(3,3) + '-' + phone.substr(6,4) +
					'<br>Directions: <b>To here</b><br /><form action="directions.php" method="post">' + '<input type="text" SIZE=10 name="saddr" id="saddr" value="" /><br>' + '<INPUT value="Get Directions" TYPE="SUBMIT">' + '<input type="hidden" name="daddr" value="' + address + '"/>' +
					'</div>';
				var infowindow = new google.maps.InfoWindow({
					content: contentString
				});
				google.maps.event.addListener(marker, 'click', function() {
					infowindow.setZIndex(++infowindowLevel);
					infowindow.open(map,marker);
				});
			}
		});
	};
}
