google.load("maps", "2");
var map;
var service, checkin, busy, type, loader, timeout, temp;
var FSQVenues = [];
var GOWVenues = [];
var TWTVenues = [];
var BKTVenues = [];
var manIcon, icon, iconFSQ, iconGOW, iconBKT, iconTWT;
var manMarker;
var geocoder, bounds;
var currentPosition;
var moveListener;
var blank = "";
var retry = "<div align='center' onclick='getData(0)' style='padding:10px;color:#eee;font-weight:bold'>RETRY</div>";
var filter = "";
		
$("document").ready(function() {
	service = 99;
	checkin = 0;
	busy = 0;
	type = 0;
	loader = 0;timeout = 0;
	document.getElementById('buttonMap').style.left = (document.getElementById('map').offsetWidth/2 - 50) + "px";  
	map = new GMap2(document.getElementById("map"));
	map.setUIToDefault();
	map.checkResize();
	defaultLat = 37.77675098675219;
	defaultLng = -122.43414580821991;
	defaultLng += Math.floor(Math.random()*999) * 0.00000000000001;
	map.setCenter(new GLatLng(defaultLat,defaultLng),16);
	geocoder = new GClientGeocoder();
	iconFSQ = new google.maps.Icon();
	iconFSQ.image = "";
	iconFSQ.iconSize = new google.maps.Size(24, 24);
	iconFSQ.iconAnchor = new google.maps.Point(12, 12);
	iconFSQ.infoWindowAnchor = new google.maps.Point(12, 12);
	iconGOW = new google.maps.Icon();
	iconGOW.image = "";
	iconGOW.iconSize = new google.maps.Size(24, 24);
	iconGOW.iconAnchor = new google.maps.Point(12, 12);
	iconGOW.infoWindowAnchor = new google.maps.Point(12, 12);
	iconBKT = new google.maps.Icon();
	iconBKT.image = "";
	iconBKT.iconSize = new google.maps.Size(24, 24);
	iconBKT.iconAnchor = new google.maps.Point(12, 12);
	iconBKT.infoWindowAnchor = new google.maps.Point(12, 12);
	iconTWT = new google.maps.Icon();
	iconTWT.image = "";
	iconTWT.iconSize = new google.maps.Size(24, 24);
	iconTWT.iconAnchor = new google.maps.Point(12, 12);
	iconTWT.infoWindowAnchor = new google.maps.Point(12, 12);	
	manIcon = new google.maps.Icon();
	manIcon.image = "http://www.checkinmania.com/man.png";
	manIcon.iconSize = new google.maps.Size(50, 50);
	manIcon.iconAnchor = new google.maps.Point(16, 50);
	manIcon.infoWindowAnchor = new google.maps.Point(14, 5);
	addMashman(map.getCenter());
	currentPosition = manMarker.getPoint();
	GEvent.addListener(map, 'click', function(overlay, point) {
		if(!overlay){
			currentPosition = point;
			manMarker.setPoint(point);
			getData(0);				
		}
	});
	GEvent.addListener(map, 'dragend', function() {
		if(document.getElementById("panSearch").checked == false){
			$('#buttonMap').fadeOut('slow');
			$('#buttonMap').fadeIn('slow');
		}
	});	
	defaultService();
});	
 
$(window).unload( function () { GUnload(); } );
 
addMashman = function(latlng) {
	manMarker = new GMarker(latlng, {icon:manIcon, draggable: true, bouncy: true, title: "Drag Me!"});				
	map.addOverlay(manMarker);
	GEvent.addListener(manMarker, "dragend", function(){
		manMarker.closeInfoWindow();
		currentPosition = manMarker.getPoint();
		getData(0);				
	});
	GEvent.addListener(manMarker, "click", function(){
		var position = manMarker.getPoint();
		geocoder.getLocations(position, function(addresses) {
		  if(addresses.Status.code != 200) {
			manMarker.openInfoWindowHtml("<div style='font-size:9pt'><center><b>I have no idea where I am </b><br>My position is " + position.toUrlValue() +"<br><br></div><div style='font-size:8pt;color:#888'>Click anywhere on map or drag me to a new location to search places around</div>",{maxWidth:200});
		  }
		  else {
			address = addresses.Placemark[0];
			var html = address.address;
			manMarker.openInfoWindowHtml("<div style='font-size:9pt'><center><b>I'm at</b><br>"+html+"<br><br></div><div style='font-size:8pt;color:#888'>Click anywhere on map or drag me to a new location to search places around</div>",{maxWidth:200});
		  }
		});					
	});	
};

getFSQSpecials = function(lat,lng,isZoomfit){
  busy = 1;
  timeout++;
  if(timeout > 1) {clearInterval(loader);}
  type = 2;
  hideDetails();
  $("#sidebar").html("<div style='text-align:center;font-weight:bold;cursor:pointer;font:8pt Arial' onclick='busy=0;this.innerHTML=retry;clearInterval(loader);'><img src='http://www.checkinmania.com/20_loading_icon.gif'><br/>Cancel</div>");
  var url = "https://api.foursquare.com/v2/venues/search?limit=50&intent=specials&ll="+lat+","+lng+"&query="+filter+"&client_id=NUZDSFI15SJGH24Z4Q13Y2O3ESBWZEPV4ST54WNWWGIU5A23&client_secret=ENYHRNGTKGX3HOKYZWDOQFRLFDDALKJAJLSOUJ4S5ZLXEA32&callback=?";
  $.getJSON(url, function(data) {
	for (var i=0; i<FSQVenues.length; i++) {
		map.removeOverlay(FSQVenues[i].marker());
	}
	$("#sidebar").html('<div id="buttons" style="" align="center"><div id="buttonVenue" onclick="toggleDataType(0)" onmouseover="this.style.backgroundColor=\'#444\'" onmouseout="this.style.backgroundColor=\'#222\'"><b>Venues</b></div><img src="http://www.checkinmania.com/blank.gif" width=10 height=1><div id="buttonOther" onclick="toggleDataType(1)" onmouseover="this.style.backgroundColor=\'#444\'" onmouseout="this.style.backgroundColor=\'#222\'"><b>Tips</b></div><img src="http://www.checkinmania.com/blank.gif" width=10 height=1><div id="buttonDeals" onclick="toggleDataType(2)"><b>Deals</b></div></div>');
	document.getElementById('buttonVenue').style.background='#222';
	document.getElementById('buttonOther').style.background='#222';
	document.getElementById('buttonDeals').style.background='#444';
	manMarker.setPoint(new GLatLng(lat,lng));
	currentPosition = new GLatLng(lat,lng);
	bounds = new GLatLngBounds();
	bounds.extend(manMarker.getPoint());
	if(data.meta.code != 200) {
    	timeout++;
    	if(timeout > 1) clearInterval(loader);
	    $("#sidebar").html("");
	    manMarker.openInfoWindowHtml("<div style='font-size:9pt'><br><b>"+data.meta.errorDetail+"</b></div>",{maxWidth:200});		
	} else {
		var specials = 0;
		for(var i=0;i<data.response.groups.length;i++){
			if(data.response.groups[i].type == 'specials'){
				specials = i;
			}
		}
	  	for(var i=0;i<data.response.groups[specials].items.length;i++) {
	  		FSQVenues.push(new FSQVenue(data.response.groups[specials].items[i]));
		}
		if(isZoomfit){zoomFitMarkers();}
	}
	busy = 0;
	clearInterval(loader);
  });		
};
 
