function ClusterMarker($map,$options){this._map=$map;this._mapMarkers=[];this._iconBounds=[];this._clusterMarkers=[];this._eventListeners=[];this.moveend_listener=undefined;this.zoomend_listener=undefined;this.maptypechanged_listener=undefined;if(typeof($options)==='undefined'){$options={};}
this.borderPadding=($options.borderPadding)?$options.borderPadding:256;this.clusteringEnabled=($options.clusteringEnabled===false)?false:true;if($options.clusterMarkerClick){this.clusterMarkerClick=$options.clusterMarkerClick;}
if($options.clusterMarkerIcon){this.clusterMarkerIcon=$options.clusterMarkerIcon;}else{this.clusterMarkerIcon=new GIcon();this.clusterMarkerIcon.image='http://maps.google.com/mapfiles/arrow.png';this.clusterMarkerIcon.iconSize=new GSize(39,34);this.clusterMarkerIcon.iconAnchor=new GPoint(9,31);this.clusterMarkerIcon.infoWindowAnchor=new GPoint(9,31);this.clusterMarkerIcon.shadowSize=new GSize(0,0);}
this.clusterMarkerTitle=($options.clusterMarkerTitle)?$options.clusterMarkerTitle:'Click to zoom in and see %count dealers';if($options.fitMapMaxZoom){this.fitMapMaxZoom=$options.fitMapMaxZoom;}
this.intersectPadding=($options.intersectPadding)?$options.intersectPadding:0;if($options.markers){this.addMarkers($options.markers);}
this.moveend_listener=GEvent.bind(this._map,'moveend',this,this._moveEnd);this.zoomend_listener=GEvent.bind(this._map,'zoomend',this,this._zoomEnd);this.maptypechanged_listener=GEvent.bind(this._map,'maptypechanged',this,this._mapTypeChanged);};ClusterMarker.prototype.clear_listeners=function(){GEvent.removeListener(this.moveend_listener);GEvent.removeListener(this.zoomend_listener);GEvent.removeListener(this.maptypechanged_listener);};ClusterMarker.prototype.addMarkers=function($markers){var i;if(!$markers[0]){var $numArray=[];for(i in $markers){$numArray.push($markers[i]);}
$markers=$numArray;}
for(i=$markers.length-1;i>=0;i--){$markers[i]._isVisible=false;$markers[i]._isActive=false;$markers[i]._makeVisible=false;}
this._mapMarkers=this._mapMarkers.concat($markers);};ClusterMarker.prototype._clusterMarker=function($clusterGroupIndexes){function $newClusterMarker($location,$icon,$title){return new GMarker($location,{icon:$icon,title:$title});}
var $clusterGroupBounds=new GLatLngBounds(),i,$clusterMarker,$clusteredMarkers=[],$marker,$this=this,$mapMarkers=this._mapMarkers;for(i=$clusterGroupIndexes.length-1;i>=0;i--){$marker=$mapMarkers[$clusterGroupIndexes[i]];$marker.index=$clusterGroupIndexes[i];$clusterGroupBounds.extend($marker.getLatLng());$clusteredMarkers.push($marker);}
this.clusterMarkerIcon.image=this.clusterMarkerIcon.image.replace('%count',$clusterGroupIndexes.length);$clusterMarker=$newClusterMarker($clusterGroupBounds.getCenter(),this.clusterMarkerIcon,this.clusterMarkerTitle.replace(/%count/gi,$clusterGroupIndexes.length));$clusterMarker.clusterGroupBounds=$clusterGroupBounds;this._eventListeners.push(GEvent.addListener($clusterMarker,'click',function(){$this.clusterMarkerClick({clusterMarker:$clusterMarker,clusteredMarkers:$clusteredMarkers});}));$clusterMarker._childIndexes=$clusterGroupIndexes;for(i=$clusterGroupIndexes.length-1;i>=0;i--){$mapMarkers[$clusterGroupIndexes[i]]._parentCluster=$clusterMarker;}
return $clusterMarker;};ClusterMarker.prototype.clusterMarkerClick=function($args){this._map.setCenter($args.clusterMarker.getLatLng(),this._map.getBoundsZoomLevel($args.clusterMarker.clusterGroupBounds));};ClusterMarker.prototype._filterActiveMapMarkers=function(){var $borderPadding=this.borderPadding,$mapZoomLevel=this._map.getZoom(),$mapProjection=this._map.getCurrentMapType().getProjection(),$mapPointSw,$activeAreaPointSw,$activeAreaLatLngSw,$mapPointNe,$activeAreaPointNe,$activeAreaLatLngNe,$activeAreaBounds=this._map.getBounds(),i,$marker,$uncachedIconBoundsIndexes=[],$oldState,$mapMarkers=this._mapMarkers,$iconBounds=this._iconBounds;if($borderPadding){$mapPointSw=$mapProjection.fromLatLngToPixel($activeAreaBounds.getSouthWest(),$mapZoomLevel);$activeAreaPointSw=new GPoint($mapPointSw.x-$borderPadding,$mapPointSw.y+$borderPadding);$activeAreaLatLngSw=$mapProjection.fromPixelToLatLng($activeAreaPointSw,$mapZoomLevel);$mapPointNe=$mapProjection.fromLatLngToPixel($activeAreaBounds.getNorthEast(),$mapZoomLevel);$activeAreaPointNe=new GPoint($mapPointNe.x+$borderPadding,$mapPointNe.y-$borderPadding);$activeAreaLatLngNe=$mapProjection.fromPixelToLatLng($activeAreaPointNe,$mapZoomLevel);$activeAreaBounds.extend($activeAreaLatLngSw);$activeAreaBounds.extend($activeAreaLatLngNe);}
this._activeMarkersChanged=false;if(typeof($iconBounds[$mapZoomLevel])==='undefined'){this._iconBounds[$mapZoomLevel]=[];this._activeMarkersChanged=true;for(i=$mapMarkers.length-1;i>=0;i--){$marker=$mapMarkers[i];$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;$marker._makeVisible=$marker._isActive;if($marker._isActive){$uncachedIconBoundsIndexes.push(i);}}}else{for(i=$mapMarkers.length-1;i>=0;i--){$marker=$mapMarkers[i];$oldState=$marker._isActive;$marker._isActive=$activeAreaBounds.containsLatLng($marker.getLatLng())?true:false;$marker._makeVisible=$marker._isActive;if(!this._activeMarkersChanged&&$oldState!==$marker._isActive){this._activeMarkersChanged=true;}
if($marker._isActive&&typeof($iconBounds[$mapZoomLevel][i])==='undefined'){$uncachedIconBoundsIndexes.push(i);}}}
return $uncachedIconBoundsIndexes;};ClusterMarker.prototype._filterIntersectingMapMarkers=function(){var $clusterGroup,i,j,$mapZoomLevel=this._map.getZoom(),$mapMarkers=this._mapMarkers,$iconBounds=this._iconBounds;for(i=$mapMarkers.length-1;i>0;i--)
{if($mapMarkers[i]._makeVisible){$clusterGroup=[];for(j=i-1;j>=0;j--){if($mapMarkers[j]._makeVisible&&$iconBounds[$mapZoomLevel][i].intersects($iconBounds[$mapZoomLevel][j])){$clusterGroup.push(j);}}
if($clusterGroup.length!==0){$clusterGroup.push(i);for(j=$clusterGroup.length-1;j>=0;j--){$mapMarkers[$clusterGroup[j]]._makeVisible=false;}
this._clusterMarkers.push(this._clusterMarker($clusterGroup));}}}};ClusterMarker.prototype.fitMapToMarkers=function(){var $mapMarkers=this._mapMarkers,$markersBounds=new GLatLngBounds(),i;for(i=$mapMarkers.length-1;i>=0;i--){$markersBounds.extend($mapMarkers[i].getLatLng());}
var $fitMapToMarkersZoom=this._map.getBoundsZoomLevel($markersBounds);if(this.fitMapMaxZoom&&$fitMapToMarkersZoom>this.fitMapMaxZoom){$fitMapToMarkersZoom=this.fitMapMaxZoom;}
this._map.setCenter($markersBounds.getCenter(),$fitMapToMarkersZoom);this.refresh();};ClusterMarker.prototype._mapTypeChanged=function(){this.refresh(true);};ClusterMarker.prototype._moveEnd=function(){if(!this._cancelMoveEnd){this.refresh();}else{this._cancelMoveEnd=false;}};ClusterMarker.prototype._preCacheIconBounds=function($indexes,$mapZoomLevel){var $mapProjection=this._map.getCurrentMapType().getProjection(),i,$marker,$iconSize,$iconAnchorPoint,$iconAnchorPointOffset,$iconBoundsPointSw,$iconBoundsPointNe,$iconBoundsLatLngSw,$iconBoundsLatLngNe,$intersectPadding=this.intersectPadding,$mapMarkers=this._mapMarkers;for(i=$indexes.length-1;i>=0;i--){$marker=$mapMarkers[$indexes[i]];$iconSize=$marker.getIcon().iconSize;$iconAnchorPoint=$mapProjection.fromLatLngToPixel($marker.getLatLng(),$mapZoomLevel);$iconAnchorPointOffset=$marker.getIcon().iconAnchor;$iconBoundsPointSw=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x-$intersectPadding,$iconAnchorPoint.y-$iconAnchorPointOffset.y+$iconSize.height+$intersectPadding);$iconBoundsPointNe=new GPoint($iconAnchorPoint.x-$iconAnchorPointOffset.x+$iconSize.width+$intersectPadding,$iconAnchorPoint.y-$iconAnchorPointOffset.y-$intersectPadding);$iconBoundsLatLngSw=$mapProjection.fromPixelToLatLng($iconBoundsPointSw,$mapZoomLevel);$iconBoundsLatLngNe=$mapProjection.fromPixelToLatLng($iconBoundsPointNe,$mapZoomLevel);this._iconBounds[$mapZoomLevel][$indexes[i]]=new GLatLngBounds($iconBoundsLatLngSw,$iconBoundsLatLngNe);}};ClusterMarker.prototype.refresh=function($forceFullRefresh){var i,$marker,$zoomLevel=this._map.getZoom(),$uncachedIconBoundsIndexes=this._filterActiveMapMarkers();if(this._activeMarkersChanged||$forceFullRefresh){this._removeClusterMarkers();if(this.clusteringEnabled&&$zoomLevel<this._map.getCurrentMapType().getMaximumResolution()){if($uncachedIconBoundsIndexes.length>0){this._preCacheIconBounds($uncachedIconBoundsIndexes,$zoomLevel);}
this._filterIntersectingMapMarkers();}
for(i=this._clusterMarkers.length-1;i>=0;i--){this._map.addOverlay(this._clusterMarkers[i]);}
for(i=this._mapMarkers.length-1;i>=0;i--){$marker=this._mapMarkers[i];if(!$marker._isVisible&&$marker._makeVisible){this._map.addOverlay($marker);$marker._isVisible=true;}
if($marker._isVisible&&!$marker._makeVisible){this._map.removeOverlay($marker);$marker._isVisible=false;}}}};ClusterMarker.prototype._removeClusterMarkers=function(){var i,j,$map=this._map,$eventListeners=this._eventListeners,$clusterMarkers=this._clusterMarkers,$childIndexes,$mapMarkers=this._mapMarkers;for(i=$clusterMarkers.length-1;i>=0;i--){$childIndexes=$clusterMarkers[i]._childIndexes;for(j=$childIndexes.length-1;j>=0;j--){delete $mapMarkers[$childIndexes[j]]._parentCluster;}
$map.removeOverlay($clusterMarkers[i]);}
for(i=$eventListeners.length-1;i>=0;i--){GEvent.removeListener($eventListeners[i]);}
this._clusterMarkers=[];this._eventListeners=[];};ClusterMarker.prototype.removeMarkers=function(){var i,$mapMarkers=this._mapMarkers,$map=this._map;for(i=$mapMarkers.length-1;i>=0;i--){if($mapMarkers[i]._isVisible){$map.removeOverlay($mapMarkers[i]);}
delete $mapMarkers[i]._isVisible;delete $mapMarkers[i]._isActive;delete $mapMarkers[i]._makeVisible;}
this._removeClusterMarkers();this._mapMarkers=[];this._iconBounds=[];};ClusterMarker.prototype.triggerClick=function($index){var $marker=this._mapMarkers[$index];if($marker._isVisible){GEvent.trigger($marker,'click');}
else if($marker._isActive){var $clusteredMarkersIndexes=$marker._parentCluster._childIndexes,$intersectDetected=true,$uncachedIconBoundsIndexes,i,$mapZoomLevel=this._map.getZoom(),$clusteredMarkerIndex,$iconBounds=this._iconBounds,$mapMaxZoomLevel=this._map.getCurrentMapType().getMaximumResolution();while($intersectDetected&&$mapZoomLevel<$mapMaxZoomLevel){$intersectDetected=false;$mapZoomLevel++;if(typeof($iconBounds[$mapZoomLevel])==='undefined'){$iconBounds[$mapZoomLevel]=[];this._preCacheIconBounds($clusteredMarkersIndexes,$mapZoomLevel);}else{$uncachedIconBoundsIndexes=[];for(i=$clusteredMarkersIndexes.length-1;i>=0;i--){if(typeof($iconBounds[$mapZoomLevel][$clusteredMarkersIndexes[i]])==='undefined'){$uncachedIconBoundsIndexes.push($clusteredMarkersIndexes[i]);}}
if($uncachedIconBoundsIndexes.length>=1){this._preCacheIconBounds($uncachedIconBoundsIndexes,$mapZoomLevel);}}
for(i=$clusteredMarkersIndexes.length-1;i>=0;i--){$clusteredMarkerIndex=$clusteredMarkersIndexes[i];if($clusteredMarkerIndex!==$index&&$iconBounds[$mapZoomLevel][$clusteredMarkerIndex].intersects($iconBounds[$mapZoomLevel][$index])){$intersectDetected=true;break;}}};this._map.setCenter($marker.getLatLng(),$mapZoomLevel);this.triggerClick($index);}else{this._map.setCenter($marker.getLatLng());this.triggerClick($index);}};ClusterMarker.prototype._zoomEnd=function(){this._cancelMoveEnd=true;this.refresh(true);};

