// JavaScript Document
// --------------------------------------------------------------
// Icon for the red square displayed with the mouse wheel zoom
/* Amit
var baseIcon = new GIcon();
baseIcon.iconSize=new GSize(100,100);
baseIcon.iconAnchor=new GPoint(50,50);
var rectIcon = new GIcon(baseIcon, "images/rect.png", null);
*/
// Global variables used with the mouse wheel zoom
/* Amit
var mouseLatLng;
var zoomRect;
// --------------------------------------------------------------

var map;
var container;

// Defaults --------------------------------------------
var zoom = 2;
var centerPoint = new GLatLng(0,0);
var wheelZooming = false;

*/ 
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

// Creates a marker at the given point with the given info and icon type
function createMarker(venue, venueid, name, typeicon, typetext, malecount, femalecount, pin) 
{
	if(pin) {
        var icon = new GIcon();
        icon.image = "images/" + pin + ".png";
		icon.shadow = "images/pushpin_shadow.png";
		icon.transparent = "images/pushpin_transparent.png";
	    icon.imageMap = [8,33, 8,24, 1,21, 1,18, 4,13, 0,6, 0,4, 6,2, 12,1, 18,3, 18,5, 15,13, 18,17, 18,20, 12,25, 10,33, 8,33, 9,32, 8,33];
        icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(28, 21);
        icon.iconAnchor = new GPoint(4, 20);
        icon.infoWindowAnchor = new GPoint(6, 2);
        var marker = new GMarker(venue,icon);
    } else {
        var marker = new GMarker(venue);
    }
	// var stars = '';
	// if(rating > 0)
	//	stars = "<img src=\"images/star" + rating + ".png\" alt=\"Venue rating\" />";
	
	var html = "<form action=\"\" method=\"post\" name=\"hangme\"><input type=\"hidden\" name=\"spotid\" value=" + venueid  + " /><div style=\"width:248px;\"><div id=\"bubble_title\" style=\"height:20px\"><a href=\"index.php?PageURL=SpotDetail&SpotID=" + venueid + "\" title=\"View details on this spot\">" + name + "</a></div><div style=\"margin:0; padding:5px 10px; background:url(images/bg_bubble.png) no-repeat bottom left\"><table cellspacing=\"3\" cellpadding=\"0\"><tr><td valign=\"middle\" style=\"text-align:center; width:60px\"><a href=\"index.php?PageURL=SpotDetail&SpotID=" + venueid + "\" title=\"View details on this spot\"><img src=\"images/" + typeicon + "\" alt=\"" + typetext + "\" /></a></td><td valign=\"top\"><p style=\"margin:5px 0 0\"><a href=\"index.php?PageURL=SpotDetail&SpotID=" + venueid + "\" title=\"View details on this spot\">Spot Profile</a></p><p style=\"margin:5px 0 0\"><span class=\"label\">Guys:</span> " + malecount + "<br /><span class=\"label\">Girls:</span> " + femalecount + "</p><p style=\"margin:5px 0 10px 0\"><a href=\"javascript:document.hangme.submit();\" title=\"Add this spot to your profile\">I Hang Here</a></p></td></tr></table></div></div></form>";

	GEvent.addListener(marker, "click", function() {
			//window.open("venue.php?id=" + venueid, "_self");
			marker.openInfoWindowHtml(html);
    });	

	/*GEvent.addListener(marker, "mouseover", function() {
				marker.openInfoWindowHtml(html);
			});*/
	
	return marker;
}

// Creates a city marker at the given point with the given info and icon type
function createCityMarker(city, spot_country, spot_state, venuecount) 
{
	var icon = new GIcon();
	icon.image = "images/pushpin_yellow.png";
	icon.shadow = "images/pushpin_shadow.png";
	icon.transparent = "images/pushpin_yellow_transparent.png";
	icon.imageMap = [9,33, 7,23, 1,21, 1,17, 4,15, 0,6, 0,5, 7,1, 12,1, 18,3, 18,6, 15,14, 18,17, 18,20, 11,23, 10,32, 8,32, 9,33];
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(28, 21);
	icon.iconAnchor = new GPoint(4, 20);
	icon.infoWindowAnchor = new GPoint(6, 2);
	var marker = new GMarker(city,icon);
	
	var html = "<div style=\"width:248px\"><div id=\"bubble_title\"><a href=\"map.php?findcity=" + spot_country + "\" title=\"View spot in this city\">" + spot_state + "</a></div><div style=\"margin:0; padding:10px; background:url(images/bg_bubble.png) no-repeat bottom left\"><p>" + spot_state + " has " + venuecount + " venues</p><p><a href=\"map.php?findcity=" + spot_country + "\" title=\"View spot in this city\">View " + spot_state + " venues</a></p></div></div>";
	
	GEvent.addListener(marker, "click", function() {
			//window.open("index.php?PageURL=Map&findcity=" + cityid, "_self");
 			window.open("index.php?PageURL=Map&findcountry=" + spot_country+"&findstate=" + spot_state, "_self");
    });

	/*GEvent.addListener(marker, "mouseover", function() {
			marker.openInfoWindowHtml(html);
	});*/

	return marker;
}

function highlight(c,colour){
	if(typeof colour == "undefined")colour = '#cc6600';
	c.style.borderColor = colour;
}

function lowlight(c,colour){
	if(typeof colour == "undefined")colour = '#999';
	c.style.borderColor = colour;
}

// Mouse wheel zoom - Event handler -----
function wheelZoom(event) {
	if (wheelZooming) {
		return;
	}

	wheelZooming = true;

	// zoomRect and rectIcon are global variables!!!

	zoomRect = new GMarker(mouseLatLng,{icon:rectIcon});
	map.addOverlay(zoomRect);

	if (event.cancelable) {
		event.preventDefault();
	}
	map.closeInfoWindow(); 
	if((event.detail || -event.wheelDelta) < 0) {
		window.setTimeout(function(){
			map.removeOverlay(zoomRect);
			map.zoomIn(mouseLatLng,true,true);
			wheelZooming = false;
		},200);
	} 
	else {
		window.setTimeout(function(){
			map.removeOverlay(zoomRect);
			map.zoomOut(mouseLatLng,true);
			wheelZooming = false;
		},200);
	}
	return false; 
}
// End event handler -----


function mouseMove(mousePt) {
	mouseLatLng = mousePt;
	var zoom = map.getZoom();
	var mousePx = '';
}

function Reload () {
var f = document.getElementById('iframe1');
f.src = f.src;
}