getFSQTips = function(lat,lng,isZoomfit){
  busy = 1;
  timeout++;
  if(timeout > 1) { clearInterval(loader); }
  type = 1;
  hideDetails();
  $("#sidebar").html("<div style='text-align:center;font-weight:bold;cursor:pointer;font:8pt Arial' onclick='busy=0;this.innerHTML=blank;clearInterval(loader);'><img src='http://www.checkinmania.com/20_loading_icon.gif'><br/>Cancel</div>");
  var url = "https://api.foursquare.com/v2/tips/search?limit=50&ll="+lat+","+lng+"&client_id=NUZDSFI15SJGH24Z4Q13Y2O3ESBWZEPV4ST54WNWWGIU5A23&client_secret=ENYHRNGTKGX3HOKYZWDOQFRLFDDALKJAJLSOUJ4S5ZLXEA32&callback=?";
  $.getJSON(url, function(data) {
	for (var i=0; i<FSQVenues.length; i++) {
		map.removeOverlay(FSQVenues[i].marker());
	}
	$("#sidebar").html('<div id="buttons" style="" align="center"><div id="buttonVenue" onclick="toggleDataType(0)" onmouseover="this.style.backgroundColor=\'#444\'" onmouseout="if(type!=0)this.style.backgroundColor=\'#222\'"><b>Venues</b></div><img src="http://www.checkinmania.com/blank.gif" width=10 height=1><div id="buttonOther" onclick="toggleDataType(1)" onmouseover="this.style.backgroundColor=\'#444\'" onmouseout="if(type!=1)this.style.backgroundColor=\'#222\'"><b>Tips</b></div><img src="http://www.checkinmania.com/blank.gif" width=10 height=1><div id="buttonDeals" onclick="toggleDataType(2, 1)" onmouseover="this.style.backgroundColor=\'#444\'" onmouseout="this.style.backgroundColor=\'#222\'"><b>Deals</b></div></div>');
	document.getElementById('buttonVenue').style.background='#222';
	document.getElementById('buttonOther').style.background='#444';
	document.getElementById('buttonDeals').style.background='#222';
	manMarker.setPoint(new GLatLng(lat,lng));
	currentPosition = new GLatLng(lat,lng);
	bounds = new GLatLngBounds();
	bounds.extend(manMarker.getPoint());
	if(data.meta.code != 200) {
    	timeout++;
    	if(timeout > 1) clearInterval(loader);
	    $("#sidebar").html("");
	    manMarker.openInfoWindowHtml("<div style='font-size:9pt'><br><b>"+data.meta.errorDetail+"</b></div>",{maxWidth:200});		
	} else {
	  	for(var i=0;i<data.response.tips.length;i++) {
	  		FSQVenues.push(new FSQVenue(data.response.tips[i]));
		}
		if(isZoomfit){zoomFitMarkers();}
	}
	busy = 0;
	clearInterval(loader);
  });		
};
 
getFSQVenues = function(lat,lng,isZoomfit){
  busy = 1;
  timeout++;
  if(timeout > 1) {clearInterval(loader);}
  type = 0;
  hideDetails();
  $("#sidebar").html("<div style='text-align:center;font-weight:bold;cursor:pointer;font:8pt Arial' onclick='busy=0;this.innerHTML=retry;clearInterval(loader);'><img src='http://www.checkinmania.com/20_loading_icon.gif'><br/>Cancel</div>");
  var url = "https://api.foursquare.com/v2/venues/search?limit=50&ll="+lat+","+lng+"&query="+filter+"&client_id=NUZDSFI15SJGH24Z4Q13Y2O3ESBWZEPV4ST54WNWWGIU5A23&client_secret=ENYHRNGTKGX3HOKYZWDOQFRLFDDALKJAJLSOUJ4S5ZLXEA32&callback=?";
  $.getJSON(url, function(data) {
	for (var i=0; i<FSQVenues.length; i++) {
		map.removeOverlay(FSQVenues[i].marker());
	}
	$("#sidebar").html('<div id="buttons" style="" align="center"><div id="buttonVenue" onclick="toggleDataType(0)" onmouseover="this.style.backgroundColor=\'#444\'" onmouseout="if(type!=0)this.style.backgroundColor=\'#222\'"><b>Venues</b></div><img src="http://www.checkinmania.com/blank.gif" width=10 height=1><div id="buttonOther" onclick="toggleDataType(1)" onmouseover="this.style.backgroundColor=\'#444\'" onmouseout="if(type!=1)this.style.backgroundColor=\'#222\'"><b>Tips</b></div><img src="http://www.checkinmania.com/blank.gif" width=10 height=1><div id="buttonDeals" onclick="toggleDataType(2, 1)" onmouseover="this.style.backgroundColor=\'#444\'" onmouseout="if(type!=1)this.style.backgroundColor=\'#222\'"><b>Deals</b></div></div>');
	$("#sidebar").append('<div style="padding:8px;background:#444"><span style="font-size:8pt;font-weight:bold">Search for </span>&nbsp;&nbsp;<input id="filter" type="text" value="'+filter+'" style="width:105px;" onFocus="this.value=\'\';filter=\'\'" onKeyPress="if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {applyFilter();return false;} else return true;">&nbsp;&nbsp;<input id="Search" type="button" value="Search" onclick="applyFilter()"></div>');
	document.getElementById('buttonVenue').style.background='#444';
	document.getElementById('buttonOther').style.background='#222';
	document.getElementById('buttonDeals').style.background='#222';
	manMarker.setPoint(new GLatLng(lat,lng));
	currentPosition = new GLatLng(lat,lng);
	bounds = new GLatLngBounds();
	bounds.extend(manMarker.getPoint());
	if(data.meta.code != 200) {
    	timeout++;
    	if(timeout > 1) clearInterval(loader);
	    $("#sidebar").html("");
	    manMarker.openInfoWindowHtml("<div style='font-size:9pt'><br><b>"+data.meta.errorDetail+"</b></div>",{maxWidth:200});		
	} else {
		var nearby = 0;
		for(var i=0;i<data.response.groups.length;i++){
			if(data.response.groups[i].type == 'nearby'){
				nearby = i;
			}
		}
	  	for(var i=0;i<data.response.groups[nearby].items.length;i++) {
	  		FSQVenues.push(new FSQVenue(data.response.groups[nearby].items[i]));
		}
		if(isZoomfit){zoomFitMarkers();}
	}
	busy = 0;
	clearInterval(loader);
  });		
};
 
FSQVenue = function(result) {
	this.result_ = result;
	map.addOverlay(this.marker());
	return;
};
 
FSQVenue.prototype.marker = function() {
	if (this.marker_) {return this.marker_;}
	iconFSQ.image = "http://foursquare.com/img/categories/none.png";
	if(type == 0){
		if(this.result_.categories.length > 0)
			if(this.result_.categories[0].icon)
				iconFSQ.image = this.result_.categories[0].icon;	
		var marker = new GMarker(new GLatLng(parseFloat(this.result_.location.lat), parseFloat(this.result_.location.lng)), {icon:iconFSQ, title:this.result_.name});	
		bounds.extend(new GLatLng(this.result_.location.lat,this.result_.location.lng));
		$("#sidebar").append(this.infoWin(1));
	} else if(type == 1){
		if(this.result_.venue.categories.length > 0)
			if(this.result_.venue.categories[0].icon)
				iconFSQ.image = this.result_.venue.categories[0].icon;	
		var marker = new GMarker(new GLatLng(parseFloat(this.result_.venue.location.lat), parseFloat(this.result_.venue.location.lng)), {icon:iconFSQ, title:this.result_.venue.name});	
		if(this.result_.venue.location.lat && this.result_.venue.location.lng){
			bounds.extend(new GLatLng(this.result_.venue.location.lat,this.result_.venue.location.lng));
		}
		$("#sidebar").append(this.infoWin(1));	
	} else if(type == 2){
		if(this.result_.categories.length > 0)
			if(this.result_.categories[0].icon)
				iconFSQ.image = this.result_.categories[0].icon;	
		var marker = new GMarker(new GLatLng(parseFloat(this.result_.location.lat), parseFloat(this.result_.location.lng)), {icon:iconFSQ, title:this.result_.name});	
		bounds.extend(new GLatLng(this.result_.location.lat,this.result_.location.lng));
		$("#sidebar").append(this.infoWin(1));
	}
	GEvent.bind(marker, "click", this, function() {
		marker.openInfoWindow(this.infoWin(0),{maxWidth:200});
		if(type == 0) {this.showDetails(this.infoWin(1));}
	});	
	this.marker_ = marker;
	return marker;
};	
 
