var geocoder = null;
var Gselected_company_id='';
var wait_for_address=1;

var anchor_lats=new Array();
var anchor_longs=new Array();


function oparate_cords(marker_id,lat,lng)
{
nodes = $A(anchor_lats);
nodes.each(function(node,index){ if (node[1]==marker_id) {node[0]=lat;anchor_longs[index]=new Array(lng,marker_id);} });
//alert(nodes.inspect());
}

function operate_address(marker_id,lat,lng,address,text,icon_src,icon_width,icon_height,draggable)
{
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
insert_marker(marker_id,lat,lng,text,icon_src,icon_width,icon_height,draggable)
return '';
} else {
map.setCenter(point, 15);
insert_marker(marker_id,point.lat(),point.lng(),text,icon_src,icon_width,icon_height,draggable);
}
}
);
}
}

function insert_marker(marker_id,lat,lng,text,icon_src,icon_width,icon_height,draggable)
{
var blueIcon = new GIcon(G_DEFAULT_ICON);
if (icon_src!='')
{
blueIcon.image = icon_src;
blueIcon.printImage = icon_src;
blueIcon.iconSize = new GSize(icon_width,icon_height);
blueIcon.iconAnchor = new GPoint(icon_width/2,icon_height);
blueIcon.shadowSize = new GSize(0, 0);
blueIcon.infoWindowAnchor = new GPoint(icon_width/2, 0);
blueIcon.imageMap = [0,0,icon_width,0,icon_width,icon_height,0,icon_height];	//for clickable area
}
var marker = new GMarker(new GLatLng(lat,lng)/*, {icon:blueIcon}*/);
if (draggable==1)
{
marker = new GMarker(new GLatLng(lat,lng), {draggable: true/*, icon:blueIcon*/});
GEvent.addListener(marker, "dragstart", function() {
map.closeInfoWindow();
});
GEvent.addListener(marker, "dragend", function() {
var rez = marker.getLatLng();
oparate_cords(marker_id,rez.lat(),rez.lng());
});
}
if (text!='')
{
GEvent.addListener(marker,"mouseover", function() {marker.openInfoWindowHtml(text);});
GEvent.addListener(marker,"mouseout", function() {marker.closeInfoWindow();});
}
map.addOverlay(marker);
}

function createMarker(marker_id,lat,lng,address,text,icon_src,icon_width,icon_height,draggable)
{
if (address!='') operate_address(marker_id,lat,lng,address,text,icon_src,icon_width,icon_height,draggable);
else insert_marker(marker_id,lat,lng,text,icon_src,icon_width,icon_height,draggable);
}

function MyApplication(id, start_x, start_y, zoom)
{
if (GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("map_canvas_"+id));
map.setCenter(new GLatLng(start_x, start_y), zoom);
map.addControl(new GSmallMapControl()); //arrows lef-right
map.addControl(new GMapTypeControl()); // view mode (satelite...)
//map.addControl(new GLargeMapControl()); //left side zooming tool
geocoder = new GClientGeocoder();

}

}

function initialize_googleMaps(id, start_x, start_y, zoom)
{
var application = new MyApplication(id, start_x, start_y, zoom);
}


function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 15);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
