
var xmlDoc;

function getDealerInfo( xmlId, node, fallback )
{
	var dealer = xmlDoc.getElementsByTagName("marker")[xmlId];

	var curNodes = dealer.getElementsByTagName( node );

	if ( 1 > curNodes.length || 1 > curNodes[0].childNodes.length )
	{
		return fallback;
	}

	return curNodes[0].childNodes[0].nodeValue;
}

function loadLocInfo( xmlId )
{

	$("#locationInfo").css( 'display', 'block' );

	var location = "";
	var address1 = "";
	var address2 = "";
	var postcode = "";
	var city = "";
	var county = "";
	var phoneNumber = "";
	var seperator = "";
	var curNodes;

	var dealer = xmlDoc.getElementsByTagName("marker")[xmlId];

	location = getDealerInfo( xmlId, "location", location );
	address1 = getDealerInfo( xmlId, "address1", address1 );
	address1 = getDealerInfo( xmlId, "dealerAddress1", address1 );
	postcode = getDealerInfo( xmlId, "postcode", postcode );
	postcode = getDealerInfo( xmlId, "dealerPostcode", postcode );
	city = getDealerInfo( xmlId, "city", city );
	city = getDealerInfo( xmlId, "dealerCity", city );
	county = getDealerInfo( xmlId, "county", county );
	county = getDealerInfo( xmlId, "dealerCounty", county );
	phoneNumber = getDealerInfo( xmlId, "phoneNumber", phoneNumber );

	if ( 0 < county.length )
	{
		seperator = ", ";
	}

	document.getElementById("dealerName").innerHTML = location;
	document.getElementById("address1").innerHTML = address1;
	document.getElementById("address2").innerHTML = postcode + " " + city + seperator + county;
	document.getElementById("phoneNumber").innerHTML = phoneNumber;
}


$(document).ready( function()
	{

		if (window.XMLHttpRequest)
		{
			xhttp=new XMLHttpRequest()
		}
		else
		{
			xhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
		xhttp.open("GET","/a/xml/tourDates/"+loc+".xml",false);
		xhttp.send("");
		xmlDoc = xhttp.responseXML;

		function getFlash()
		{
			var targetFlash = document.getElementById("flashMap");
			return targetFlash;

		}

		function centerMap(i)
		{
			var targetFlash = getFlash();
			var flashInfo = targetFlash.centerMap(i);
		}

		function showFlag(i)
		{
			var targetFlash = getFlash();
			var flashInfo = targetFlash.showFlag(i);
		}

		$('#locations li .showMap').click( function()
		{

			var xmlId = $(this).parent().parent().attr('id').replace( "hd_", "" );
			centerMap(  xmlId );
			return false;
		});

		$('#locations li').hover( function()
		{

			var xmlId = $(this).attr('id').replace( "hd_", "" );

			showFlag( xmlId );

			loadLocInfo( xmlId );

		},
		function ()
		{
			return false;
		});

	});

