function getElementsByIdLike( el, like )
{
	var collection = new Array();
	var els = el == null ? document.getElementsByTagName("*") : e.getElementsByTagName("*");
	
	for ( var i = 0; i < els.length;i++ ) {
		if ( "" != els[i].id && like == els[i].id.substr( 0, like.length ) )
		{
			collection.push( els[i] );
		}
	}
	
	return collection;
}

var geocoder;
var map = new Object();

function Maps( id )
{
	this.id = id;
	this.el = document.getElementById( this.id );
	this.location = this.el.firstChild.nodeValue;
	
	this.initMap();
	this.getLocation();
}

Maps.prototype.getLocation = function()
{
	var location = this.location.split( "|" );
	if ( location.length != 2 ) {
		var _self = this;
		this.geocode.getLatLng( location[0], function( point ) {
			if ( point ) {
				_self.MyMap.setCenter( point, 15 );
				_self.AddIcon();
			} } );
		return false;
	}
	
	_self.MyMap.setCenter( new GPoint( location[0], location[1] ), 15 );
	_self.AddIcon();
};

Maps.prototype.AddIcon = function()
{
	var marker = new GMarker( this.MyMap.getCenter() );	
	this.MyMap.addOverlay( marker );
};

Maps.prototype.initMap = function()
{
	this.MyMap = new GMap2( this.el );
	this.MyMap.setCenter(new GLatLng(-33.867139, 151.207114), 6);
	this.MyMap.addControl( new GMapTypeControl() );
	this.MyMap.addControl( new GScaleControl() );
	if ( null != hasClass( this.el, "small" ) ) {
		this.MyMap.addControl( new GSmallMapControl() );
	} else {
		this.MyMap.addControl( new GLargeMapControl() );
	}
	this.geocode = new GClientGeocoder();
	
	return;
};

function google_load()
{
	var maps = getElementsByIdLike( null, "map" );
	if ( maps.length == 0 ) {
		return;
	}
	
	if ( !GBrowserIsCompatible() ) {
		return;
	}
	
	for ( var i = 0; i < maps.length; i++ ) {
		new Maps( maps[i].id );
	}
	
	return;
}

addLoadEvent( google_load );

