OtherCallbacks = {
    map: null,
    icon: null,
    markers: [],
    records: [],
    markerFields: {},
    htmlFields: {},
    init: function( map, markerFields, htmlFields, htmlResults, icon, cluster_icon ) {
        this.icon = icon;    
        if ( cluster_icon ) {
            map.declutterGroup( icon.groupName, { 'cluster_icon' : cluster_icon } );
        }
        this.markerFields = markerFields;
        this.htmlFields = htmlFields;
        this.htmlResults = htmlResults;
        this.map = map;
    },
    getIcon: function( record ) {
        if ( typeof this.icon == 'function' ) {
            this.getIcon = function( record ) {
                return this.icon( record );
            }
        } else {
            this.getIcon = function( record ) {
                return this.icon;
            }
        }
        return this.getIcon( record );
    },
	OtherStoreSearch: function( data, searchpoint ) {
    	this.map.setCenter(searchpoint, 13);
 		this.htmls=[];
        this.markers = [], this.records = [];
        var record, marker, bounds, infobox, html = [];
        bounds = new GLatLngBounds(); 
        if ( data.records && data.records.length > 0 ) {
            if ( data.records.length > 1 ) {
                for ( var i = 0, j = data.records.length; i < j; i++ ) {
                	  var index=10+i;
                    record = data.records[i];
					infobox = this.getInfoBoxHtml( record, this.markerFields, 'infobox', 'div', index );
                    html.push( this.getHtml( record, this.htmlFields, 'result', 'table', index ) );
         			this.htmls[i]=infobox;
	            	var point = new GLatLng(record.point.lat, record.point.lon);
	            	marker=this.createMarker(point,record,infobox,i);
	            	this.map.addOverlay(marker);
                    this.markers.push( marker );
                    this.records.push( record );
                    bounds.extend( point );
                }
                this.handleResults( html );
                bounds.extend( searchpoint );
				this.map.setCenter(searchpoint, this.map.getBoundsZoomLevel(bounds)); 
            } else {
                this.records.push( data.records[0] );
                this.markers.push( marker );
            }
        } else {
 								bounds.extend( searchpoint );
								this.map.setCenter(searchpoint,9); 
        }
        return true;
    },
	    handleResults: function( results ) {
	        if ( this.htmlResults ) {
	            var header = 'Branch name';
	            if ( Page.oParams.type.toLowerCase() == 'pharmacy' || Page.oParams.type.toLowerCase() == 'food' ) {
	                header = 'Store';
	            }
	            this.htmlResults.innerHTML = '';
	            var html = '';
	            html += '<tr class="MMTableRoot MMTableHeader">';
	            html += '<td class="MMResultFragment MMName">' + header + '</td>';
	            html += '<td class="MMResultFragment MMDistance">Distance</td>';
	            html += '<td class="MMResultFragment MMAddress">Contact details</td>';
	//            html += '<td class="MMResultFragment MMLinks">Links</td>';
	            html += '</tr>';
	            this.htmlResults.innerHTML = '<table cellspacing="0" cellpadding="0" class="MMresultRoot">' + html + results.join( '' ) + '</table>';
	        }
	    },
	    getInfoBoxHtml: function( record, tabs, classname, rootel, id ) {
	        var markertabs = [], tabhtml, validtab;
	        for ( var tab in tabs ) {
	            tabhtml = this.getHtml( record, tabs[tab], classname, rootel, id );
	            if ( tabhtml.match( /class/ig ).length > 1 ) {
	                validtab = tabhtml;
	     //           markertabs.push( new MMInfoBoxTab( tab, tabhtml ) );
	            }
	        }
	        if ( markertabs.length > 1 ) {
	            return markertabs;
	        } else {
	            return validtab;
	        }
	    },
		   createMarker:  function(point, record,infoboxhtml,i) {
		   	 //          marker = createMarker( record.point, { 
		          //              'label' : record.store_name, 
		          //              'icon' : this.getIcon( record ), 
		           //             'text' : i   + 1
		           //         } );

		  // Set up our GMarkerOptions object
			  markerOptions = { icon:Page.getIcon( record,i ),title : record.store_name,zIndexProcess:inverseOrder};
			  var marker = new GMarker(point, markerOptions);
			 	GEvent.addListener(marker, "click", function() {
			  marker.openInfoWindowHtml( infoboxhtml);
		  });
		  return marker;
		},
    getHtml: function( record, fields, classname, rootel, id ) {
   
        var html;
        if ( typeof fields.customInsert == 'function' ) {
            return fields.customInsert( record, id );
        }
        if ( fields.addOnClick ) {
            if ( typeof fields.customOnclick == 'function' ) {
                window[classname + 'customonclick'] = fields.customOnclick;
                html = '<' + rootel + ' class="MM' + classname + 'Root" onclick="' + classname + 'customonclick( ' + id + ' ); return false;">';
            } else {
                html = '<' + rootel + ' class="MM' + classname + 'Root" onclick="Callbacks.markers[' + id + '].openInfoBox(); return false;">';
            }
        } else {
            html = '<' + rootel + ' class="MM' + classname + 'Root">';
        }
        for ( var field in fields ) {
            if ( record[fields[field].fieldname] ) {
                html += '<' + fields[field].element + ' class="MM' + classname + fields[field].fieldname + '">';
                html += record[fields[field].fieldname];
                html += '</' + fields[field].element + '>';
            }
        }
        html += '</' + rootel + '>';
        return html.replace( /(\<a)+/ig, '<a href="#"' );
    }
}