FSQVenue.prototype.infoWin = function(isSidebar) {
	var container = document.createElement("div");
	var moreDetails;
	if(isSidebar){
		container.className = "venue";
	}else {
		container.className = "venue-infowin";
	}	
	var category_name = "";
	var category_image = "http://foursquare.com/img/categories/none.png";
	if(type == 0){
		if(this.result_.categories.length > 0) {
			if(this.result_.categories[0].name){
				category_name = this.result_.categories[0].name;
			}	
			if(this.result_.categories[0].icon){
				category_image = this.result_.categories[0].icon;
			}
		}
		container.innerHTML = "<table><tr><td style='padding-right:10px;'><img src='"+category_image+"'></td><td><div class='title-text'>"+this.result_.name+"</div><div class='subtitle-text'>"+category_name+"</div></td></tr></table><div class='clickhere'>details</div>";
		moreDetails = "<div style='text-align:center'><a class='subtitle-text' style='color:#00e' href='http://www.checkinmania.com/foursquare/places/"+this.result_.id+"' target='_blank'>Get More Details</a></div>";
	} else if(type == 1){
		var lastname = "";
		if(this.result_.user.lastName){ lastname = this.result_.user.lastName;}
		container.innerHTML = "<div style='padding:4px;font-size:8pt;'><table cellpadding=0 cellspacing=0 border=0><tr><td style='padding-right:10px;' valign='top'><a href='http://www.foursquare.com/user/"+this.result_.user.id+"' target='_blank'><img src='"+this.result_.user.photo+"' style='height:48px; width:48px' border=0></a></td><td valign=top><div style='padding:2px;font-size:9pt'><b>@ <a style='color:#777' href='http://foursquare.com/venue/"+this.result_.venue.id+"' target='_blank'>"+this.result_.venue.name+"</a></b> - "+this.result_.text+"<br>(via "+this.result_.user.firstName+" "+lastname+")</div></td></tr></table></div>"; 
		moreDetails = "<div style='text-align:center'><a class='subtitle-text' style='color:#00e' href='http://www.checkinmania.com/foursquare/places/"+this.result_.venue.id+"' target='_blank'>Get More Details</a></div>";
	} else if(type == 2){
		if(this.result_.categories.length > 0) {	
			if(this.result_.categories[0].icon){
				category_image = this.result_.categories[0].icon;
			}
		}
		var special = "";
		if(this.result_.specials.length > 0){
			for(i=0;i<this.result_.specials.length;i++){	    
				special += "<div style='padding-top:10px'><div class='subtitle-text'><span style='padding:3px;background-color:#dd2;color:#000;border-radius: 3px;-moz-border-radius: 3px;-webkit-border-radius: 3px;'>"+this.result_.specials[i].title+"</span></div><div class='subtitle-text' style='padding:3px'>"+this.result_.specials[i].message+"</div></div>";
			}
		}
		container.innerHTML = "<table><tr><td style='padding-right:10px;' valign='top'><a href='http://www.checkinmania.com/foursquare/places/"+this.result_.id+"' target='_blank'><img src='"+category_image+"' border=0></a></td><td><div class='title-text'>"+this.result_.name+"</div>"+special+"</td></tr></table>";
		moreDetails = "<div style='text-align:center'><a class='subtitle-text' style='color:#00e' href='http://www.checkinmania.com/foursquare/places/"+this.result_.id+"' target='_blank'>Get More Details</a></div>";
	}
	if(isSidebar) {
    	GEvent.bindDom(container, "mouseover", this, function() {
        	if (type == 0)this.marker_.openInfoWindow(container.innerHTML + moreDetails,{maxWidth:200});
        	else this.marker_.openInfoWindow(container.innerHTML + moreDetails,{maxWidth:280});
    		container.className = "venue-hover";
      	});  
      	GEvent.bindDom(container, "mouseout", this, function() { 
    		container.className = "venue";
      	});
      	GEvent.bindDom(container, "click", this, function() {  
    		container.className = "venue";
    		if(type == 0) {this.showDetails(container, moreDetails);}
      	});
  	} else {
  		container.innerHTML += moreDetails;
  	}
  	return container;
};
 
FSQVenue.prototype.showDetails = function (content, details) {
	var hover = document.getElementById("sidebar-bottom");
	$("#sidebar").height(230);
	$("#sidebar-bottom").height(270);
	$("#sidebar-bottom").hide();
	$("#sidebar-bottom").html("<div id='details' style='overflow-y:auto;overflow-x:hidden;border:6px solid #29c;height:250px;padding:4px'></div>");
	details ? details : "";
	var address_street = this.result_.address ? this.result_.address : "";
	var address_city = this.result_.city ? this.result_.city : "";
	var address_state = this.result_.state ? this.result_.state : "";
	var address_zip = this.result_.zip ? this.result_.zip : "";
	var address = '<div style="padding-left:48px;color:#555;font-size:8pt;">'+address_street+'<br/>'+address_city+' '+address_state+' '+address_zip+'</div><br/>';	
	$("#details").html(content.innerHTML + address + details);
    GEvent.bindDom(hover, "mouseover", this, function() {
        this.marker_.openInfoWindow(content.innerHTML,{maxWidth:200});
    });		
	$("#sidebar-bottom").fadeIn('slow');
	timeout = 0;
	getFSQVenueDetails(this.result_.id);
	temp = this.result_.id;
	loader = setInterval(function(){getFSQVenueDetails(temp);}, 6000);
	return;
};
 