/*
  //global storage - per element in array ->
  - unique_data_config
  - bounding_data_config
  - map
*/
GDATA = {}; 
GMARKERS = [];
  
/**
 * CENTRE THE LOADING MESSAGE
 **/
jQuery.fn.centerScreen=function(loaded){if(!jQuery(loaded).length)return;var obj=this;if(!loaded){obj.css('top',(jQuery(window).height()*0.3)-(this.height()*0.3));obj.css('left',jQuery(window).width()/2-this.width()/2);jQuery(window).resize(function(){obj.centerScreen(!loaded);});}else{obj.stop();obj.animate({top:jQuery(window).height()/2-this.height()/2,left:jQuery(window).width()/2-this.width()/2},200,'linear');}};

/**
 * Ajax loading functions for the maps
 */ 
jQuery(document).ajaxStart(function(ajaxevent){ jQuery('#ajaxBusy').show().centerScreen();});
jQuery(document).ajaxStop(function(){jQuery('#ajaxBusy').hide();});
jQuery(document).ajaxError(function(){jQuery('#ajaxBusy').hide();});

/*
  Original code to handle creation of map elements etc
*/
/* data object to fetch things */
function gdata(options){
  if(typeof(options) != "undefined") this.options = jQuery.extend({}, this.options, options);
  return this;
};
/*
 - unique_data
  - url               //url to get unique data from - ie individual element data for windows etc
  - type              //post or get
  - error             //error function to call
  - success           //success function to call
  - dataType          //returned data type 
*/
gdata.prototype.options = {};
/*
 //these are fed directly into the ajax call...
 - fetch      //bounding data queries
    - url               //url to get unique data from - ie individual element data for windows etc
    - type              //post or get
    - data              //data
    - error             //error function to call
    - success           //success function to call
    - timeout           //timeout
    - dataType          //returned data type
*/
gdata.prototype.fetch = function(config, obj){
  jQuery.ajax({
    url: config.url,
    type: config.type,
    data: config.data,
    timeout: 5000,
    dataType: config.dataType,
    success:function(response){
      config.success(response, obj);
    },
    error:function(XMLHttpRequest, textStatus, errorThrown){
      alert(textStatus + " > " +errorThrown);
      config.error();
    }
  });
};

