var OVERVIEWMAPCONTROL = null;

//Marker factory: creates markers
function AMarkerFactory(){
	;
}

AMarkerFactory.createCountryMarker = function(name, point, flag){
    //prepare flag image uri
    var flagURI = "http://www.anwb.nl/images/vlaggen/s_c_vl-" + arguments[2] + ".gif";
	
    //create markerOptions
    var markerOptions = new Object();
	markerOptions.title = arguments[0] + " (Klik om te zoomen)";
	markerOptions.icon = AIconFactory.getIcon("country", flagURI);

	//create marker
	var newMarker = new GMarker(arguments[1], markerOptions);

	//add custom properties
	newMarker.label = arguments[0];	

        //add behaviour
        GEvent.addListener(newMarker, "click",  function(){
	        map.setCenter(point, COUNTRY_MAXZOOM + 1);
	        // show overview map if lower right corner of map
	        if (OVERVIEWMAPCONTROL == null) {
	        	OVERVIEWMAPCONTROL = new GOverviewMapControl();
	        	map.addControl(OVERVIEWMAPCONTROL);
	        } else {
				OVERVIEWMAPCONTROL.show();
			}
        });

        GEvent.addListener(newMarker, "mouseover", function(){
                ASidebar.highlightItem(newMarker.id);
        });

        GEvent.addListener(newMarker, "mouseout", function(){
                ASidebar.restoreHighlightedItem(newMarker.id);
        });

        return newMarker;
}

AMarkerFactory.createItemMarker = function(name, point, uniqueId, icon, type){
	//create markerOptions
	var markerOptions = new Object();
	markerOptions.title = arguments[0] + " (Klik voor info)";
	
	if (icon){
		markerOptions.icon = icon;
	} else {
		alert('Unspecified icon');
		//markerOptions.icon = AIconFactory.getIcon("camping");
	}

    //create marker
    var newMarker = new GMarker(arguments[1], markerOptions);
    var localUniqueId = arguments[2];

    //add custom properties
    newMarker.label = arguments[0];
    newMarker.uniqueId = arguments[2];
	tabs = new Array();
	if (type == MARKER_TYPE_CAMPING_BOOKABLE || type == MARKER_TYPE_CAMPING_NONBOOKABLE) {
		if (type == MARKER_TYPE_CAMPING_BOOKABLE) {
			htmlBoeken = '<iframe src="/verblijven/campings/toonOmschrijvingBoekenForGoogleMap.jsf?type=CMP&adamnummer=' + localUniqueId + '" width="300" height="270" scrolling="auto" frameborder="0"></iframe>';
			tabs.push(new GInfoWindowTab("Boeken", htmlBoeken));
		}
		htmlOmschrijving = '<iframe src="/verblijven/campings/toonOmschrijvingAlgemeenForGoogleMap.jsf?type=CMP&adamnummer=' + localUniqueId + '" width="300" height="270" scrolling="auto" frameborder="0"></iframe>';
		tabs.push(new GInfoWindowTab("Omschrijving", htmlOmschrijving));
	} else if (type == MARKER_TYPE_BEDANDBREAKFAST_RESERVABLE || type == MARKER_TYPE_BEDANDBREAKFAST_NONRESERVABLE) {
//		if (type == MARKER_TYPE_BEDANDBREAKFAST_RESERVABLE) {
//			htmlReserveren = '<iframe src="/verblijven/bedandbreakfasts/toonOmschrijvingReserverenForGoogleMap.jsf?type=BB&adamnummer=' + localUniqueId + '" width="300" height="270" scrolling="auto" frameborder="0"></iframe>';
//			tabs.push(new GInfoWindowTab("Reserveren", htmlReserveren));
//		}
		htmlOmschrijving = '<iframe src="/verblijven/bedandbreakfasts/toonOmschrijvingAlgemeenForGoogleMap.jsf?type=BB&adamnummer=' + localUniqueId + '" width="300" height="270" scrolling="auto" frameborder="0"></iframe>';
		tabs.push(new GInfoWindowTab("Omschrijving", htmlOmschrijving));
	}
	newMarker.tabs = tabs;
	
	//add custom functions
	newMarker.showInfo = function() {
		newMarker.openInfoWindowTabsHtml(newMarker.tabs);
	}

	//add behaviour
	GEvent.addListener(newMarker, "click",  function(){
		newMarker.showInfo();
	});

	GEvent.addListener(newMarker, "mouseover", function(){
		ASidebar.highlightItem(newMarker.id);
	});

	GEvent.addListener(newMarker, "mouseout", function(){
		ASidebar.restoreHighlightedItem(newMarker.id);
	});

	return newMarker;	
}

//Function that formats the content for an info window and adds zoom functionality
function formatContentForInfoWindow(content){
	//html for zoom functionality
	var zoomFunctionality = '<br><a href="javascript:map.setZoom(map.getZoom()+2);">Zoom in</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:map.setZoom(map.getZoom()-2);">Zoom uit</a>'

	//combine content with extra functionality 
	var output = content + zoomFunctionality;

	//return the formatted content for the info window
	return output;
}
	