getFSQVenueDetails = function(vid){
    timeout++;
    if(timeout > 1) {clearInterval(loader);}
	$("#details").append("<div id='loading' style='cursor:pointer;font:8pt Arial' onclick='busy=0;this.innerHTML=null;clearInterval(loader);'><img src='http://www.checkinmania.com/20_loading_icon.gif'> Cancel</div>");
	var url = "https://api.foursquare.com/v2/venues/"+vid+"?client_id=NUZDSFI15SJGH24Z4Q13Y2O3ESBWZEPV4ST54WNWWGIU5A23&client_secret=ENYHRNGTKGX3HOKYZWDOQFRLFDDALKJAJLSOUJ4S5ZLXEA32&callback=?";
	$.getJSON(url, function(data) {
		if(data.meta.code != 200) {
    		timeout++;
    		if(timeout > 1) clearInterval(loader);	
		//	$("#loading").html("<div align='center' style='font-size:8pt;color:#ddd'>"+data.meta.errorDetail+"</div>");
			$("#loading").html("");
		} else {	
			var category_name = "";
			var category_image = "http://foursquare.com/img/categories/none.png";
			if(data.response.venue.categories.length > 0) {
				if(data.response.venue.categories[0].name){
					category_name = data.response.venue.categories[0].name;
				}	
				if(data.response.venue.categories[0].icon){
					category_image = data.response.venue.categories[0].icon;
				}
			}
			$("#details").html("<div style='padding:3px;border:2px solid #29c;-moz-border-radius-bottomleft: 5px;-webkit-border-bottom-left-radius: 5px;-moz-border-radius-bottomright: 5px;-webkit-border-bottom-right-radius: 5px;cursor:pointer' onmouseover='this.style.backgroundColor=\"#333\"' onmouseout='this.style.backgroundColor=\"#222\"'><table width='100%'><tr><td width='40' style='padding-right:5px;'><a href='http://www.foursquare.com/venue/"+vid+"' target='_blank'><img src='"+category_image+"' height=32 width=32 border=0></a></td><td width='40' align='center' style='padding-right:5px;'><img src='zoom_icon.png' style='cursor:pointer' onclick='zoomMap()'></td><td><div class='title-text' onclick='window.open(\"http://www.checkinmania.com/foursquare/places/"+vid+"\", \"_blank\")'><span style='font-size:12pt'>"+data.response.venue.name+"</span></div><div class='subtitle-text'>"+category_name+"</div></td></tr></table></div>");
			$("#details").append("<div style='padding:5px;'></div><span>&nbsp;</span>");
			if(data.response.venue.tags){
				for(var i=0;i<data.response.venue.tags.length;i++){
					$("#details").append("<span style='font-size:8pt'> "+data.response.venue.tags[i]+" .</span>");	
				}
			}
			$("#details").append("<div style='padding:5px;'></div>");	
			var tips;
			if(data.response.venue.tips) {
				tips = data.response.venue.tips.count;
			} else {
				tips = 0;
			}
			$("#details").append("<div style='padding:4px;font-size:8pt' align='center'><table cellpadding=0 cellspacing=3 border=0 width='100%'><tr><td align='center'><div style='-webkit-border-radius:5px;-moz-border-radius: 5px;border:5px solid #29c;width:54px;background:#29c'><span style='font-size:18pt;'>"+data.response.venue.stats.checkinsCount+"</span><br><span style='font-size:10pt'>checkins</span></div></td><td align='center'><div style='-webkit-border-radius:5px;-moz-border-radius: 5px;border:5px solid #29c;width:54px;background:#29c'><span style='font-size:18pt;'>"+data.response.venue.hereNow.count+"</span><br><span style='font-size:10pt'>here&nbsp;now</span></div></td><td align='center'><div style='-webkit-border-radius:5px;-moz-border-radius: 5px;border:5px solid #29c;width:54px;background:#29c'><span style='font-size:18pt;'>"+tips+"</span><br><span style='font-size:10pt'>tips</span></div></td></tr></table></div>");
			if(data.response.venue.mayor){
				var lastname = "";
				if(data.response.venue.mayor.user.lastName) { lastname = data.response.venue.mayor.user.lastName;}
				$("#details").append("<div style='padding:4px;font-size:8pt'>Mayor:</div>");
				$("#details").append("<div style='padding:4px;font-size:8pt;background:#29c;-moz-border-radius: 5px;-webkit-border-radius: 5px;cursor:pointer' onmouseover='this.style.backgroundColor=\"#18b\"' onmouseout='this.style.backgroundColor=\"#29c\"'><table cellpadding=0 cellspacing=0 border=0 width='100%'><tr><td width='50' style='padding-right:10px;'><a href='http://www.foursquare.com/user/"+data.response.venue.mayor.user.id+"' target='_blank'><img src='"+data.response.venue.mayor.user.photo+"' height=48 width=48 border=0></a></td><td valign=top><div style='padding:2px;font-size:14pt' onclick='window.open(\"http://www.foursquare.com/user/"+data.response.venue.mayor.user.id+"\", \"_blank\")'><b> "+data.response.venue.mayor.user.firstName+" "+lastname+"</b></div><div style='padding:2px;font-size:8pt'><span style='font-size:14pt'>"+data.response.venue.mayor.count+"</span> chekins</div></td></tr></table></div>");
			}
			if(data.response.venue.tips.groups.length > 0) {
				$("#details").append("<div style='padding:4px;font-size:8pt'>Tips:</div>");
				for(var j=0;j<data.response.venue.tips.groups.length;j++) {
					for(var i=0;i<data.response.venue.tips.groups[j].items.length;i++) {	
						var lastname = "";
						if(data.response.venue.tips.groups[j].items[i].user.lastName) {lastname = data.response.venue.tips.groups[j].items[i].user.lastName;}
						$("#details").append("<div id='user' style='padding:4px;font-size:8pt;border-bottom:1px solid #333'><table cellpadding=0 cellspacing=0 border=0 width='100%'><tr><td width='50' style='padding-right:10px;' valign='top'><a href='http://www.foursquare.com/user/"+data.response.venue.tips.groups[j].items[i].user.id+"' target='_blank'><img src='"+data.response.venue.tips.groups[j].items[i].user.photo+"' height=48 width=48 border=0></a></td><td valign=top><div style='padding:2px;font-size:9pt'><b> "+data.response.venue.tips.groups[j].items[i].user.firstName+" "+lastname+" - </b>"+data.response.venue.tips.groups[j].items[i].text+"</div></td></tr></table></div>");
					}
				}
			}
		}
		clearInterval(loader);
	});
};
 
getGOWVenues = function(lat,lng,isZoomfit){
  busy = 1;
  timeout++;
  if(timeout > 1) {clearInterval(loader);}
  hideDetails();
  $("#sidebar").html("<div style='text-align:center;font-weight:bold;cursor:pointer;font:8pt Arial' onclick='busy=0;this.innerHTML=retry;clearInterval(loader);'><img src='http://www.checkinmania.com/20_loading_icon.gif'><br/>Cancel</div>");
  var url = "http://www.checkinmania.com/jsonp?url=http://api.gowalla.com/spots.json?radius=50%26lat="+lat+"%26lng="+lng+"&callback=?"; 
  $.getJSON(url, function(data) {
	for (var i=0; i<GOWVenues.length; i++) {
		map.removeOverlay(GOWVenues[i].marker());
	} 
	$("#sidebar").html("");
	bounds = new GLatLngBounds();
	bounds.extend(manMarker.getPoint());
  	for(var i=0;i<data.spots.length;i++) {  	
  		if(checkin == 1) {
  			if(data.spots[i].trending_level != 0){
  				GOWVenues.push(new GOWVenue(data.spots[i]));
  			}	
  		} else {
  			GOWVenues.push(new GOWVenue(data.spots[i]));
  		}
	 }
	 if(isZoomfit){zoomFitMarkers();}
	 manMarker.closeInfoWindow();
	 busy = 0;
	 clearInterval(loader);
   });
};
 
GOWVenue = function(result) {
	this.result_ = result;
	map.addOverlay(this.marker());
	return;
};
 
GOWVenue.prototype.marker = function() {
	if (this.marker_) {return this.marker_;}
	iconGOW.image = this.result_.image_url;
	var marker = new google.maps.Marker(new google.maps.LatLng(parseFloat(this.result_.lat), parseFloat(this.result_.lng)), {icon:iconGOW, title:this.result_.name});	
	bounds.extend(new GLatLng(this.result_.lat,this.result_.lng));
	$("#sidebar").append(this.infoWin(1));
	GEvent.bind(marker, "click", this, function() {
		marker.openInfoWindow(this.infoWin(0),{maxWidth:200});
		this.showDetails(this.infoWin(1));
	});	
	this.marker_ = marker;
	return marker;
};	
 