gdata.prototype.unique_data = function(id, obj){
  var call = jQuery.extend({}, this.options, {data:"uqid="+id});
  this.fetch(call, obj);
};
gdata.prototype.bounding_data = function(new_bounding_box, old_bounding_box, obj){
  var nsw = new_bounding_box.getSouthWest(),
      nne = new_bounding_box.getNorthEast(),
      osw = old_bounding_box.getSouthWest(),
      one = old_bounding_box.getNorthEast(),
      data = "new[bl][lat]="+nsw.lat() +
             '&new[bl][lng]='+nsw.lng() +
             '&new[tr][lat]='+nne.lat() + 
             '&new[tr][lng]='+nne.lng() +
             "&old[bl][lat]="+osw.lat() +
             '&old[bl][lng]='+osw.lng() +
             '&old[tr][lat]='+one.lat() + 
             '&old[tr][lng]='+one.lng(),      
      call = jQuery.extend({}, this.options, {data:data, timeout:'1200'});
  this.fetch(call, obj);
};


/*map*/
function gmap(options){
  if(typeof(options) != "undefined") this.options = jQuery.extend({}, this.options, options);
  return this.create();
};
/*
  - lat             //start lat
  - lng             //start lng
  - zoom            //start zoom
  - map             //Gmap
  - container       //container
  - icon_config     //config data for icons
  - marker
*/
gmap.prototype.options = {};
gmap.prototype.bounding_box = new GLatLngBounds(new GLatLng(90,-180), new GLatLng(-90,180));
gmap.prototype.cluster_marker_obj = undefined;
gmap.prototype.create = function(){
  if(typeof(this.options.map) == "undefined"){
    this.options.map = new google.maps.Map2(document.getElementById(this.options.container));
    this.centre(new GLatLng(this.options.lat,this.options.lng), this.options.zoom);
    this.options.map.setUIToDefault();
		this.options.map.enableScrollWheelZoom();
    this.before_load();
		this.load();
  }
  return this;
};
gmap.prototype.load = function(){
  GMARKERS = [];
  var obj = this,
      config = jQuery.extend({}, this.options.bounding_data_config,{success:obj.markers, error:obj.failed}),      
      dataobj = new gdata(config),
      oldbounding_box = this.bounding_box,
      newbounding_box = this.bounding_box = this.options.map.getBounds();
  GEvent.clearInstanceListeners(this.options.map);
  dataobj.bounding_data(newbounding_box, oldbounding_box, this);
  return this;
};
gmap.prototype.markers = function(response, obj){
  if(response.length > 0){
    for(var i in response){
      
      var extra_config = {unique_id:response[i].uid},
          icon_config = jQuery.extend({}, obj.options.icon, extra_config),          
          icon = new gicon(icon_config),
          config = {icon:icon, 
                lat:response[i].lat, 
                lng:response[i].lng,
                title:response[i].title, 
                unique_id: response[i].uid
                },
          map_marker = new gmarker(config);
          map_marker.options.marker.title = response[i].title;
          map_marker.options.marker.uid = response[i].uid;
          map_marker.options.marker.sales = response[i].sales;
          map_marker.options.marker.service = response[i].service;
          map_marker.options.marker.parts = response[i].parts;
          map_marker.options.marker.used = response[i].used;
      GMARKERS.push(map_marker.options.marker);    
      if(obj.options.cluster_config.use == false){        
        var cmap = obj.options.map;
        cmap.removeOverlay(map_marker.options.marker);
        cmap.addOverlay(map_marker.options.marker);
      }
    }
  }
  if(obj.options.cluster_config.use){
    obj.cluster(GMARKERS);
  }
  obj.listeners();
  obj.after_load();
  return this;
}
gmap.prototype.clear = function(markers){
  for(var i in markers) this.options.map.removeOverlay(markers[i]);
  return this;
};
gmap.prototype.cluster = function(markers){
  var clusterMarkerIcon = new gicon(this.options.cluster_config.icon).options.icon;
  this.cluster_marker_obj = new ClusterMarker(this.options.map, { markers:markers, clusterMarkerIcon:clusterMarkerIcon} );
  this.options.map.clearOverlays();
  this.cluster_marker_obj.refresh();
};
gmap.prototype.position_save = function(){
  this.options.map.savePosition();
  return this;
};
gmap.prototype.position_load = function(){
  this.options.map.returnToSavedPosition();
  return this;
};
gmap.prototype.centre = function(latlng, zoom){
  this.options.map.setCenter(latlng, zoom);
  return this;
};
gmap.prototype.listeners = function(){
  var obj = this;
  var move_event = GEvent.addListener(this.options.map, 'moveend', function(){
    obj.moved();
    if(obj.options.async_data_load){
      obj.clear(GMARKERS);
      obj.load();    
    }
  });
  var zoom = GEvent.addListener(this.options.map, 'zoomend', function(){
    obj.zoomed();
  });
  
};
gmap.prototype.zoomed = function(){};
gmap.prototype.moved = function(){};
gmap.prototype.before_load = function(){};
gmap.prototype.after_load = function(){};
gmap.prototype.failed = function(){return this;};
/*window*/
/*
  what happens here
  - call open to open a window 
  - this triggers the ajax gdata fetch request ..
    - successful 
      - runs this.create
    - failed called 
      - runs this.failed
*/
function gwindow(options){
  if(typeof(options) != undefined) this.options = jQuery.extend({}, this.options, options);
  return this;
};
/*
 - unique_id      //the unique identifier for this marker
 - marker         //the marker thats been clicked
*/
gwindow.prototype.options = {};
gwindow.prototype.create = function(repsonse, obj){
  if(typeof(repsonse.tabs) == "undefined"){
     
  }else{
   var tabs = [];
   for(var tname in repsonse.tabs) tabs.push(new GInfoWindowTab(tname, repsonse.tabs[tname]));
   obj.options.marker.openInfoWindowTabsHtml(tabs, {maxWidth:450});
  }
  obj.listeners();
  return this;
};
gwindow.prototype.open = function(){
  var obj=this,
        config = jQuery.extend({}, GDATA.unique_data_config,{success:obj.create, error:obj.failed}), 
        dataobj = new gdata(config);
  dataobj.unique_data(this.options.unique_id, this);
  return this;
};

