// CN MAPS

if( typeof( _cn ) == 'undefined' ) {
	alert( 'cnBase.inc.js not included before cnGoogleMaps.inc.js' );
}


function cnCMapMarkerInstanceCreate( pMap, pLatLng, pMarkerOptions ) {
	this.mMarker = new GMarker( pLatLng, pMarkerOptions );
	pMap.addOverlay( this.mMarker )
}


function cnCMapMarkerInstanceEventClickSet( pFunction ) {
	var markerData = {
		marker: this.mMarker
	}

	this.mEventClickFn = function() {
		pFunction( markerData );
	};

	GEvent.addListener( this.mMarker, 'click', this.mEventClickFn );
}



function cnCMapMarkerInstanceGMarkerGrab() {
	return this.mMarker;
}


function cnCMapMarkerInstance() {
	this.mMarker = null;
	this.mEventClickFn = null;
}


cnCMapMarkerInstance.prototype.create = cnCMapMarkerInstanceCreate;
cnCMapMarkerInstance.prototype.eventClickSet = cnCMapMarkerInstanceEventClickSet;
cnCMapMarkerInstance.prototype.gmarkerGrab = cnCMapMarkerInstanceGMarkerGrab;


// ---


function cnCMapMarkersAdd( pId, pImageUrl, pIconSizeX, pIconSizeY, pAnchorX, pAnchorY ) {
	var icon = new GIcon( G_DEFAULT_ICON );
	icon.image = pImageUrl;
	icon.iconSize = new GSize( pIconSizeX, pIconSizeY );
	icon.iconAnchor = new GPoint( pAnchorX, pAnchorY );

	this.mMarkers[ pId ] = icon;
}


function cnCMapMarkersGet( pId ) {
	return this.mMarkers[ pId ];
}


function cnCMapMarkers() {
	this.mMarkers = new Array();
}

cnCMapMarkers.prototype.add = cnCMapMarkersAdd;
cnCMapMarkers.prototype.get = cnCMapMarkersGet;


// --


function cnCMapInstanceCreate( pLatLng, pZoom ) {
	if( !GBrowserIsCompatible() ) {
		alert( 'Your browser is not compatible with Google Maps' );
		return false;
	}

	this.mMap = new GMap2( document.getElementById( this.mDomId ) );
	this.mMap.setCenter( pLatLng, pZoom );
	this.mMap.setUIToDefault();

// this.mMap.addControl( new GSmallMapControl() );
// this.mMap.addControl( new GMapTypeControl() );

	return true;
}


function cnCMapInstanceCentreSet( pLatLng ) {
	this.mMap.setCenter( pLatLng );
}


function cnCMapInstanceCentrePan( pLatLng ) {
	this.mMap.panTo( pLatLng );
}


function cnCMapInstanceZoom( pZoom ) {
	this.mMap.setZoom( pZoom );
}


function cnCMapInstanceMarkerAdd( pMarker, pLatLng ) {
	var markerOptions = {
		icon: pMarker,
	};
	
	var markerInstance = new cnCMapMarkerInstance();
	markerInstance.create( this.mMap, pLatLng, markerOptions );
//	var marker = markerInstance.mMarker;

//	markerInstance.clickAdd(
//		function() {
//			this.mMarker.openInfoWindowHtml( 'yuo', { maxWidth: 300 })
//		}
//	);

//	GEvent.addListener(marker, 'click', function() {
//		this.openInfoWindowHtml( pHtml, { maxWidth: 300 });
//	});
	
	return markerInstance;
}


function cnCMapInstance( pDomId ) {
	this.mDomId = pDomId;
	this.mMap = null;
}

cnCMapInstance.prototype.create = cnCMapInstanceCreate;
cnCMapInstance.prototype.centreSet = cnCMapInstanceCentreSet;
cnCMapInstance.prototype.centrePan = cnCMapInstanceCentrePan;
cnCMapInstance.prototype.zoom = cnCMapInstanceZoom;
cnCMapInstance.prototype.markerAdd = cnCMapInstanceMarkerAdd;

