﻿function GIcons()
{
  GIcons.prototype.getLargeHotelIcon = function()
  {
    var icon = new GIcon();

    icon.image            = '/img/L_marker_hotel.png';
    icon.shadow           = '/img/L_marker_hotel_sh.png';
    icon.iconSize         = new GSize(26,26);
    icon.shadowSize       = new GSize(40,27);
    icon.iconAnchor       = new GPoint(13,27);
    icon.infoWindowAnchor = new GPoint(13,1);

    return icon;
  };

  GIcons.prototype.getHotelIcon = function()
  {
    var icon = new GIcon();

    icon.image            = '/img/marker_hotel.png';
    icon.shadow           = '/img/marker_hotel_sh.png';
    icon.iconSize         = new GSize(17,17);
    icon.shadowSize       = new GSize(28,20);
    icon.iconAnchor       = new GPoint(8,17);
    icon.infoWindowAnchor = new GPoint(8,1);

    return icon;
  };
}


var map;
var icon = new GIcon();
icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(5, 1);

var l_icon =new GIcons().getLargeHotelIcon();
var s_icon =new GIcons().getHotelIcon();


function createMarker(point,html) {
  var marker = new GMarker(point,icon);
  GEvent.addListener(marker, "mouseover", function() {
  //marker.openInfoWindow(html);
  });  
  return marker;
}

function createHMarker(i, ico) {
	var marker=new GMarker(new GLatLng(hotelsAr[i][0], hotelsAr[i][1]), {draggable: false, icon: ico});
	GEvent.addListener(marker, "mouseover",function() {
			displayPoint(marker, i);
	});	
	GEvent.addListener(marker, "mouseout",function() {
			bID('mapText').style.display='none';
	});
	GEvent.addListener(marker, "click",function() {
			window.location='http://www.traveladriatic.net' + hotelsAr[i][6] + '/affiliate_hotel.asp?hotl_id=' + hotelsAr[i][7];
	});
	return marker;
}

	var pozicija='';

	function loadHotels(x,y,z) {
	if (GBrowserIsCompatible()) {
        map = new GMap2(bID('map'));
	map.addControl(new GLargeMapControl());
	map.addControl(new GScaleControl());

	try { 
	var divTag = document.createElement("div");
        divTag.id = "mapText";
	divTag.style.display="none";
	bID('mapcover').appendChild(divTag);
	map.getPane(G_MAP_FLOAT_PANE).appendChild(divTag); 
	} catch (e) {}

        map.setCenter(new GLatLng(x,y), z);
	map.enableContinuousZoom();
	map.enableDoubleClickZoom();


	for (i=1; i<hotelsAr.length; i++) {
		map.addOverlay(createHMarker(i, s_icon));
	}
	map.addOverlay(createHMarker(0, l_icon));
	}
	}


	function loadHotel(i) {
	if (GBrowserIsCompatible()) {
        map = new GMap2(bID('map'));
	map.addControl(new GLargeMapControl());
	map.addControl(new GScaleControl());

	try { 
	var divTag = document.createElement("div");
        divTag.id = "mapText";
	divTag.style.display="none";
	bID('mapcover').appendChild(divTag);
	map.getPane(G_MAP_FLOAT_PANE).appendChild(divTag); 
	} catch (e) {}

        map.setCenter(new GLatLng(hotelsAr[i][0], hotelsAr[i][1]), 13);
	map.enableContinuousZoom();
	map.enableDoubleClickZoom();

	map.addOverlay(createHMarker(i, l_icon));
	}
	}

	function loadSMap(x,y,z) {
	if (GBrowserIsCompatible()) {
        smap = new GMap2(bID('smap'));
	//smap.addControl(new GLargeMapControl());
	//smap.addControl(new GScaleControl());

        smap.setCenter(new GLatLng(x,y), z);
	smap.enableContinuousZoom();
	smap.enableDoubleClickZoom();

	smap.addOverlay(createHMarker(0, l_icon));
	}
	}


	function displayPoint(marker, idx){
		$("#mapText").hide();

		var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
		var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
		var anchor=marker.getIcon().iconAnchor;
		var iheight=marker.getIcon().iconSize.height;
		var height=bID('mapText').clientHeight;
		var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x, offset.y - point.y -anchor.y + iheight+3)); 
		pos.apply(bID('mapText'));

		$("#mapText").html('<table width=74 height=90 align=left style="margin-right:4" ><tr><td>	<div style="width:66; height:66; border:1px solid #111111; background:none">	<img tip=mapImage lbox=0 width=60 hegiht=60 reflect=1 bgcolor="#222222" src="' + hotelsAr[idx][3] + '">	</div>	</tr></td></table> <font color="#ffcccc"><u><b>' + hotelsAr[idx][4] + '</b></u> ' + hotelsAr[idx][5] +'</font><br>' + hotelsAr[idx][2]);
		$('img[tip=mapImage][reflect=1]').each(function(){
			$(this).load( 
				function(){ 
					$(this).reflect({height: 0.3, opacity: 0.5, marginTop:10}, $(this).attr('bgcolor') );
				} 
			);
		});

		$("#mapText")
			.show();
			//.css({ top:markerOffset.y, left:markerOffset.x });
	}