gwindow.prototype.listeners = function(){
  var obj = this;
  var window_open = GEvent.addListener(this.options.marker, "infowindowopen", 
     function(){
       obj.after_open(obj.options.marker);
       GDATA.gmap.position_save();
     }
   );
   GEvent.addListener(this.options.marker, "infowindowclose", 
     function(){   
       GEvent.removeListener(window_open);
       obj.after_close(obj.options.marker);
       GDATA.gmap.position_load();
     }
   );
  return this;
};
gwindow.prototype.after_open = function(marker){};
gwindow.prototype.after_close = function(marker){};
gwindow.prototype.failed = function(){return this;}

/*markers*/
function gmarker(options){
  if(typeof(options) != undefined) this.options = jQuery.extend({}, this.options, options);
  return this.create(this.options.icon);
};
/*
 - icon           //GIcon object
 - lat            //latitude
 - lng            //longitude
 - title          //title
 - unique_id      //the unique identifier for this marker
 - marker         // the marker
*/
gmarker.prototype.options = {}; 
gmarker.prototype.create = function(icon){
  if(typeof(this.options.marker) == "undefined"){
    if(typeof(icon) == "undefined") var icon = new gicon();
    this.options.marker = new GMarker(new GLatLng(this.options.lat, this.options.lng), {icon:icon.options.icon, title:this.options.title});
    this.trigger();
  }
  return this;
};
gmarker.prototype.trigger = function(){
  var obj = this;
  GEvent.addListener(this.options.marker, "click", function(){obj.clicked();});
  return this;
};
gmarker.prototype.clicked = function(){
  this.before_clicked(this.options.marker);
  var info_window = new gwindow({marker: this.options.marker, unique_id: this.options.unique_id}).open();
};
gmarker.prototype.before_clicked = function(marker){};

