var iconimage; 
var iconshadow;
var iconshape;
var firstTabHTML;
var secondTabHTML;
var latitude;
var longitude;
var mapcenter;
var map;

function initContactMap()
{
	initContactMap(false);
}

function initContactMap(isSingapore)
{
	setContactConditions(isSingapore);
	mapCenter = new google.maps.LatLng(latitude, longitude);
	
	var mapOptions = {
		// -> http://code.google.com/apis/maps/documentation/v3/reference.html#Map%20options
		zoom: 		10,
		center: 	mapCenter, 
		mapTypeId: 	google.maps.MapTypeId.HYBRID,
		mapTypeControl: false
	};
		
	map = new google.maps.Map(document.getElementById("map"), mapOptions);
	
	setIconValues();
	//teken de markers
	showContantMapMarkers();
}

function setIconValues()
{
	iconimage = new google.maps.MarkerImage('img/markers/image.png',
												//size  
												new google.maps.Size(31,18),	
												//origin
												new google.maps.Point(0, 0),	
												//anchor
												new google.maps.Point(0,18));	
	iconshadow = new google.maps.MarkerImage('img/markers/shadow.png',
												 new google.maps.Size(40,18),
												 new google.maps.Point(0, 0),
												 new google.maps.Point(0,18));
	iconshape = {
		coord: [27,0,29,1,29,2,30,3,30,4,30,5,30,6,30,7,21,8,21,9,20,10,20,11,20,12,20,13,20,14,20,15,19,16,18,17,12,17,11,16,10,15,10,14,10,13,10,12,10,11,10,10,10,9,0,8,0,7,0,6,0,5,0,4,0,3,1,2,2,1,3,0],
		type: 'poly'};
}

function setContactConditions(isSingapore)
{
	var address;
	firstTabHTML = '';
	firstTabHTML += '<p>';
	if(!isSingapore)
	{
		latitude = 52.015542;
		longitude = 4.69511;
		firstTabHTML += '<strong>Delta Marine Consultants</strong>';
		firstTabHTML += '<br />';
		firstTabHTML += 'H.J. Nederhorststraat 1';
		firstTabHTML += '<br />';
		firstTabHTML += '2801 SC Gouda';
		firstTabHTML += '<br />';
		firstTabHTML += 'The Netherlands';
		firstTabHTML += '</p>';
		firstTabHTML += '</div>';
		address = "H.J.Nederhorststraat 1, 2801 SC Gouda, Netherlands (Delta Marine Consultants BV)";
	}
	else
	{
		latitude = 1.301869;
		longitude = 103.864006;
		firstTabHTML += '<strong>Delta Marine Consultants Singapore Pte. Ltd.</strong>';
		firstTabHTML += '<br />';
		firstTabHTML += '6002 Beach Road';
		firstTabHTML += '<br />';
		firstTabHTML += '#20-03 Golden Mile Tower';
		firstTabHTML += '<br />';
		firstTabHTML += 'Singapore 199589';
		address = "Golden Mile Tower #20-03, 6001 Beach Road (S)199589, 19, Singapore (Delta Marine Consultants Singapore Pte.Ltd.)";
	}
	firstTabHTML += '</p>';
	
	secondTabHTML  = '';
	secondTabHTML += '<form action="http://maps.google.nl/maps" method="get" target="_blank">';
	secondTabHTML += '<label>Your address:</label>';
	secondTabHTML += '<input type="text" name="saddr" id="saddr" value="" style="width:150px;font-size:0.7em;"  /><br/>';
	secondTabHTML += '<input type="submit" value="get driving directions" style="width:155px;font-size:0.7em;"  />';
	secondTabHTML += '<input type="hidden" name="daddr" id="daddr" value="' + address + '" />';
	secondTabHTML += '<input type="hidden" name="hl" value="nl" />';
	secondTabHTML += '<input type="hidden" name="ie" value="UTF8"';
	secondTabHTML += '</form>';
}

function infoWindowShowRoute()
{
	var infowindowtabselect = document.getElementById("infowindowtabselect");
	var infowindowcontent = document.getElementById("infowindowcontent");
	infowindowtabselect.innerHTML = '<a href="#" onclick="infoWindowShowInfo();return false;">info</a> | route';
	infowindowcontent.innerHTML = secondTabHTML;
}

function infoWindowShowInfo()
{
	var infowindowtabselect = document.getElementById("infowindowtabselect");
	var infowindowcontent = document.getElementById("infowindowcontent");
	infowindowtabselect.innerHTML = 'info | <a href="#" onclick="infoWindowShowRoute();return false;">route</a>';
	infowindowcontent.innerHTML = firstTabHTML;
}

function showContantMapMarkers()
{
	var infoWindowHeight = 80;
	var marker = new google.maps.Marker({
		position: mapCenter,
        map: map,
        shadow: iconshadow,
        icon: iconimage,
        shape: iconshape,
        title: "contact",
        zIndex: 10
	});
	var infoWindowHTML  = '<div>';
		infoWindowHTML += '<p id="infowindowtabselect">info | <a href="#" onclick="infoWindowShowRoute();return false;">route</a></p>';
		infoWindowHTML += '</div><div id="infowindowcontent" style="overflow:hidden">';
		infoWindowHTML += firstTabHTML;
		infoWindowHTML += '</div>';

	var infowindow = new google.maps.InfoWindow({
	    content: infoWindowHTML,
	    maxWidth: 110
	});
	
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	});
	
	google.maps.event.trigger(marker, 'click');
}