function JMapCount( div_id, opts )
{
	this.div_id			= div_id;
	this.opts			= opts;

	this.obj_gmap		= null;
	this.bool_init		= false;
	this.bool_searching = false;
	this.bool_cancel	= false;

	this.divCount		= null;
	this.search_bound	= null;
}

JMapCount.prototype.init = function( gFrame, obj_gmap, url )
{
	this.bool_init	 	= true;
	this.gFrame			= gFrame;
	this.obj_gmap		= obj_gmap;
	this.url			= url;

	var thisObj = this;
	gFrame.GEvent.addListener(obj_gmap, 'moveend', 
		function(){
			thisObj.search();
		}
	);
}

JMapCount.prototype.cancel = function()
{
	this.bool_cancel = true;
}

JMapCount.prototype.search = function()
{
	if( this.bool_init == false ){ return; }
	if( this.bool_searching == false ){

		this.bool_searching = true;
		this.divCount		= xGetElementById( this.div_id );

		xInnerHtml( this.divCount, "<img src='/img_jams/loading/small.gif'>" );

		this.search_bound = this.obj_gmap.getBounds();

		var LL_NE = this.obj_gmap.getBounds().getNorthEast();
		var LL_SW = this.obj_gmap.getBounds().getSouthWest();

		var url = this.url;

		url += "/ne_lat-" + LL_NE.lat();
		url += "/ne_lng-" + LL_NE.lng();
		url += "/sw_lat-" + LL_SW.lat();
		url += "/sw_lng-" + LL_SW.lng();

		if( this.opts ){
			url += this.opts;
		}

		var xml = new JKL.ParseXML( url );
		var thisObj = this;
		xml.async( function(data){ thisObj.results(data); } );
		xml.parse();

		// getAcc
		var acc = new JKL.ParseXML.DOM( getAccUrl() );
		acc.async( this.acc );
		acc.parse();
	}
}
JMapCount.prototype.acc = function()
{
}

JMapCount.prototype.results = function(data)
{
	try{
		if( data ){
			if( this.bool_cancel == false ){
				this.bool_searching = false;

				if( this.search_bound.equals( this.obj_gmap.getBounds() ) ){
					xInnerHtml( this.divCount, data['items']['count'] );
				}else{
					this.search();
				}
			}
		}
	}catch(e){
	}
}