GOWVenue.prototype.infoWin = function(isSidebar) {
	var container = document.createElement("div");
	if(isSidebar){
		container.className = "venue";
	} else {
		container.className = "venue-infowin";
	}	
	var category_name = "";
	var category_image = "";
	if(this.result_.spot_categories){
		if(this.result_.spot_categories[0].name) {
			category_name = this.result_.spot_categories[0].name;
		}
	}	
	if(this.result_.image_url){
		category_image = this.result_.image_url;
	}
	var vidId = this.result_.url.split('/')[2];	
	container.innerHTML = "<table><tr><td style='padding-right:10px;'><img src='"+category_image+"' height=32 width=32></td><td><div class='title-text'>"+this.result_.name+"</div><div class='subtitle-text'>"+category_name+"</div></td></tr></table><div class='clickhere'>details</div>";
  	var moreDetails = "<div style='text-align:center;'><a class='subtitle-text' style='color:#00e' href='http://www.checkinmania.com/gowalla/places/"+this.result_.url.substring(7,this.result_.url.length)+"' target='_blank'>Get More Details</a></div>";
  	if(isSidebar){
      	GEvent.bindDom(container, "mouseover", this, function() {
       	 	this.marker_.openInfoWindow(container.innerHTML + moreDetails,{maxWidth:200});
    		container.className = "venue-hover";
      	});  
      	GEvent.bindDom(container, "mouseout", this, function() {  
    		container.className = "venue";
      	});
      	GEvent.bindDom(container, "click", this, function() {  
    		container.className = "venue";
    		this.showDetails(container);
      	});    
  	} else {
  		container.innerHTML += moreDetails;
  	}
  	return container;
};
 
GOWVenue.prototype.showDetails = function (content) {
	var hover = document.getElementById("sidebar-bottom");
	$("#sidebar").height(230);
	$("#sidebar-bottom").height(270);
	$("#sidebar-bottom").hide();
	$("#sidebar-bottom").html("<div id='details' style='overflow-y:auto;overflow-x:hidden;border:6px solid #e80;height:250px;padding:4px'></div>");
	$("#details").html(content.innerHTML);
    GEvent.bindDom(hover, "mouseover", this, function() {
        this.marker_.openInfoWindow(content.innerHTML,{maxWidth:200});
    });		
	$("#sidebar-bottom").fadeIn('slow');
	timeout = 0;
	getGOWVenueDetails(this.result_.url);
	temp = this.result_.url;
	loader = setInterval(function(){getGOWVenueDetails(temp);}, 6000);
	return;
};
 
getGOWVenueDetails = function(vid){
    timeout++;
    if(timeout > 1) {clearInterval(loader);}
	$("#details").append("<span style='cursor:pointer;font:8pt Arial' onclick='busy=0;this.innerHTML=retry;clearInterval(loader);'><img src='http://www.checkinmania.com/20_loading_icon.gif'> Cancel</span>");
	var url = "http://www.checkinmania.com/jsonp?url=http://api.gowalla.com"+vid+".json&callback=?";
	$.getJSON(url, function(data) {
		var vidId = vid.split('/')[2];
		$("#details").html("<div style='padding:3px;border:2px solid #e80;-moz-border-radius-bottomleft: 5px;-webkit-border-bottom-left-radius: 5px;-moz-border-radius-bottomright: 5px;-webkit-border-bottom-right-radius: 5px;cursor:pointer' onmouseover='this.style.backgroundColor=\"#333\"' onmouseout='this.style.backgroundColor=\"#222\"'><table width='100%'><tr><td width='50' style='padding-right:5px;'><a href='http://www.gowalla.com"+vid+"' target='_blank'><img src='"+data.image_url+"' height=48 width=48 border=0></a></td><td width='40' align='center' style='padding-right:5px;'><img src='zoom_icon.png' style='cursor:pointer' onclick='zoomMap()'></td><td><div class='title-text' onclick='window.open(\"http://www.checkinmania.com/gowalla/places/"+vidId+"\", \"_blank\")'><span style='font-size:12pt'>"+data.name+"</span></div><div class='subtitle-text'>"+data.spot_categories[0].name+"</div></td></tr></table></div>");
		$("#details").append("<div style='padding:4px;font-size:8pt'>"+data.description+"</div>");
		$("#details").append("<div style='padding:4px;font-size:8pt'><table cellpadding=0 cellspacing=3 border=0 width='100%'><tr><td align='center'><div style='-webkit-border-radius:5px;-moz-border-radius: 5px;border:5px solid #e80;width:50px;background:#e80'><span style='font-size:18pt;'>"+data.checkins_count+"</span><br><span style='font-size:10pt'>checkins</span></div></td><td align='center'><div style='-webkit-border-radius:5px;-moz-border-radius: 5px;border:5px solid #e80;width:50px;background:#e80'><span style='font-size:18pt;'>"+data.users_count+"</span><br><span style='font-size:10pt'>users</span></div></td></tr></table></div>");			
		if(data.top_10.length > 0) {
			$("#details").append("<div style='padding:4px;font-size:8pt'>Top Users:</div>");
			$("#details").append("<div style='padding:4px;font-size:8pt;background:#e80;-moz-border-radius: 5px;-webkit-border-radius: 5px;cursor:pointer' onmouseover='this.style.backgroundColor=\"#d60\"' onmouseout='this.style.backgroundColor=\"#e80\"'><table cellpadding=0 cellspacing=3 border=0 width='100%'><tr><td width='50' style='padding-right:10px;' valign='top'><a href='http://www.gowalla.com"+data.top_10[0].url+"' target='_blank'><img src='"+data.top_10[0].image_url+"' height=48 width=48 border=0></a></td><td valign=top><div style='padding:2px;font-size:9pt' onclick='window.open(\"http://www.gowalla.com"+data.top_10[0].url+"\", \"_blank\")'><b> "+data.top_10[0].first_name+" "+data.top_10[0].last_name+"</b></div><div><span style='font-size:14pt'>"+data.top_10[0].checkins_count+" </span>checkins</div></td></tr></table></div>");
			for(var i=1;i<data.top_10.length;i++){
				$("#details").append("<div style='padding:4px;font-size:8pt;border-bottom:1px solid #333;-moz-border-radius: 5px;-webkit-border-radius: 5px;cursor:pointer' onmouseover='this.style.backgroundColor=\"#333\"' onmouseout='this.style.backgroundColor=\"#222\"'><table cellpadding=0 cellspacing=3 border=0 width='100%'><tr><td width='50' style='padding-right:10px;' valign='top'><a href='http://www.gowalla.com"+data.top_10[0].url+"' target='_blank'><img src='"+data.top_10[i].image_url+"' height=48 width=48 border=0></a></td><td valign=top><div style='padding:2px;font-size:9pt' onclick='window.open(\"http://www.gowalla.com"+data.top_10[i].url+"\", \"_blank\")'><b> "+data.top_10[i].first_name+" "+data.top_10[i].last_name+"</b></div><div><span style='font-size:14pt'>"+data.top_10[i].checkins_count+" </span>checkins</div></td></tr></table></div>");
			}
		}
		clearInterval(loader);
	});
};

