/******************************************************************************
* Module: custom.js
* Author: Scott Wang
* Email: scott@bmalloc.com
* Web: http://www.bmalloc.com
* Date: July 27, 07
* Purpose: Interact with GOOGLE MAP API
* Modified History: null
*******************************************************************************/
var baseIcon = new GIcon();
baseIcon.shadow = "icons/shadow.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(20, 34);
baseIcon.infoWindowAnchor = new GPoint(20, 34);
baseIcon.infoShadowAnchor = new GPoint(37, 34);
var global_zoom = 6;
var global_center = new GLatLng(49.181238, -124.951205);
var PromoControl = function(url,map) {
this.url_=url;
};
PromoControl.prototype = new GControl(true);
PromoControl.prototype.initialize = function(map) {
var container = document.createElement ("div");
container.innerHTML = '
';
container.style.width = '228px';
container.style.height = '75px';
url = this.url_;
GEvent.addDomListener(container, "click", function () {
document.location = url;
});
map.getContainer().appendChild(container);
return container;
};
PromoControl.prototype.getDefaultPosition = function () {
return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize (70, 15));
};
var load_map_callback = function(t){
var map = new GMap2($('map'));
//add map control, Zoom In, Zoom Out
map.addControl(new GLargeMapControl());
//add map control, satellite, hybird
map.addControl(new GMapTypeControl());
map.setCenter(global_center, global_zoom);
map.addControl(new PromoControl('http://nisa.com/mapping.php'));
/* Create multiple icons */
var listings = eval('(' + t.responseText +')');
for(var i = 0; i < listings.length; i++){
var pos = new GLatLng(listings[i].latitude,listings[i].longitude);
//setting tabs
var tabs = [
$H({'title': listings[i].name,
'contents': '
'
})
];
var infoTabs = new Array();
for(var j = 0; j < tabs.length; j++){
infoTabs[j] = new GInfoWindowTab(tabs[j]['title'],tabs[j]['contents']);
}
map.addOverlay(createMarker(pos, infoTabs, listings[i]));
}
}
function createMarker(point, infoTabs, listing) {
// Create a lettered icon for this point using our icon class
var icon = new GIcon(baseIcon);
// Set Up Icons
if(listing.icon != ''){
icon.image = "icons/" + listing.icon;
}else{
icon.image = "icons/icon.gif";
}
var marker = new GMarker(point, icon);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowTabsHtml(infoTabs);
new Ajax.Updater('tab1', 'get_tab.php', {postBody: 'tab=1&id=' + listing.id});
new Ajax.Updater('tab2', 'get_tab.php', {postBody: 'tab=2&id=' + listing.id});
new Ajax.Updater('tab3', 'get_tab.php', {postBody: 'tab=3&id=' + listing.id});
});
/*
GEvent.addListener(marker, "mouseover", function() {
marker.openInfoWindowTabsHtml(infoTabs);
new Ajax.Updater('tab1', 'get_tab.php', {postBody: 'tab=1&id=' + listing.li});
new Ajax.Updater('tab2', 'get_tab.php', {postBody: 'tab=2&id=' + listing.li});
new Ajax.Updater('tab3', 'get_tab.php', {postBody: 'tab=3&id=' + listing.li});
}); */
return marker;
}
function go(){
var source_addr = document.getElementById('source_addr').value;
var dest_addr = document.getElementById('dest_addr').value;
var url = 'http://maps.google.com/maps?saddr='
+ source_addr + '&daddr=' + dest_addr;
window.open(url);
}
function change_image(direction){
var images = document.getElementsByName('images');
var image_index = parseInt(document.getElementById('image_index').value);
var directions = new Array();
directions['prev'] = -1;
directions['next'] = 1;
image_index += directions[direction];
if(image_index < 1){
image_index = images.length;
}else if(image_index > images.length){
image_index = 1;
}
var image_obj = document.getElementById('image_src');
image_obj.src = images[image_index-1].value;
document.getElementById('image_index').value = image_index + '';
}
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
function set_center(point){
global_zoom = 11;
global_center = point;
}
function load_map(latitude, longitude){
if (GBrowserIsCompatible()) {
var club_city = $('club_city').value;
var weekday = $('weekday').value;
if(latitude & longitude ){
global_zoom = 12;
global_center = new GLatLng(latitude, longitude);
}else if(club_city != '' && club_city != '%'){
var geocoder = new GClientGeocoder();
geocoder.getLatLng(club_city, set_center);
}else{
global_zoom = 6;
global_center = new GLatLng(49.181238, -124.951205);
}
var opt = {
postBody: 'weekday=' + weekday,
onSuccess: load_map_callback
};
$('map').innerHTML = "
";
new Ajax.Request('get_listings.php', opt);
}
}