﻿// JScript File
    var map;  
    var deselectCurrent = function() {};
    var focusLong = '';
    var focusLat = '';
    
    function initializePoint(pointData, pos) {
	    var point = new GLatLng(pointData.latitude, pointData.longitude);
    	
	    var icon = new GIcon();
	    icon.image = "http://www.tampahotelsandmotels.com/img/mk/marker" + pos + ".png";
	    icon.shadow = "http://www.tampahotelsandmotels.com/img/mm_20_shadow.png";
        icon.iconSize = new GSize(20, 34);
        icon.shadowSize = new GSize(37, 34);
        icon.iconAnchor = new GPoint(9, 34);
        icon.infoWindowAnchor = new GPoint(9, 2);
        icon.infoShadowAnchor = new GPoint(18, 25);
    	
	    var marker = new GMarker(point,icon);
	    
	    var listItem = document.createElement('li');
	    var listItemLink = listItem.appendChild(document.createElement('a'));
	    listItemLink.style.display = 'block';
	    
	    var listItemPrice = listItem.appendChild(document.createElement('div'));
	    var listItemData = listItem.appendChild(document.createElement('div'));
	    var listItemSep = listItem.appendChild(document.createElement('div'));
	    var visible = false;

	    listItemLink.href = "#";
	    listItemLink.innerHTML = '<span style="font-weight : normal;">' + pointData.number + ') </span> ' + pointData.name;
	    
        if (pointData.lo != 0) { listItemPrice.innerHTML = 'Starting at <b>$' + pointData.lo + '</b>'; }
        
	    listItemData.innerHTML = pointData.distance;
	    
	    listItemSep.innerHTML = '<hr style="height : 1px; width: 80%;"/>';
	    	        	
	    var focusPoint = function() {
		    deselectCurrent();
		    listItem.className = 'current';
		    deselectCurrent = function() { listItem.className = ''; }
		    var frm = '';
		    
		    frm =  frm + '<div style="font-size : 1.1em; font-weight : bold;">' + pointData.name + '</div>';
		    if (pointData.lo > 0) 
		    { frm =  frm + '<div style="font-size : .9em; margin-top : 3px;"><a href="' + pointData.website + '" title="hotel booking details">Reserve now from $' + pointData.lo + ' per night.</a></div>'; }
		    else
		    { frm =  frm + '<div style="font-size : .9em; margin-top : 3px;"><a href="' + pointData.website + '" title="hotel booking details">Reserve Your Room!</a></div>'; }

		    if (pointData.distance != '') 
		    { frm =  frm + '<div style="font-size : .85em;"><i>' + pointData.distance + '</i></div>'; }
		    //frm =  frm + '<address style="font-size : .85em; margin-top : 5px;">' + pointData.address + '</address>';
		    //frm =  frm + '<div style="font-size : .85em; margin-top : 5px;"><b>Description</b><br/>' + pointData.description + ' ...</div>';
		    marker.openInfoWindowHtml('<div style="width : 300px; padding : 5px;">' + frm + '</div>');
		    map.panTo(point);
		    return false;
	    }

	    GEvent.addListener(marker, 'click', focusPoint);	
	    listItemLink.onclick = focusPoint;

	    pointData.show = function() {
		    if (!visible) {
			    document.getElementById('sidebar-list').appendChild(listItem);
			    map.addOverlay(marker);
			    visible = true;
		    }
	    }
	    
	    pointData.hide = function() {
		    if (visible) {
			    document.getElementById('sidebar-list').removeChild(listItem);
			    map.removeOverlay(marker);
			    visible = false;
		    }
	    }

	    pointData.show();
	    
    }
    
    function changeBodyClass(from, to) {
	    document.body.className = document.body.className.replace(from, to);
	    return false;
    }

    function init(zmlvl) {
	    var type;
	    var allTypes = { 'All':[] };
    	   	    
	    map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(focusLat, focusLong), zmlvl);

	    for(id in markers) {
		    initializePoint(markers[id],markers[id].number);
		    allTypes[markers[id].type] = true;
	    }

	    for(type in allTypes) {
	        /* Removed since we are adding sort tabs server side */
		    /* initializeSortTab(type); */
	    }
	    //changeBodyClass('loading', 'standby');
    }
    
    function createArrow(point) {
	
	    var marker = new GMarker(point);
        var baseIcon = new GIcon();
		var icon = new GIcon(baseIcon);
		
   	    baseIcon.image = 'http://www.tampahotelsandmotels.com/img/arrow.png';
	    baseIcon.shadow = 'http://www.tampahotelsandmotels.com/img/arrowshadow.png';
	    baseIcon.iconSize = new GSize(40, 34);
	    baseIcon.shadowSize = new GSize(40, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
	    baseIcon.infoWindowAnchor = new GPoint(9, 2);
	    baseIcon.infoShadowAnchor = new GPoint(18, 25);

		var marker = new GMarker(point, baseIcon);
		return marker;
	}