getBKTVenues = function(lat,lng,isZoomfit){
  busy = 1;
  timeout++;
  if(timeout > 1) {clearInterval(loader);  }
  hideDetails();
  $("#sidebar").html("<div style='text-align:center;font-weight:bold;cursor:pointer;font:8pt Arial' onclick='busy=0;this.innerHTML=retry;clearInterval(loader);'><img src='http://www.checkinmania.com/20_loading_icon.gif'><br/>Cancel</div>");
  var url = "http://www.checkinmania.com/jsonp?url=http://brightkite.com/places.json?clat="+lat+"%26clng="+lng+"&callback=?"; 
  $.getJSON(url, function(data) {
	for (var i=0; i<BKTVenues.length; i++) {
		map.removeOverlay(BKTVenues[i].marker());
	} 
	$("#sidebar").html("");
	bounds = new GLatLngBounds();
	bounds.extend(manMarker.getPoint());
  	for(var i=0;i<data.length;i++) { 
		if(data[i].scope == "address"){
			BKTVenues.push(new BKTVenue(data[i]));
		}
	 }
	 if(isZoomfit) {zoomFitMarkers();}
	 manMarker.closeInfoWindow();
	 busy = 0;
	 clearInterval(loader);
   });		
};
 
BKTVenue = function(result) {
	this.result_ = result;
	map.addOverlay(this.marker());
	return;
};
 
BKTVenue.prototype.marker = function() {
	if (this.marker_) {return this.marker_;}
	iconBKT.image = "brightkite-marker.png";
	var marker = new google.maps.Marker(new google.maps.LatLng(parseFloat(this.result_.latitude), parseFloat(this.result_.longitude)), {icon:iconBKT, title:this.result_.name});	
	bounds.extend(new GLatLng(this.result_.latitude,this.result_.longitude));
	$("#sidebar").append(this.infoWin(1));
	GEvent.bind(marker, "click", this, function() {
		marker.openInfoWindow(this.infoWin(0),{maxWidth:200});
		this.showDetails(this.infoWin(1));
	});	
	this.marker_ = marker;
	return marker;
};	
 
BKTVenue.prototype.infoWin = function(isSidebar) {
	var container = document.createElement("div");
	if(isSidebar) {
		container.className = "venue";
	} else {
		container.className = "venue-infowin";
	}
	var category_name = "";
	var category_image = "brightkite-icon.png";
	if(this.result_.city) {
		category_name = this.result_.city;
	}
	container.innerHTML = "<table><tr><td style='padding-right:10px;'><img src='"+category_image+"' height=32 width=32></td><td><div class='title-text'>"+this.result_.name+"</div><div class='subtitle-text'>"+category_name+"</div></td></tr></table><div class='clickhere'>details</div>";
  	moreDetails = "<div class='subtitle-text' style='text-align:center'><a class='subtitle-text' style='color:#00e' href='http://brightkite.com/places/"+this.result_.id+"' target='_blank'>Get More Details</a></div>";
  	if(isSidebar){
      	GEvent.bindDom(container, "mouseover", this, function() {
        	this.marker_.openInfoWindow(container.innerHTML + moreDetails,{maxWidth:200});
    		container.className = "venue-hover";
      	});  
      	GEvent.bindDom(container, "mouseout", this, function() {  
    		container.className = "venue";
      	});
      	GEvent.bindDom(container, "click", this, function() {  
    		container.className = "venue";
    		this.showDetails(container);
      	});    
  	} else {
      	container.innerHTML += moreDetails;
  	}
  	return container;
};
 
BKTVenue.prototype.showDetails = function (content) {
	var hover = document.getElementById("sidebar-bottom");
	$("#sidebar").height(230);
	$("#sidebar-bottom").height(270);
	$("#sidebar-bottom").hide();
	$("#sidebar-bottom").html("<div id='details' style='overflow-y:auto;overflow-x:hidden;border:6px solid #ad2;height:250px;padding:4px'></div>");
	$("#details").html(content.innerHTML);
    GEvent.bindDom(hover, "mouseover", this, function() {
        this.marker_.openInfoWindow(content.innerHTML,{maxWidth:200});
    });		
	$("#sidebar-bottom").fadeIn('slow');
	timeout = 0;
	getBKTVenueDetails(this.result_.id, this.result_.name, this.result_.city, this.result_.street, this.result_.state, this.result_.country);	
//	loader = setInterval(function(){getBKTVenueDetails(this.result_.id, this.result_.name, this.result_.city, this.result_.street, this.result_.state, this.result_.country);}, 9000);
	return;
};
 
getBKTVenueDetails = function(place_id, place_name, city, address, state, country){
    timeout++;
    if(timeout > 1) {clearInterval(loader);	}
	if(state == null) {state = "";}
	if(address == null) {address = "";}
	if(country == null) {country = "";}
	$("#details").append("<img src='http://www.checkinmania.com/20_loading_icon.gif'>");
	var url = "http://www.checkinmania.com/jsonp?url=http://brightkite.com/places/"+place_id+"/visitors.json&callback=?";
	$.getJSON(url, function(data) {
		$("#details").html("<div style='padding:3px;border:2px solid #ad2;-moz-border-radius-bottomleft: 5px;-webkit-border-bottom-left-radius: 5px;-moz-border-radius-bottomright: 5px;-webkit-border-bottom-right-radius: 5px;cursor:pointer' onmouseover='this.style.backgroundColor=\"#333\"' onmouseout='this.style.backgroundColor=\"#222\"'><table width='100%'><tr><td width='50' style='padding-right:5px;'><a href='http://brightkite.com/places/"+place_id+"' target='_blank'><img src='brightkite-icon.png' height=48 width=48 border=0></a></td><td width='40' align='center' style='padding-right:5px;'><img src='zoom_icon.png' style='cursor:pointer' onclick='zoomMap()'></td><td><div class='title-text' onclick='window.open(\"http://brightkite.com/places/"+place_id+"\", \"_blank\")'><span style='font-size:12pt'>"+place_name+"</span></div><div class='subtitle-text'>"+city+"</div></td></tr></table></div>");
		$("#details").append("<div style='padding:8px;font-size:10pt'>Address:<b><br>"+address+"<br>"+city+", "+state+", "+country+"</b></div>");
		if(data.length != 0) {
			$("#details").append("<div style='padding:4px;font-size:8pt'>Visitors:</div>");
			for(var i=0;i<data.length;i++){
				$("#details").append("<div style='padding:4px;font-size:8pt;border-bottom:1px solid #333;-moz-border-radius: 5px;-webkit-border-radius: 5px;cursor:pointer' onmouseover='this.style.backgroundColor=\"#333\"' onmouseout='this.style.backgroundColor=\"#222\"'><table cellpadding=0 cellspacing=3 border=0 width='100%'><tr><td width='50' style='padding-right:10px;' valign='top'><a href='http://brightkite.com/people/"+data[i].person.login+"' target='_blank'><img src='"+data[i].person.small_avatar_url+"' height=48 width=48 border=0></a></td><td valign=top><div style='padding:2px;font-size:9pt' onclick='window.open(\"http://brightkite.com/people/"+data[i].person.login+"\", \"_blank\")'><b> "+data[i].person.fullname+"</b></div><div><span style='font-size:14pt'>"+data[i].visit_count+" </span>check-ins</div></td></tr></table></div>");
			}
		} else
			$("#details").append("<div style='padding:4px;font-size:8pt'>No visitors here.</div>");
    	clearInterval(loader);		
	});
};


