function depInfo(data){
	var html = '';

	//display all kinds of information about locations, but only if its there
	$.each(data,function(){
		html += "<div class='depTable'><span class='depName'>";
		html += this.DLNAME+"</span><div class='depInfo'>";
		if(this.DLADD1 !== ''){
			html += this.DLADD1;
		}
		if(this.DLADD2 !== ''){
				html += "<br/>"+ this.DLADD2;
			
		}		
		if(this.DLCITY !== '')
		{
			html += "<br/>"+this.DLCITY;

			if(this.DLSTAT !== '')
			{
				html += " "+ this.DLSTAT;
			}
			if(this.DLZIPC !== '')
			{
				html += " "+ this.DLZIPC;
			}
			html += "<br/>";
		}
		
		html += "<br/>";
		
		if(this.DLPHOL !== '')
		{
			html +=	'Local Phone: '+this.DLPHOL+'<br/>';
		}
		if(this.DLPHOT !== '')
		{
			html +=	'Toll Phone: '+this.DLPHOT+'<br/>';
		}		
		if(this.DLFAXX !== '')
		{
			html +=	'Fax: '+this.DLFAXX+'<br/>';
		}
		if(this.DLFQUC !== '')
		{
			html +=	'UNICOM: '+this.DLFQUC+'<br/>';
		}
		if(this.DLFQAI !== '')
		{
			html +=	'ARINC: '+this.DLFQAI+'<br/>';
		}
		
		html += "</div></div>";	
		
	});
	
	$('#infoBox').html(html);
//open box
	$('#infoBox').animate({
		marginTop: '0px'
	}, 500);
	
//close box button
	$('#closeInfo').click(function(){
		$('#infoBox').animate({
			marginTop: '-300px'
		}, 500);
	});
}

function createMarker(map,pos){
	//position marker
	var currPoint = new GLatLng(pos.GCLATI,pos.GCLONG);
	var icon = new GIcon();
	icon.image = '/map_files/img/push-pin.png';
	icon.iconSize = new GSize(25, 32);
	icon.iconAnchor = new GPoint(0, 25);
	icon.infoWindowAnchor = new GPoint(10,10);
	//var currMarker = new GMarker(currPoint,{icon:icon});	//removed to set default Google marker
	var currMarker = new GMarker(currPoint);
	map.addOverlay(currMarker);

	//create popup html
	var currHtml = '<div id="popUpBox"><div id="boxTitle">'+ pos.GCLABL +'</div>';
	currHtml += '<div id="locType">'+pos.GCTYPE+'<br/><br/></div>';
	currHtml += '<div id="locAddress">';
	
	if(pos.GCPHOL !== '')
	{
		currHtml += pos.GCPHOL + " (Local Line)";
	}
	if(pos.GCPHOT)
	{
		currHtml += "<br/>"+pos.GCPHOT + " (Toll-Free Phone)";
	}
	if(pos.GCFAXX)
	{
		currHtml += "<br/>"+pos.GCFAXX + " (Fax)";
	}
	if(pos.GCADD1)
	{
		var add1 = (pos.GCADD1 != "")?"<br/><br/>"+pos.GCADD1:""
		var citstate = (pos.GCCITY != "")?"<br/>"+pos.GCCITY+', '+pos.GCSTAT+' '+pos.GCZIPC+"<br/><br/>":""
	}
	else {
		var citstate = "";
		var add1 = "";
	}
	if(pos.GCADD2)
	{
		var add2 = (pos.GCADD2 != "")?"<br/>"+pos.GCADD2:""
	}
	else {
		var add2 = "";
	}
	if(pos.GCADD3)
	{
		var add3 = (pos.GCADD3 != "")?"<br/>"+pos.GCADD3:""
	}
	else { 
		var add3 = "";
	}
	 currHtml += add1+ add2 + add3+ citstate +'</div><div><a target="blank" class="directions" href="http://maps.google.com/maps?q='+pos.GCLATI+',+'+pos.GCLONG+'+('+pos.GCLABL+')" >Get Directions...</a></div>';
	if(pos.extras > 0){
		currHtml += "<div><a href='' class='moreInfo' id='"+pos.GCAIRP+"'>Departments</a></div>";
	}
	
	currHtml += "</div>";
	//open info box and get rid of old bindings
	GEvent.addListener(currMarker,"click",function() {
		this.openInfoWindowHtml(currHtml);
	});

	//add event for slide out menu
	GEvent.addListener(currMarker, 'infowindowopen', function(){

		$('#'+pos.GCAIRP).click(function(){
			
		$.ajax({
			data: 'GCAIRP='+pos.GCAIDN+'&rand='+Math.random(),
			dataType: 'json',
			url: "/map_files/jax/duncanMapJax.php",
			beforesend: function(){
				$('#infoBox').html("loading...");
			},			
			success: function(data){
				depInfo(data);
			}
		});			
			
			
			return false;
		});
		
	});
	
	//close when a different window is selected
	GEvent.addListener(currMarker, 'infowindowclose', function(){
		
		$('#infoBox').animate({
			marginTop: '-300px'
		}, 500).html('');

		return false;

	});

}

var map;
function mapInit(){
//	if (GBrowserIsCompatible()) {	
		//initial settings;
		map = new GMap2(document.getElementById("dMap"));			
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.checkResize();
		GSize(700,400);

		map.setCenter(new GLatLng(38,-98),4);
		
		//pull out the last part of the url
		var page = location.href;
		page = page.split("/");
		page = page[page.length -1];
		
		//initiaze teh listings
		$.ajax({
			dataType: 'json',
			data: 'rand='+Math.random()+'&page='+page,
			url: "/map_files/jax/duncanMapJax.php",
			success: function(data){
				for(var i = 0; i < data.length; i++){
					createMarker(map, data[i]);
				}
			}
			
		});

//	}else{
//		$("#dMap").html("Your browser is not compatible with google maps");
//	}	
	
}
