
function util_poi_get_all()
{
	map_5255.clearOverlays();
	// get bound points
	var map_center = map_5255.getCenter();
	var bounds = map_5255.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
	var latSpan = northEast.lat() - southWest.lat();
	var lngSpan = northEast.lng() - southWest.lng();
	$.ajax({
		type: 'GET',
		dataType: 'json',
		url: site_url + poi_type + '/ax_get_all/',
		success: function(res) {
			if (res.status=='0') {
				m_list = res.rows;
				util_marker_clusterer();
			} else if (res.status=='1') {
				//
			} else {
				alert(res.errorDesc);
			}
		},
		failure: function(res) {alert('failure');}
	});

	return false;
}

function util_marker_clusterer() {
	markers = [];
	var mcOptions = { gridSize: 30, maxZoom: 11};
	var marker_inx = 0;
	for (x in m_list) {
		var point = new GLatLng(m_list[x].GLat, m_list[x].GLng);
		markers.push(util_create_poi_marker(point, m_list[x], marker_inx));
		marker_inx++;
	}
	gmc = new MarkerClusterer(map_5255, markers, mcOptions);
}

function util_create_poi_marker(point,poi_item,m_inx) {
	var marker = new GMarker(point, poi_icon);
	marker.tooltip = '<div class="tooltip_5255">'+poi_item.name+'</div>';
	GEvent.addListener(marker, "mouseover", function() {
		setTimeout(function() {
			util_show_tooltip(marker);
		}, (100));
	});
	GEvent.addListener(marker, "mouseout", function() {
		setTimeout(function() {
			tooltip_5255.style.visibility="hidden";
		}, (100));
	});
	GEvent.addListener(marker, "click", function() {
		var istr = '<div style="float: left; text-align:left; font-size: 9px;"><div style="float: left; text-align:left; font-size: 9px;"><strong>'+poi_item.name+'</strong><hr><div style="float: left; width: 140px; height: 128px; text-align:left; font-size: 9px;"><a id="alb_img_'+poi_item.cust_id+'" href="javascript:util_express_color('+poi_item.cust_id+', \''+poi_item.name+'\');" title=""><image src="'+asset_url+'img/boya/small/'+poi_item.cust_id+'.jpg" border="0"></a></div><strong>Adres:</strong> '+poi_item.adres+'<br><strong>Tel:</strong> '+poi_item.phone1+'<br><br><br><div style="text-align:right;"><a href="javascript:util_marker_zoom_in('+poi_item.GLat+', '+poi_item.GLng+');">Yakınlaş</a> | <a href="javascript:util_marker_get_dirs('+m_inx+');">Yol Tarifi Al</a></div></div>';
		marker.openInfoWindowHtml(istr);
	});
	marker.poi_item = poi_item;
	return marker;
}

function util_express_color(p_cust_id, p_name) {
	$.fancybox({
		'padding'		: 0,
		'overlayOpacity': 0.7,
		'overlayColor'	: '#000000',
		'href'			: asset_url+'img/boya/medium/'+p_cust_id+'.jpg',
		'title'   		: p_name,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
}

function util_marker_zoom_in(GLat, GLng) {
	var p_center = new GLatLng(GLat,GLng);
	map_5255.setCenter(p_center, 15);
}

function util_marker_get_dirs(m_inx) {
	util_marker_get_dirs_ctx(markers[m_inx]);
}

function util_marker_get_dirs_ctx(marker) {
	if (my_place instanceof GMarker) {
		marker.closeInfoWindow();
		dirs_init_vars(marker);
	} else {
		$.fancybox('Önce konumunuzu işaretleyiniz!<br>Harita üzerinde sağ tıklayarak konumunuzu işaretleyebilirsiniz.');
	}
}

function util_show_tooltip(marker) {
	tooltip_5255.innerHTML = marker.tooltip;
	var point=map_5255.getCurrentMapType().getProjection().fromLatLngToPixel(map_5255.getBounds().getSouthWest(),map_5255.getZoom());
	var offset=map_5255.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map_5255.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
	pos.apply(tooltip_5255);
	tooltip_5255.style.visibility="visible";
}

function CallPrint(prtContent)
{
	var WinPrint = window.open('','','left=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');
	WinPrint.document.write(prtContent);
	WinPrint.document.close();
	WinPrint.focus();
	WinPrint.print();
	WinPrint.close();
}

function fancy_call_help()
{
	$.fancybox(document.getElementById("div_help").innerHTML);
}