getTWTVenues = function(lat,lng,isZoomfit){
  busy = 1;
  timeout++;
  if(timeout > 1) {clearInterval(loader); }
  hideDetails();
  $("#sidebar").html("<div style='text-align:center;font-weight:bold;cursor:pointer;font:8pt Arial' onclick='busy=0;this.innerHTML=retry;clearInterval(loader);'><img src='http://www.checkinmania.com/20_loading_icon.gif'><br/>Cancel</div>");
  var url = "http://api.twitter.com/1/geo/search.json?granularity=poi&max_results=50&lat="+lat+"&long="+lng+"&callback=?"; 
  $.getJSON(url, function(data) {
	for (var i=0; i<TWTVenues.length; i++) {
		map.removeOverlay(TWTVenues[i].marker());
	} 
	TWTVenues = [];
	$("#sidebar").html("");
	bounds = new GLatLngBounds();
	bounds.extend(manMarker.getPoint());
	if(data.errors){
	 	manMarker.openInfoWindowHtml("<div style='font-size:9pt;color:#888'><br>"+data.errors[0].message+"</div>",{maxWidth:200});	 
	 	busy = 0;
	} else {
  		for(var i=0;i<data.result.places.length;i++) {  	
  			if(data.result.places[i].place_type == "poi"){
	  			TWTVenues.push(new TWTVenue(data.result.places[i]));
	  		}
	 	}
	 	if(isZoomfit) {zoomFitMarkers();}
	 	manMarker.closeInfoWindow();
	 	busy = 0;
	 	if(TWTVenues.length == 0){
	 		manMarker.openInfoWindowHtml("<div style='font-size:9pt;color:#888'><br>No Places available around here<br>(Twitter places available only in US)</div>",{maxWidth:200});
	 	}
	}
	clearInterval(loader);
   });		
};
 
TWTVenue = function(result) {
	this.result_ = result;
	map.addOverlay(this.marker());
	return;
};
 
TWTVenue.prototype.marker = function() {
	if (this.marker_) {return this.marker_;}
	iconTWT.image = "icon_twitter.png";
	var marker = new google.maps.Marker(new google.maps.LatLng(parseFloat(this.result_.bounding_box.coordinates[0][0][1]), parseFloat(this.result_.bounding_box.coordinates[0][0][0])), {icon:iconTWT, title:this.result_.name});	
	bounds.extend(new GLatLng(this.result_.bounding_box.coordinates[0][0][1],this.result_.bounding_box.coordinates[0][0][0]));
	$("#sidebar").append(this.infoWin(1));
	GEvent.bind(marker, "click", this, function() {
		marker.openInfoWindow(this.infoWin(0),{maxWidth:200});
		this.showDetails(this.infoWin(1));
	});	
	this.marker_ = marker;
	return marker;
};

TWTVenue.prototype.infoWin = function(isSidebar) {
	var container = document.createElement("div");
	if(isSidebar){
		container.className = "venue";
	} else {
		container.className = "venue-infowin";
	}
	category_image = "icon_twitter.png";			
	container.innerHTML = "<table><tr><td style='padding-right:10px;'><img src='"+category_image+"' height=32 width=32></td><td><div class='title-text'>"+this.result_.name+"</div><div class='subtitle-text'>"+this.result_.contained_within[0].full_name+"</div></td></tr></table><div class='clickhere'>details</div>";
  	moreDetails = "<div class='subtitle-text' style='text-align:left;padding-left:47px'><a class='subtitle-text' style='color:#00e' href='http://www.checkinmania.com/twitter/places/"+this.result_.id+"' target='_blank'>Get More Details</a></div>";
  	if(isSidebar){
      	GEvent.bindDom(container, "mouseover", this, function() {
        	this.marker_.openInfoWindow(container.innerHTML + moreDetails,{maxWidth:200});
    		container.className = "venue-hover";
      	});  
      	GEvent.bindDom(container, "mouseout", this, function() {  
    		container.className = "venue";
      	});
      	GEvent.bindDom(container, "click", this, function() {  
    		container.className = "venue";
    		this.showDetails(container);
      	});    
  	} else {
  		container.innerHTML += moreDetails;
  	}
  	return container;
};
 
TWTVenue.prototype.showDetails = function (content) {
	var hover = document.getElementById("sidebar-bottom");
	$("#sidebar").height(230);
	$("#sidebar-bottom").height(270);
	$("#sidebar-bottom").hide();
	$("#sidebar-bottom").html("<div id='details' style='overflow-y:auto;overflow-x:hidden;border:6px solid #59c;height:250px;padding:4px'></div>");
	$("#details").html(content.innerHTML);
    GEvent.bindDom(hover, "mouseover", this, function() {
        this.marker_.openInfoWindow(content.innerHTML,{maxWidth:200});
    });		
	$("#sidebar-bottom").fadeIn('slow');
	timeout = 0;
	getTWTVenueDetails(this.result_.id, this.result_.name,this.result_.contained_within[0].full_name, this.result_.attributes.street_address);
//	loader = setInterval(function(){getTWTVenueDetails(this.result_.id, this.result_.name,this.result_.contained_within[0].full_name, this.result_.attributes.street_address);}, 9000);
	return;
};

getTWTVenueDetails = function(place_id, name, city, address){
    timeout++;
    if(timeout > 1) {clearInterval(loader);}
	$("#details").append("<img src='http://www.checkinmania.com/20_loading_icon.gif'>");
	var url = "http://search.twitter.com/search.json?q=place:"+place_id+"&callback=?";
	$.getJSON(url, function(data) {
		$("#details").html("<div style='padding:3px;border:2px solid #59c;-moz-border-radius-bottomleft: 5px;-webkit-border-bottom-left-radius: 5px;-moz-border-radius-bottomright: 5px;-webkit-border-bottom-right-radius: 5px;cursor:pointer' onmouseover='this.style.backgroundColor=\"#333\"' onmouseout='this.style.backgroundColor=\"#222\"'><table width='100%'><tr><td width='50' style='padding-right:5px;'><a href='http://twitter.com/search?q=place:"+place_id+"&format=html' target='_blank'><img src='"+iconTWT.image+"' height=48 width=48 border=0></a></td><td width='40' align='center' style='padding-right:5px;'><img src='zoom_icon.png' style='cursor:pointer' onclick='zoomMap()'></td><td><div class='title-text' onclick='window.open(\"http://www.checkinmania.com/twitter/places/"+place_id+"\", \"_blank\")'><span style='font-size:12pt'>"+name+"</span></div><div class='subtitle-text'>"+city+"</div></td></tr></table></div>");
		$("#details").append("<div style='padding:8px;font-size:10pt'>Address:<b><br>"+address+"<br>"+city+"</b></div>");
		if(data.results.length == 0) {
			$("#details").append("<div style='padding:4px;font-size:8pt'>No Tweets at this place</div>");
		} else {
			$("#details").append("<div style='padding:4px;font-size:8pt'>Tweets:</div>");
			for(var i=0;i<data.results.length;i++){
				$("#details").append("<div style='padding:4px;font-size:8pt;border-bottom:1px solid #333;-moz-border-radius: 5px;-webkit-border-radius: 5px;cursor:pointer' onmouseover='this.style.backgroundColor=\"#333\"' onmouseout='this.style.backgroundColor=\"#222\"'><table cellpadding=0 cellspacing=3 border=0 width='100%'><tr><td width='50' style='padding-right:10px;' valign='top'><a href='http://twitter.com/"+data.results[i].from_user+"' target='_blank'><img src='"+data.results[i].profile_image_url+"' height=48 width=48 border=0></a></td><td valign=top><div style='padding:2px;font-size:9pt' onclick='window.open(\"http://twitter.com/"+data.results[i].from_user+"/status/"+data.results[i].id+"\", \"_blank\")'><b> "+data.results[i].from_user+"</b></div><div onclick='window.open(\"http://twitter.com/"+data.results[i].from_user+"/status/"+data.results[i].id+"\", \"_blank\")'>"+data.results[i].text+"</div></td></tr></table></div>");
			}
		}
    	clearInterval(loader);		
	});
};


toggleService = function(value){
	if(service != value && busy != 1) {
		hideDetails();
		service = value;
		toggleDataType(type);
	}
};
 