/*icons*/
function gicon(options){
  if(typeof(options) != undefined) this.options = jQuery.extend({}, this.options, options);
  return this.create();
};
/*
 - image          //url
 - dimensions:    //{} object
    - x             //int
    - y             //int
    - shadow      //{} object
        - x         //int
        - y         //int
 - unique_id      //indentifier for this icon
 - icon           //the icon
*/
gicon.prototype.options = {};

gicon.prototype.create = function(){
  if(typeof(this.options.icon) == "undefined"){  
    this.options.icon = new GIcon(G_DEFAULT_ICON);
    if(typeof(this.options.image) != "undefined") this.options.icon.image = this.options.image;
    if(typeof(this.options.dimensions) != "undefined"){
      this.options.icon.iconSize = new GSize(this.options.dimensions.x, this.options.dimensions.y);
      this.options.icon.imageMap = [0,0, this.options.dimensions.x,0, this.options.dimensions.x,this.options.dimensions.y, 0,this.options.dimensions.y];
      if(typeof(this.options.shadow) != "undefined") this.options.icon.shadowSize=new GSize(this.options.shadow.x, this.options.shadow.y);
      else this.options.icon.shadowSize=new GSize(0,0);
    }
  }    
  return this;
};


/*** JQUERY PLUGIN THAT USES ALL THAT STUFF ABOVE ***/
(function($) {

	$.fn.smart_gmap = function(options){
		return this.each(function(){		
			//check dependancies && not in use atm
			if(this._kick_ass) return;
			this._kick_ass = 'obb';
			$.smart_gmap.config = jQuery.extend({}, $.smart_gmap.config, options);
			//setup params
		  GDATA = {unique_data_config:$.smart_gmap.config.unique_data_config, 
		              bounding_data_config:$.smart_gmap.config.bounding_data_config,		                          
		              gmap: new gmap($.smart_gmap.config)
	              };
		});	
	};
	
	$.smart_gmap = {
		compatible:function(){
		  
		  if(typeof(GBrowserIsCompatible) == "function" && typeof(jQuery) != "undefined") return GBrowserIsCompatible();
		  else return false;
		},  
	/*
    - lat                   //start lat
    - lng                   //start lng
    - zoom                  //start zoom
    - map                   //Gmap
    - container             //container
    - icon_config           //config data for icons - dont set by default, so it just uses defaults
      - image          //url
      - dimensions:    //{} object
         - x             //int
         - y             //int
         - shadow      //{} object
            - x         //int
            - y         //int
    - unique_data_config
      - url
      - type
      - dataType
    - bounding_data_config  
      - url
      - type
      - dataType
    - cluster_config      
      - icon
        - image          //url
        - dimensions:    //{} object
           - x             //int
           - y             //int
           - shadow      //{} object
              - x         //int
              - y         //int
      - use
        
  */
	  config:{	  
	    lat:54.67383096593114, 
  	  lng:-3.515625, 
  	  zoom:5,
  	  async_data_load:false,
  	  container: "google_map",
  	  icon:{
  	    image:"/images/map-markers/marker.png",
  	    dimensions:{
	        x:27,
	        y:31
	      }
  	  }, 	  
  	  unique_data_config:{
  	    url:"/maps/unique.json",  //url to get unique data from - ie individual element data for windows etc
        type:"post",               //post or get
        dataType:'json'           //returned data type
  	    },
  	  bounding_data_config:{
  	    url:"/maps/bounding.json",  //url to get unique data from - ie individual element data for windows etc
        type:"post",               //post or get
        dataType:'json'           //returned data type
  	    },
  	  cluster_config:{
  	    use:true,
  	    icon:{
  	      image: "/images/map-markers/group.png",
  	      dimensions:{
  	        x:70,
  	        y:38
  	      }
  	    }
  	  }
  	}
	};
	
})(jQuery);


