var d = document; var MPOI = {}; var loader = 'maps_zloader.php'; MPOI['records'] = {}; MPOI['idmap'] = {}; MPOI['last_popup'] = 0; function ylib_Browser() { d=document; this.agt=navigator.userAgent.toLowerCase(); this.major = parseInt(navigator.appVersion); this.dom=(d.getElementById)?1:0; // true for ie6, ns6 this.ns=(d.layers); this.ns4=(this.ns && this.major == 4); this.ns4up=(this.ns && this.major >=4); this.ns6=(this.dom&&navigator.appName=="Netscape"); this.op=(window.opera? 1:0); this.op6= ((this.agt.indexOf("opera 6") > 0) || (this.agt.indexOf("opera/6") > 0)); this.ie=(d.all); this.ie4=(d.all&&!this.dom)?1:0; this.ie4up=(this.ie && this.major >= 4); this.ie5=(d.all&&this.dom && navigator.userAgent.match(/MSIE 5/)); this.ie6=(d.nodeType)? 1:0; this.sf=(this.agt.indexOf("safari")!=-1); this.win=((this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1)); this.mac=(this.agt.indexOf("mac")!=-1); } var oBw = new ylib_Browser(); // this function assumes the inclusion of js/env_detection function mpoi_is_supported() { if (oBw.op) return 0; if (oBw.ns4) return 0; if (oBw.mac && oBw.ie) return 0; if (oBw.dom) return 1; return 0; } // popups function mpoi_mouseout(event) { var record = _mpoi_get_record(event); if (!record) { return false; } var state = record['popup_state']; if (state == 'title') { var icon = record['icon_div']; icon.style.zIndex = 50; var icon_size = 16; if ( record['isize'] ) icon_size = record['isize']; mpoi_set_icon(icon, record['icon'], 'mouseout', icon_size, icon_size, record['x'], record['y']); var popup = record['popup_div']; popup.style.visibility = 'hidden'; popup.style.zIndex = 100; record['popup_state'] = 'closed'; var id = record['id']; oLi = document.getElementById(id); if ( oLi ) { if (oLi.style.backgroundColor == "#d8e6fa"){ oLi.style.backgroundColor = ""; } } } return true; } function mpoi_mouseover(event) { var record = _mpoi_get_record(event); if (!record) { return false; } var state = record['popup_state']; if (!state || state == 'closed') { var icon = record['icon_div']; icon.style.zIndex = 1000; mpoi_set_icon(icon, record['icon'], 'mouseover', 20, 20, record['x'], record['y']); var popup = record['popup_div']; var c = mpoi_make_popup(record, 'title'); _mpoi_set_popup(popup, c); mpoi_position_popup(record); popup.style.zIndex = 1500; record['popup_state'] = 'title'; var id = record['id']; oLi = document.getElementById(id); if ( oLi ) { if (oLi.style.backgroundColor == ""){ oLi.style.backgroundColor = "#d8e6fa"; } else { oLi.style.backgroundColor = ""; } } } return true; } function _mpoi_set_popup(popup, msg) { popup.style.left = '0px'; popup.style.top = '0px'; popup.style.width = '200px'; popup.innerHTML = msg; popup.style.visibility = 'visible'; } function mpoi_onclick(event) { var record = _mpoi_get_record(event); if (!record) { return false; } var state = record['popup_state']; if (state == 'closed' || state == 'title') { var icon = record['icon_div']; icon.style.zIndex = 1000; if(oBw.ie5) record['cat'] = null; //no tracking for ie5, url length issue mpoi_set_icon(icon, record['icon'], 'click', 20, 20, record['x'], record['y'], record['cat']); var popup = record['popup_div']; var c = mpoi_make_popup(record, 'expand'); _mpoi_set_popup(popup, c); mpoi_position_popup(record); popup.style.zIndex = 1100; record['popup_state'] = 'expand'; if (MPOI['last_popup'] != record['id']) { mpoi_close(MPOI['last_popup']); } MPOI['last_popup'] = record['id']; } else if (state == 'expand') { mpoi_close(record['id']); } return true; } function mpoi_expand_popup(id) { var idmap = MPOI['idmap']; if (idmap[id]) { var record =idmap[id]; var icon = record['icon_div']; icon.className = 'mpoiselected'; var popup = record['popup_div']; var c = mpoi_make_popup(record, 'expand'); _mpoi_set_popup(popup, c); mpoi_position_popup(record); record['popup_state'] = 'expand'; } } function mpoi_position_popup(record) { var popup = record['popup_div']; var icon = record['icon_div']; var icon_w = icon.width; var icon_h = icon.height ; var width = popup.offsetWidth; var height = popup.offsetHeight; var image = document.getElementById('map'); var x = parseInt(record['x']); var y = parseInt(record['y']); if ((x + 4 + icon_w/2 + width) >= image.offsetWidth) { x = x - width - icon_w/2 - 2; } else { x = x + 4 + icon_w/2; } if ((y + height) >= image.offsetHeight) { y = (y - height) + icon_h / 2; } else { y = y - icon_h / 2; } popup.style.left = x + 'px'; popup.style.top = y + 'px'; popup.style.zIndex = 1000; } function mpoi_close(id) { var record = MPOI['records'][id]; if (!record) { return false; } var icon = record['icon_div']; icon_size = 16; if (record['isize']) icon_size = record['isize']; mpoi_set_icon(icon, record['icon'], 'mouseout', icon_size, icon_size, record['x'], record['y']); var popup = record['popup_div']; popup.style.visibility = 'hidden'; record['popup_state'] = 'closed'; var id = record['id']; oLi = document.getElementById(id); if ( oLi ) { if (oLi.style.backgroundColor == "#d8e6fa"){ oLi.style.backgroundColor = ""; } } } function _mpoi_get_record(event) { if (!event) { event = window.event; } var src = event.srcElement; if (!src) { src = event.currentTarget; } if (!src) { return; } var idmap = MPOI['idmap']; while (src) { var id = src.id; if (id) { var record = idmap[id]; if (record) { return record; } } src = src.parentNode; } return; } function mpoi_pan(x, y) { // TODO: decouple from mpoi_form name var form = document.getElementById('mpoi_form'); if (x == 0) { x = 1; } if (y == 0) { y = 1; } form.pan_x.value = x; form.pan_y.value = y; return mpoi_update_state(form); } function mpoi_pan_dir(dir) { var form = document.getElementById('mpoi_form'); form.compass.value = dir; return mpoi_update_state(form); } function mpoi_zoom(z) { // TODO: decouple from mpoi_form name var form = document.getElementById('mpoi_form'); if (z == 0 && form.mag.value > 1) { form.mag.value--; } else if (z == 11 && form.mag.value < 10) { form.mag.value++; } else { form.mag.value = z; } return mpoi_update_state(form); } function mpoi_map_click(event) { if (!event) { event = window.event; } var src = event.srcElement; var form = document.getElementById('mpoi_form'); if (!src) { src = event.currentTarget; } if (!src) { return false; } var pan_x; var pan_y; if (event.layerX) { pan_x = event.layerX; pan_y = event.layerY; } else { pan_x = event.offsetX; pan_y = event.offsetY; } var panable; if ( form.panable ) return mpoi_pan(pan_x, pan_y); else return true; } function mpoi_server_update() { var data = mpoi_expand_data(mpoi_fields, mpoi_data); mpoi_clear_points(); for (var i = 0; i < data.length; i++) { var record = data[i]; var id = record['id']; mpoi_add_point(id, record); } } function mpoi_add_point(id, record) { var mpoi_records = MPOI['records']; var mpoi_idmap = MPOI['idmap']; if (mpoi_records[id]) { // duplicate id return; } var container = document.getElementById('mpoi_container'); var x = record['x']; var y = record['y']; var icon = record['icon']; var id = record['id']; var icon_size = 16; if ( record['isize'] ) icon_size = record['isize']; // icon var iconimg = document.createElement('img'); iconimg.width = icon_size; iconimg.height = icon_size; iconimg.border = 0; iconimg.style.position = 'absolute'; iconimg.style.zIndex = '500'; mpoi_set_icon(iconimg, icon, 'mouseout', icon_size, icon_size, x, y); iconimg.onmouseout = mpoi_mouseout; iconimg.onmouseover = mpoi_mouseover; iconimg.onclick = mpoi_onclick; domid = iconimg.id = id + '_icon'; mpoi_idmap[domid] = record; record['icon_div'] = iconimg; container.appendChild(iconimg); // popup var popup = document.createElement('div'); popup.style.position = 'absolute'; popup.style.left = '0px'; popup.style.top = '0px'; popup.style.visibility = 'hidden'; domid = popup.id = id + '_popup'; mpoi_idmap[domid] = record; record['popup_div'] = popup; container.appendChild(popup); mpoi_records[id] = record; mpoi_idmap[id] = record; if (record['state'] && record['state'] == 'expand') { setTimeout('mpoi_expand_popup(' + id + ')', 10); } } function mpoi_set_icon(imgnode, name, state, width, height, x, y, track) { if (!name) return; x = x - width / 2; y = y - height / 2; var url = 'http://us.i1.yimg.com/us.yimg.com/i/us/map/gr/' + name; if (state == 'mouseout') { url += '_s.gif'; } else if (state == 'click') { url += '_r.gif'; } else if (state == 'mouseover') { url += '_c.gif'; } else { // unknown state return; } if (track) { url = 'http://us.rd.yahoo.com/maps/mapresults/mpoi/' + track + '/*' + url; } imgnode.style.left = x + 'px'; imgnode.style.top = y + 'px'; imgnode.style.cursor = 'hand'; imgnode.src = url; imgnode.width = width; imgnode.height = height; } function mpoi_make_el(tag, attrs) { var result = document.createElement(tag); if (attrs) { for (var attr in attrs) { if (attr == 'className') { result.setAttribute('class', attrs[attr]); } result.setAttribute(attr, attrs[attr]); } } return result; } function mpoi_make_popup(record, state) { var c = ''; // should the title be shown? if (state == 'title') { c += '
' + record['title'] + ' | '; c += '
Click icon for more info |