toggleDataType = function(value){
    type = value;
	if(service == 0){
		document.getElementById('buttonFSQ').style.background='#29c';
		document.getElementById('buttonGOW').style.background='#333';
		document.getElementById('buttonBKT').style.background='#333';
		document.getElementById('buttonTWT').style.background='#333';
		document.getElementById('sidebar').style.borderColor='#29c';
		document.getElementById('map').style.borderColor='#29c';
		for (var i=0; i<GOWVenues.length; i++) {	
			map.removeOverlay(GOWVenues[i].marker());
		}
		for (var i=0; i<BKTVenues.length; i++) {	
			map.removeOverlay(BKTVenues[i].marker());
		}
		for (var i=0; i<TWTVenues.length; i++) {	
			map.removeOverlay(TWTVenues[i].marker());
		}
		timeout = 0;
		getFSQData(0, 1);
		loader = setInterval(function(){getFSQData(0);}, 6000);		
	} else if(service == 1) {
		document.getElementById('buttonFSQ').style.background='#333';
		document.getElementById('buttonGOW').style.background='#e80';
		document.getElementById('buttonBKT').style.background='#333';
		document.getElementById('buttonTWT').style.background='#333';
		document.getElementById('sidebar').style.borderColor='#e80';
		document.getElementById('map').style.borderColor='#e80';
		for (var i=0; i<FSQVenues.length; i++) {
			map.removeOverlay(FSQVenues[i].marker());
		}
		for (var i=0; i<BKTVenues.length; i++) {	
			map.removeOverlay(BKTVenues[i].marker());
		}
		for (var i=0; i<TWTVenues.length; i++) {	
			map.removeOverlay(TWTVenues[i].marker());
		}
		timeout = 0;
		getGOWVenues(currentPosition.lat(), currentPosition.lng());
		loader = setInterval(function(){getGOWVenues(currentPosition.lat(), currentPosition.lng());}, 6000);
	} else if(service == 2) {
		document.getElementById('buttonFSQ').style.background='#333';
		document.getElementById('buttonGOW').style.background='#333';
		document.getElementById('buttonBKT').style.background='#ad2';
		document.getElementById('buttonTWT').style.background='#333';
		document.getElementById('sidebar').style.borderColor='#ad2';
		document.getElementById('map').style.borderColor='#ad2';
		for (var i=0; i<GOWVenues.length; i++) {
			map.removeOverlay(GOWVenues[i].marker());
		}
		for (var i=0; i<FSQVenues.length; i++) {
			map.removeOverlay(FSQVenues[i].marker());
		}
		for (var i=0; i<TWTVenues.length; i++) {	
			map.removeOverlay(TWTVenues[i].marker());
		}
		timeout = 0;
		getBKTVenues(currentPosition.lat(), currentPosition.lng());
		loader = setInterval(function(){getBKTVenues(currentPosition.lat(), currentPosition.lng());}, 6000);		
	} else if(service == 3) {
		document.getElementById('buttonFSQ').style.background='#333';
		document.getElementById('buttonGOW').style.background='#333';
		document.getElementById('buttonBKT').style.background='#333';
		document.getElementById('buttonTWT').style.background='#59c';
		document.getElementById('sidebar').style.borderColor='#59c';
		document.getElementById('map').style.borderColor='#59c';
		for (var i=0; i<GOWVenues.length; i++) {
			map.removeOverlay(GOWVenues[i].marker());
		}
		for (var i=0; i<FSQVenues.length; i++) {
			map.removeOverlay(FSQVenues[i].marker());
		}
		for (var i=0; i<BKTVenues.length; i++) {	
			map.removeOverlay(BKTVenues[i].marker());
		}
		timeout = 0;
		getTWTVenues(currentPosition.lat(), currentPosition.lng());
		loader = setInterval(function(){getTWTVenues(currentPosition.lat(), currentPosition.lng());}, 6000);				
	}
};
 
changeCity = function() {
	hideDetails();
	if(document.getElementById("where").value != "" || document.getElementById("where").value != "Change City") {
		var geocoder = new GClientGeocoder();
		geocoder.getLatLng(document.getElementById("where").value,function(point) {
			manMarker.setPoint(point);
			map.setCenter(point);
			currentPosition = point;
			getData(0.001);					
		});
	}
	return false;
};
 
zoomMap = function() {
	map.getCurrentMapType().getMaxZoomAtLatLng(map.getCenter(),function(obj){map.setZoom(obj.zoom);});
};
 
zoomFitMarkers = function(){
	var zoomLevel = map.getBoundsZoomLevel(bounds);
	if (zoomLevel > 16) zoomLevel = 16;
	map.setCenter(bounds.getCenter(), zoomLevel);
	return;
};

applyFilter = function() {
	filter = document.getElementById('filter').value;
	getData(0,1);
};
 
myLocation = function() {
	if (navigator.geolocation) {	
		navigator.geolocation.getCurrentPosition(
			function(position){
				currentPosition = new GLatLng(position.coords.latitude,position.coords.longitude);
				manMarker.setPoint(currentPosition);
				map.setCenter(currentPosition);
				getData(0,1);	
			},
			function(){
				if (google.loader.ClientLocation) {
					currentPosition = new GLatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
					manMarker.setPoint(currentPosition);
					map.setCenter(currentPosition);
					getData(0,1);	
				} else {
					manMarker.openInfoWindowHtml('<br><span style="font-size:8pt;color:#888">Sorry, Cannot get your location.</span>');
				}
			},{maximumAge:600000});
	} else 	if (google.loader.ClientLocation) {
		currentPosition = new GLatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
		manMarker.setPoint(currentPosition);
		map.setCenter(currentPosition);
		getData(0,1);	
	} else {
		manMarker.openInfoWindowHtml('<br><span style="font-size:8pt;color:#888">Sorry, Cannot get your location.</span>');
	}
};
 
togglePanSearch = function(){
	if(document.getElementById("panSearch").checked == true){
		$('#buttonMap').hide('slow');
		moveListener = GEvent.addListener(map, 'dragend', function() {
			currentPosition = map.getCenter();
			manMarker.setPoint(currentPosition);
			getData(0);
		});		
	} else {
		if(moveListener) GEvent.removeListener(moveListener);
	}
};

centerSearch = function(){
	$("#buttonMap").fadeOut('slow');
	currentPosition = map.getCenter();
	manMarker.setPoint(currentPosition);
	getData(0);
};
 
getData = function(offset,isZoomfit){
	if(service == 0){
		getFSQData(offset,isZoomfit);
	} else if(service == 1) {
		getGOWVenues(currentPosition.lat(), currentPosition.lng(),isZoomfit);
	} else if(service == 2) {
		getBKTVenues(currentPosition.lat(), currentPosition.lng(),isZoomfit);			
	} else if(service == 3) {
		getTWTVenues(currentPosition.lat(), currentPosition.lng(),isZoomfit);			
	}
};
 
getFSQData = function(offset,isZoomfit){
	if(type == 0) {
		getFSQVenues(currentPosition.lat()+offset, currentPosition.lng(),isZoomfit);
	} else if(type == 1) {
		getFSQTips(currentPosition.lat()+offset, currentPosition.lng(),isZoomfit);		
	} else if(type == 2) {
		getFSQSpecials(currentPosition.lat()+offset, currentPosition.lng(),isZoomfit);		
	}
};
 
hideDetails = function(){
	manMarker.closeInfoWindow();
	$("#sidebar").height(502);
	$("#sidebar-bottom").height(0);
	$("#sidebar-bottom").html("");
	$("#sidebar-bottom").hide();
//	$("#sidebar").hide();
	$("#sidebar").fadeIn('slow');
}
