
var compat = GBrowserIsCompatible();
var imgBase = '';
var bounds = new Array();
//bounds['m'] = null;
//bounds['f'] = null;
//bounds['o'] = null;
var markers = new Array();
markers['m'] = new Array();
markers['f'] = new Array();
markers['o'] = new Array();
var labels = new Array();
labels['m'] = new Array();
labels['f'] = new Array();
labels['o'] = new Array();
var groundOverlay = new Array();
groundOverlay['m'] = null;
groundOverlay['f'] = null;
groundOverlay['o'] = null;
var map = new Array();
map['m'] = null;
map['f'] = null;
map['o'] = null;
var bub = null;

if ( compat ) {
	function hood_icon() {
		icon = new GIcon();
		icon.image = imgBase + 'pin_neigh.png';
		icon.shadow = imgBase + 'pin_neigh_shadow.png';
		icon.shadowSize = new GSize(48,36);
		icon.iconSize = new GSize(31,36);
		icon.iconAnchor = new GPoint(15, 35);
		icon.infoWindowAnchor = new GPoint(15, 10);
		return icon;
	}

	function house_icon(colpin,num) {
		icon = new GIcon();
		if ( num > 8 ) num = 'plus';
		icon.image = ''+ imgBase + 'pin_'+ colpin +'_'+ num +'.png';
		icon.shadow = imgBase + 'pin_shadow.png';
		icon.shadowSize = new GSize(43,36);
		icon.iconSize = new GSize(22,36);
		icon.iconAnchor = new GPoint(11, 35);
		icon.infoWindowAnchor = new GPoint(1, 2);
		return icon;
	}

	function type_icon(t) {
		icon = new GIcon();
		icon.image = ''+ imgBase + 'pin_'+ t +'.png';
		//icon.shadow = imgBase + 'pin_shadow.png';
		//icon.shadowSize = new GSize(43,36);
		icon.iconSize = new GSize(22,36);
		icon.iconAnchor = new GPoint(11, 35);
		icon.infoWindowAnchor = new GPoint(1, 2);
		return icon;
	}

	/* Depracated 
	function standardControls() {
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(3, 20)));
	}
	*/
	
	function extraMarker(css,point,content,css_click,content_click,icon,x,y,x_click,y_click) {
		var marker = new GMarker(point, icon);
		if ( content != '' ) {
			if ( bub != null ) {
				if ( content_click != '' ) {
					GEvent.addListener(marker, "click", function() {
						if ( bub.canHide ) {
							bub.oldCenter = map.getCenter();
						}
					
						bub.canHide = true;
						bub.openOnMarker(css_click,marker,x_click,y_click,content_click);
						bub.canHide = false;
						
						p = marker.getPoint();
						pix = map.fromLatLngToDivPixel(p);
						pix.y = pix.y -30;
						map.panTo(map.fromDivPixelToLatLng(pix));
					});
				}
				GEvent.addListener(marker, "mouseover", function() {
					bub.openOnMarker(css,marker,x,y,content);
				});
				GEvent.addListener(marker, "mouseout", function() {
					bub.hide();
				});
			}
		}
		return marker;
	}
	
	function createMarker(css,point,dtlLink,content,css_click,content_click,icon,x,y,id,x_click,y_click,markerNum,type) {
		/*****/
		/*icon = new GIcon();
		icon.image = imgBase + 'pin_neigh.png';
		icon.shadow = imgBase + 'pin_neigh_shadow.png';
		icon.shadowSize = new GSize(48,36);
		icon.iconSize = new GSize(31,36);
		icon.iconAnchor = new GPoint(15, 35);
		icon.infoWindowAnchor = new GPoint(15, 10);
		var opts = {text: "$20k"};
		var marker = new PopupMarker(point, opts);
		//var marker = new PopupMarker(point, icon);*/
		/****/
		/*
		var options = { 
			draggable: true,
			bouncy: false,
			zIndexProcess:orderOfCreation
		};
		var marker = new GMarker(point, options);
		*/
		var marker = new GMarker(point, type_icon('bluedot'));
		//var marker = new GMarker(point, icon);
		marker.num = markerNum;
		marker.mtype = type;
		marker.hoverImage = icon.image;
		
		if ( content != '' ) {
				GEvent.addListener(marker, "click", function() {
					if ( css_click == '' && content_click == '' ) {
								//window.location.href = dtlLink;
							resetMarkers(markerNum,type);
							marker.setImage(marker.hoverImage);
							
							numberPropsPage = 25;
							pagenum = Math.floor( markerNum / numberPropsPage );
							propScroll = (markerNum - (pagenum  * numberPropsPage));
							offset = propScroll *150 + (markerNum - (pagenum  * numberPropsPage));
								
							// interact with region listings by highlighting region when mouse hovers over point
							// page IDs go 0-39, 0-39 etc per page...but maps ids increase sequentionally so we map back
							regionListingId = "rl"+propScroll;
					
							if( document.getElementById( regionListingId ) != null ){
								unHoverListings();  // reset all listings then color the current one
								document.getElementById( regionListingId ).className = "regionlistinghover";
							}
							//scroll to the current property with the scrollbar
							if( document.getElementById( "pane1" ) != null ){
								$('#pane1')[0].scrollTo( offset );
							}
					
					} else {
						/*
						if ( bub.canHide ) {
							bub.oldCenter = map.getCenter();
						}
					
						bub.canHide = true;
						bub.openOnMarker(css_click,marker,x_click,y_click,content_click);
						bub.canHide = false;
						
						p = marker.getPoint();
						pix = map.fromLatLngToDivPixel(p);
						pix.y = pix.y -30;
						map.panTo(map.fromDivPixelToLatLng(pix));
						*/
						displayInfoWindow(places[type],markerNum,type,false)
					}
				});
				GEvent.addListener(marker, "mouseover", function() {
					resetMarkers(markerNum,type);
					marker.setImage(marker.hoverImage);
				});
				GEvent.addListener(marker, "mouseout", function() {
				
				});
		}
		markers[type].push(marker);
		return marker;
	}
	
	function rebound(type) {
		center = bounds[type].getCenter();
		newZoom = map[type].getBoundsZoomLevel(bounds[type]);
		if ( map[type].getZoom() != newZoom ){
			map[type].setCenter(center, newZoom);
		} else {
			map[type].panTo(center);
		}
	}
	
	function reboundMax(type) {
		center = bounds[type].getCenter();
		newZoom = map[type].getBoundsZoomLevel(bounds);
		if ( newZoom > 13 ) {
			newZoom = 13;
		}
		if ( map[type].getZoom() != newZoom ){
			map[type].setCenter(center, newZoom);
		} else {
			map[type].panTo(center);
		}
	}
	
	function recenter(type) {
		center = bounds[type].getCenter();
		map[type].setCenter(center);
	}
	
	function addMarker(css,latitude,longitude,dtlLink,content,css_click,content_click,icon,x,y,id,x_click,y_click,formated_price,type) {
		point = new GLatLng(latitude, longitude);
		if(formated_price)
		{
			// Create the Label
			var dcontents = '<div><div style="background-color:#FBF9DD;font-weight:bold;border:1px black solid;white-space:nowrap;padding:2px;">'+formated_price+'<\/div><\/div>';
			var point_x = get_point_x(formated_price);
			var label=new ELabel(point, dcontents, null, new GSize(point_x,-35), 100);
			var markerNum = labels[type].push(label) - 1;
			map[type].addOverlay(label);
			label.hide();
		}
		
		map[type].addOverlay( createMarker(css,point, dtlLink, content, css_click, content_click, icon,x,y,id,x_click,y_click,markerNum,type) );
		bounds[type].extend(point);
	}
	
	function processLocs(arr, type) {
		for(i = 0; i < arr.length; i++) {
			addMarker(
				arr[i][0],
				arr[i][1],
				arr[i][2],
				arr[i][3],
				arr[i][4],
				arr[i][5],
				arr[i][6],
				arr[i][7],
				arr[i][8],
				arr[i][9],
				arr[i][10],
				arr[i][11],
				arr[i][12],
				arr[i][13],
				type
			);
		}
	}
	
	function findNumId(arr,id) {
		for(i = 0; i < arr.length; i++) {
			if ( arr[i][10] == id ) {
				return i;
			}
		}
		return -1;
	}
	
	/* Where is this Used? Should it be depricated? */
	function displayListingInfoWindow(arr,id) {
		num = findNumId(arr,id);
		if ( num > -1 ) {
			if ( bub != null ) {
				bub.openOnMarker(arr[num][0],markers[type][num],arr[num][8],arr[num][9],arr[num][4]);
			} else {
				markers[type][num].openInfoWindowHtml(arr[num][3]);
			}
		}
	}
	
	function displayInfoWindow(arr,num,type,zoomit) {
	
		resetMarkers(num,type);
		if(zoomit) {
			var point = new GLatLng(arr[num][1], arr[num][2]);
			map[type].setCenter(point, 14);
			//map[type].setZoom(14);
		}
		var preview = map[type]['proppreview'];
		var id = type+arr[num][10];
		//alert( "num="+num+", id="+id +", type="+type+", arr="+'Comentoffarr');
		if($(preview).attr('id') != id) {
			// for now do not display tabs
			//$(preview).html(arr[num][4]);
			//$(preview).attr('id',id);
			// setupAjaxTabs();
		}
		if($(preview).hasClass('hide')) $(preview).toggleClass('hide');
		/*
		if ( bub != null ) {
			bub.openOnMarker(arr[num][0],markers[type][num],arr[num][8],arr[num][9],arr[num][4]);
			p = markers[type][num].getPoint();
			if ( bub.canHide ) {
				bub.oldCenter = map[type].getCenter();
			}
			map[type].panTo(p);
		} else {
			markers[type][num].openInfoWindowHtml(arr[num][3]);
		}
		*/
		markers[type][num].setImage(markers[type][num].hoverImage);
		//alert( labels[type][num] );
		labels[type][num].show();
	}
	
	function hideInfoWindow(arr,num,type) {
		var preview = map[type]['proppreview'];
		$(preview).toggleClass('hide');
		/*
		if ( bub != null ) {
			bub.hide();
		} else {
			markers[type][num].closeInfoWindow();
		}
		*/
	}
	function resetMarkers(num,type) {
		for(i=0;i<markers[type].length;i++) {
			if(i != num) {
				markers[type][i].setImage(markers[type][i].getIcon().image);
				labels[type][i].hide();
			} else {
				labels[type][i].show();
			}
		}
	}
	function closeMyWindow(num,type) {
		var preview = map[type]['proppreview'];
		$(preview).toggleClass('hide');
		markers[type][num].setImage(markers[type][num].getIcon().image);
		labels[type][num].hide()
	}
	function standardDetailContent(address,cityStateZip,description,dtlLink,mls_id,office_name,num_photos,main_image,price,beds,baths,sqft,year) {
		retstr = [];
		retstr.push('<div class="click_results"><a onclick="bub.closeCenter()"><img class="close_click_results" src="');
		retstr.push(imgBase);
		retstr.push('close_click_results.gif" alt="close" /></a><div class="clear"></div><div class="click_results_details"><address>');
		retstr.push(address);
		retstr.push('<br /><span>');
		retstr.push(cityStateZip);
		retstr.push('</span></address><p>');
		retstr.push(description);
		retstr.push('<a href="');
		retstr.push(dtlLink);
		retstr.push('"><img class="more_click_results" src="');
		retstr.push(imgBase);
		retstr.push('more_click_results.gif" alt="More" /></a></p><div class="clear"></div><div class="click_mls">MLS# ');
		retstr.push(mls_id);
		retstr.push('</div><div class="click_broker">By: ');
		retstr.push(office_name);
		retstr.push('</div><a class="click_photo_num"><div class="click_photo_num_text">');
		retstr.push(num_photos);
		retstr.push('</div></a><a href="');
		retstr.push(dtlLink);
		retstr.push('"><img class="button_click_details" src="');
		retstr.push(imgBase);
		retstr.push('button_click_details.gif" alt="Full Details" /><img class="button_click_photos" src="');
		retstr.push(imgBase);
		retstr.push('button_click_photos.gif" alt="More Photos" /></a></div><div class="click_results_photo_price"><div class="click_results_photo"><a href="');
		retstr.push(dtlLink);
		retstr.push('"><img src="');
		retstr.push(main_image);
		retstr.push('" alt="" /><div class="frame_click_results_photo"></div></a><div class="click_results_price">$');
		retstr.push(price);
		retstr.push('</div></div></div><div class="click_results_stats"><div class="click_stats_beds">');
		retstr.push(beds);
		retstr.push('</div><div class="click_stats_baths">');
		retstr.push(baths);
		retstr.push('</div><div class="click_stats_sqft">');
		retstr.push(sqft);
		retstr.push('</div><div class="click_stats_year">');
		retstr.push(year);
		retstr.push('</div></div></div>');
		
		return retstr.join('');
	}
	
	function standardContent(imgSrc,address,broker,dtlLink,dtlImage,price,beds,baths,sqr_feet,lsize,id,listingType,num) {
		retstr = [];
		retstr.push('<div class="top"><h2>Property Preview');
		retstr.push('<img width="16" height="16" alt="collapse" src="'+imgBase+'collapse-close-icon.gif" class="closemapdetail" style="display: block;" onclick="closeMyWindow('+num+',\''+listingType+'\');" /></h2></div>');
		retstr.push('<div class="inner ajaxtabs"><ul class="tab-navigation">');
		
		/*
		retstr.push('<li class="tab-one"><a id="iddetails-'+listingType+id+'">Details</a></li>');
		if(listingType != 'f')
			retstr.push('<li class="tab-two"><a id="idphotos-'+listingType+id+'">Photos</a></li>');
		*/
		if(listingType != 'f'){
			retstr.push('<li class="tab-one"><a id="idphotos-'+listingType+id+'">Photos</a></li>');
			retstr.push('<li class="tab-two"><a id="iddetails-'+listingType+id+'">Details</a></li>');
		}else{
			retstr.push('<li class="tab-one"><a id="iddetails-'+listingType+id+'">Details</a></li>');
		}
			
		//retstr.push('<li class="tab-three"><a id="idcontact-'+listingType+id+'">Contact Agent</a></li>');
		retstr.push('</ul>');
		retstr.push('<div class="tab" id="details-'+listingType+id+'">');
		retstr.push('<a href="'+dtlLink+'"><address>');
		retstr.push(address);
		retstr.push('</address></a>');
		retstr.push('<div class="orange">$');
		retstr.push(price);
		retstr.push('</div>');
		if(listingType != 'o') {
			retstr.push('By: ');
			retstr.push(broker);
			retstr.push('<br />');
		}
		retstr.push('<div class="green">');
		retstr.push(beds);
		retstr.push(' Beds / ');
		retstr.push(baths);
		retstr.push(' Baths </div>');
		retstr.push(sqr_feet);
		retstr.push(' sq. ft');
		
		retstr.push('<input type="hidden" id="url_propertydetail" value="'+dtlLink+'" />');
		retstr.push('</div>');
		
		if(listingType!='f') {
			retstr.push('<div class="tab" id="photos-'+listingType+id+'">');
			retstr.push('</div>');
		}
		
		retstr.push('<div class="tab" id="contact-'+listingType+id+'">');
		retstr.push('</div>');

		retstr.push('</div>');
		
		return retstr.join('');
	}
	
	function standardNeighborhood(hood,city,state,homes,avg_home,link,dtlImage) {
		retstr = [];
		retstr.push('<h4>');
		retstr.push(hood);
		retstr.push('</h4><span>');
		retstr.push(city);
		retstr.push(', ');
		retstr.push(state);
		retstr.push('</span><div class="clear"></div><div class="over_tot_homes">');
		retstr.push(homes);
		retstr.push('</div><div class="over_avg_price">$');
		retstr.push(avg_home);
		retstr.push('</div><a class="button_view_neigh" href="');
		retstr.push(link);
		retstr.push('"><img src="');
		retstr.push(dtlImage);
		retstr.push('" alt="View Neighborhood" /></a>');
		return retstr.join('');
	}

	function mapInit(id,type) {
		map[type] = new GMap2( document.getElementById(id) );
		bounds[type] = new GLatLngBounds();
		map[type]['proppreview'] = $('#'+id).parent().children().filter('div.collapse-container-narrow-tabs');
	}
}
  function initialPosition(type)
  {
   var span = bounds[type].toSpan();
   var newSW = new GLatLng(bounds[type].getSouthWest().lat() + span.lat()/5, 
                           bounds[type].getSouthWest().lng() + span.lng()/5);
   var newNE = new GLatLng(bounds[type].getNorthEast().lat() - span.lat()/5, 
                           bounds[type].getNorthEast().lng() - span.lng()/5);

   var newBounds = new GLatLngBounds(newSW, newNE) ;
   GEvent.addListener(map[type], 'zoomend', function() { updateHoodBoundaries(type); });
   GEvent.addListener(map[type], 'moveend', function() { updateHoodBoundaries(type); });
  }

  function updateHoodBoundaries(type)
  {
	bounds[type] = map[type].getBounds();
  	if($('#showhoods'+type).is(':checked')) {
		if (groundOverlay[type]) {
			map[type].removeOverlay(groundOverlay[type]);
		}
		groundOverlay[type] = new ProjectedOverlay ( "/boundaries.php?SW=" + bounds[type].getSouthWest().toUrlValue() + "&NE=" + bounds[type].getNorthEast().toUrlValue() + "&R=" + Math.random().toFixed(4), new GLatLngBounds(bounds[type].getSouthWest(), bounds[type].getNorthEast()), '&ZOOM=', 'bound'+type);
		map[type].addOverlay(groundOverlay[type]);
  	} else {
		if (groundOverlay[type]) {
			map[type].removeOverlay(groundOverlay[type]);
		}
  	}
  }



function mapLoading() {
	div_map = document.getElementById('map');
	d = document.createElement('div');
	d.id = 'page_overlay';
	d.style.display = 'none';
	d.innerHTML = '<div id="loadingBox"><img src="'+imgBase+'loading.gif" /><br />loading</div>';
	div_map.appendChild(d);
}

function mapSuggest() {
	div_map = document.getElementById('map');
	d = document.createElement('div');
	d.id = 'suggest_location';
	d.style.display = 'none';
	d.innerHTML = '<img id="suggest_title" src="'+imgBase+'suggest_title.jpg" /><a href="javascript:hideDiv(\'suggest_location\');"><img id="suggest_close" src="'+imgBase+'suggest_close.jpg" /></a><div style="clear: both;"></div><img id="suggest_head" src="'+imgBase+'suggest_head.jpg" /><div style="clear: both;"></div><div id="suggest_items"></div>';
	div_map.appendChild(d);
}

function suggestContent(content) {
	document.getElementById('suggest_items').innerHTML = content;
}

function pageOverlay(m_div_id,on) {
	div_map = document.getElementById(m_div_id);
	objOverlay = document.getElementById('page_overlay');

	if ( objOverlay && div_map ) {
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = '0';
		objOverlay.style.left = '0';
		objOverlay.style.zIndex = '995';
	 	objOverlay.style.width = '100%';
	 	objOverlay.style.height = '100%';
		
		if ( ! on ) {
			objOverlay.style.display = 'none';
			objOverlay.style.visibility = 'hidden';
		} else if ( on ) {
			objOverlay.style.display = 'block';
			objOverlay.style.visibility = 'visible';
		}
		
	}
}

function messageOverlay(m_div_id,on) {
	div_map = document.getElementById(m_div_id);
	d = document.createElement('div');
	d.id = 'message_overlay';
	d.innerHTML = '';
	
	d.style.position = 'absolute';
	d.style.top = '0';
	d.style.left = '0';
	d.style.zIndex = '999';
 	d.style.width = '100%';
 	
	div_map.appendChild(d);
}

var current_messages = new Array();
function displayMessageOverlay(m) {
	m_overlay = document.getElementById('message_overlay');
	if ( m_overlay ) {
		d = document.createElement('div');
		d.className = 'message_overlay_text';
		d.id = current_messages.length;
	}
}





/** 
	this is addition to this file
	added by DPR
*/

function get_point_x(formated_price)
{
	var point_x;
	if(formated_price.length==5)
		point_x = -18;
	else if(formated_price.length==6)
		point_x = -20;
	else if(formated_price.length==7)
		point_x = -22;
	else if(formated_price.length==8)
		point_x = -24;
	else
		point_x = -15;
	
	return point_x;
}
// ELabel.js 
//
//   This Javascript is provided by Mike Williams
//   Blackpool Community Church Javascript Team
//   http://www.blackpoolchurch.org/
//   http://econym.org.uk/gmap/
//
//   This work is licenced under a Creative Commons Licence
//   http://creativecommons.org/licenses/by/2.0/uk/
//
// Version 0.2      the .copy() parameters were wrong
// version 1.0      added .show() .hide() .setContents() .setPoint() .setOpacity() .overlap
// version 1.1      Works with GMarkerManager in v2.67, v2.68, v2.69, v2.70 and v2.71
// version 1.2      Works with GMarkerManager in v2.72, v2.73, v2.74 and v2.75
// version 1.3      add .isHidden()
// version 1.4      permit .hide and .show to be used before addOverlay()
// version 1.5      fix positioning bug while label is hidden
// version 1.6      added .supportsHide()
// version 1.7      fix .supportsHide()
// version 1.8      remove the old GMarkerManager support due to clashes with v2.143


function ELabel(point, html, classname, pixelOffset, percentOpacity, overlap) {
// Mandatory parameters
this.point = point;
this.html = html;

// Optional parameters
this.classname = classname||"";
this.pixelOffset = pixelOffset||new GSize(0,0);
if (percentOpacity) {
  if(percentOpacity<0){percentOpacity=0;}
  if(percentOpacity>100){percentOpacity=100;}
}        
this.percentOpacity = percentOpacity;
this.overlap=overlap||false;
this.hidden = false;
} 

ELabel.prototype = new GOverlay();

ELabel.prototype.initialize = function(map) {
var div = document.createElement("div");
div.style.position = "absolute";
div.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>' ;
map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div);
this.map_ = map;
this.div_ = div;
if (this.percentOpacity) {        
  if(typeof(div.style.filter)=='string'){div.style.filter='alpha(opacity:'+this.percentOpacity+')';}
  if(typeof(div.style.KHTMLOpacity)=='string'){div.style.KHTMLOpacity=this.percentOpacity/100;}
  if(typeof(div.style.MozOpacity)=='string'){div.style.MozOpacity=this.percentOpacity/100;}
  if(typeof(div.style.opacity)=='string'){div.style.opacity=this.percentOpacity/100;}
}
if (this.overlap) {
  var z = GOverlay.getZIndex(this.point.lat());
  this.div_.style.zIndex = z;
}
if (this.hidden) {
  this.hide();
}
}

ELabel.prototype.remove = function() {
this.div_.parentNode.removeChild(this.div_);
}

ELabel.prototype.copy = function() {
return new ELabel(this.point, this.html, this.classname, this.pixelOffset, this.percentOpacity, this.overlap);
}

ELabel.prototype.redraw = function(force) {
var p = this.map_.fromLatLngToDivPixel(this.point);
var h = parseInt(this.div_.clientHeight);
this.div_.style.left = (p.x + this.pixelOffset.width) + "px";
this.div_.style.top = (p.y +this.pixelOffset.height - h) + "px";
}

ELabel.prototype.show = function() {
if (this.div_) {
  this.div_.style.display="";
  this.redraw();
}
this.hidden = false;
}

ELabel.prototype.hide = function() {
if (this.div_) {
  this.div_.style.display="none";
}
this.hidden = true;
}

ELabel.prototype.isHidden = function() {
return this.hidden;
}

ELabel.prototype.supportsHide = function() {
return true;
}

ELabel.prototype.setContents = function(html) {
this.html = html;
this.div_.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>' ;
this.redraw(true);
}

ELabel.prototype.setPoint = function(point) {
this.point = point;
if (this.overlap) {
  var z = GOverlay.getZIndex(this.point.lat());
  this.div_.style.zIndex = z;
}
this.redraw(true);
}

ELabel.prototype.setOpacity = function(percentOpacity) {
if (percentOpacity) {
  if(percentOpacity<0){percentOpacity=0;}
  if(percentOpacity>100){percentOpacity=100;}
}        
this.percentOpacity = percentOpacity;
if (this.percentOpacity) {        
  if(typeof(this.div_.style.filter)=='string'){this.div_.style.filter='alpha(opacity:'+this.percentOpacity+')';}
  if(typeof(this.div_.style.KHTMLOpacity)=='string'){this.div_.style.KHTMLOpacity=this.percentOpacity/100;}
  if(typeof(this.div_.style.MozOpacity)=='string'){this.div_.style.MozOpacity=this.percentOpacity/100;}
  if(typeof(this.div_.style.opacity)=='string'){this.div_.style.opacity=this.percentOpacity/100;}
}
}

ELabel.prototype.getPoint = function() {
return this.point;
}

	
	function mBubble(map,map_div_id) {
		this.map = map;
		this.map_div_id = map_div_id;
		this.visible = false;
		this.canHide = true;
		this.oldCenter = 0;
	}

	mBubble.prototype = new GOverlay();

	mBubble.prototype.initialize = function(map) {
		var div = document.createElement("div");
		//map.getPane(G_MAP_MARKER_MOUSE_TARGET_PANE).appendChild(div);
		document.getElementById(this.map_div_id).appendChild(div);
		this.div = div;
		this.hide();
	}

	mBubble.prototype.openOnMap = function(css, point, x, y, html) {
		if ( this.canHide ) {
			this.offsetX = x;
			this.offsetY = y;
			this.point = point;
			
			this.div.className = css;
			this.div.innerHTML = html;
			this.div.style.zIndex = 999; //GOverlay.getZIndex(this.point.lat());

			this.show();
			this.redraw(true);
		}
	}

	mBubble.prototype.openOnMarker = function(css,marker,x,y,html) {
		if ( this.canHide ) {
			this.openOnMap(css,marker.getPoint(), x, y, html);
		}
	}


	mBubble.prototype.redraw = function(force) {
		if (!this.visible) {return;}
		var cloc = this.map.fromContainerPixelToLatLng(new GPoint(0,0), true);
		var clocPixel = this.map.fromLatLngToDivPixel(cloc);
		
		var p = map.fromLatLngToDivPixel(this.point);
		this.div.style.left   = ( p.x - clocPixel.x + this.offsetX  ) + "px";
		this.div.style.top = ( p.y - clocPixel.y + this.offsetY ) + "px";
	}

	mBubble.prototype.remove = function() {
		this.canHide = true;
		this.hide();
		this.div.parentNode.removeChild(this.div);
	}

	mBubble.prototype.copy = function() { return new EWindow(this.map, this.css);
	}

	mBubble.prototype.show = function() {
		this.div.style.display = '';
		this.visible = true;
	}

	mBubble.prototype.hide = function() {
		if ( this.canHide ) {
			this.div.style.display = 'none';
			this.visible = false;
		}
	}

	mBubble.prototype.close = function() {
		this.canHide = true;
		this.hide();
	}

	mBubble.prototype.closeCenter = function() {
		this.close();
		map.panTo( this.oldCenter );
	}

	mBubble.prototype.isHidden = function() {return !this.visible;}
	mBubble.prototype.supportsHide = function() {return true;}


addEvent = function(o, e, f, s){
	var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
	r[r.length] = [f, s || o], o[e] = function(e){
		try{
			(e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			e.target || (e.target = e.srcElement || null);
			e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		}catch(f){}
		for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
		return e = null, !!d;
    }
};
removeEvent = function(o, e, f, s){
	for(var i = (e = o["_on" + e] || []).length; i;)
		if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
			return delete e[i];
	return false;
};

ToolTip = function(o, t, c, f){
	var i, $ = this;
	$.s = ($.o = document.createElement("div")).style;
	$.s.display = "none", $.s.position = "absolute", $.o.className = c, $.t = t, $.f = f;
	for(i in {mouseout: 0, mouseover: 0, mousemove: 0})
		addEvent(o, i, function(e){$[e.type](e);});
};
with({p: ToolTip.prototype}){
	p.update = function(e){
		var w = window, b = document.body;
		this.s.top = e.clientY + (w.scrollY || b.scrollTop || b.parentNode.scrollTop || 0) + "px",
		this.s.left = e.clientX + (w.scrollX || b.scrollLeft || b.parentNode.scrollLeft || 0) + "px";
	}
	p.mouseout = function(){
		this.s.display = "none";
	};
	p.mouseover = function(e){
		document.body.appendChild(this.o).innerHTML = this.t,
		e.stopPropagation(), this.update(e), this.s.display = "block";
	};
	p.mousemove = function(e){
		this.f && this.update(e);
	};
	p.setContent = function(s){
		this.o.innerHTML = this.t = s;
	};
}
function get_tool_tip(meEle, varImg)
{
	var t = new ToolTip(document.getElementById(meEle), "<img src='" + varImg + "'>", "toolTip", true);
}

(function($){
	/*----------------------------------------------------------------------------------
	Class: FloatObject
	-------------------------------------------------------------------------------------*/
		function FloatObject(jqObj, params)
		{
			this.jqObj = jqObj;
			
			switch(params.speed)
			{
				case 'fast': this.steps = 5; break;
				case 'normal': this.steps = 10; break;
				case 'slow': this.steps = 20; break;
				default: this.steps = 10;
			};
			
			var offset = this.jqObj.offset();
			
			this.currentX = 0;//offset.left;
			this.currentY = 0;//offset.top;
			this.minY = offset.top;
			this.maxY = this.jqObj.parent().parent().height() - (this.jqObj.height() + 100);
			
			this.origX = typeof(params.x) == "string" ?  this.currentX : params.x;
			this.origY = typeof(params.y) == "string" ?  this.currentY : params.y;
			//if( params.y) this.origY = params.y;
			
			
			//now we make sure the object is in absolute positions.
			this.jqObj.css({'position':'relative' , 'top':this.currentY ,'left':this.currentX});
		}
		
		FloatObject.prototype.updateLocation = function()
		{
			this.maxY = this.jqObj.parent().parent().height() - (this.jqObj.height() + 100);

			this.updatedX = $(window).scrollLeft() + this.origX;
			this.updatedY = $(window).scrollTop()+ this.origY - this.minY;
			
			this.dx = Math.abs(this.updatedX - this.currentX );
			this.dy = Math.abs(this.updatedY - this.currentY );
			if(this.updatedY < 0 && this.dy <= Math.abs(this.updatedY) ) this.dy = 0;
			//console.log(this.jqObj.attr('id') + ' x: '+this.dx + ' y: '+this.dy + ' upY: '+this.updatedY + ' cur: '+this.currentY + ' miny: '+this.minY + ' maxY: '+ this.maxY);
			return this.dx || this.dy;
		}
		
		FloatObject.prototype.move = function()
		{
			if( this.jqObj.css("position") != "relative" ) return;
			if(this.jqObj.is(':visible')) {
				var cx = 0;
				var cy = 0;
				
				if( this.dx > 0 )
				{			
					if( this.dx < this.steps / 2 )
						cx = (this.dx >= 1) ? 1 : 0;
					else
						cx = Math.round(this.dx/this.steps);
					
					if( this.currentX < this.updatedX )
						this.currentX += cx;
					else
						this.currentX -= cx;
				}
				
				if( this.dy > 0 )
				{
					if( this.dy < this.steps / 2 )
						cy = (this.dy >= 1) ? 1 : 0;
					else
						cy = Math.round(this.dy/this.steps);
					
					if( this.currentY < this.updatedY )
						this.currentY += cy;
					else
						this.currentY -= cy;
				}
			//console.log(this.jqObj.attr('id') + ' curY: '+this.currentY + ' miny: '+this.minY + ' maxY: '+ this.maxY + ' x: '+this.dx + ' y: '+this.dy);
		
				if(this.currentY < 0) this.currentY = 0;
				if(this.currentY > this.maxY) this.currentY = this.maxY;
				
				this.jqObj.css({'left':this.currentX, 'top': this.currentY });
			}
		}

		
		
	/*----------------------------------------------------------------------------------
	Object: floatMgr
	-------------------------------------------------------------------------------------*/		
		$.floatMgr = {
			
			FOArray: new Array() ,
			
			timer: null ,
			
			initializeFO: function(jqObj,params) 
			{
				var settings =  $.extend({
					x: 0 ,
					y: 0 ,
					minY: 0,
					maxY: 0,
					speed: 'normal'	},params||{});
				var newFO = new FloatObject(jqObj,settings);
				
				$.floatMgr.FOArray.push(newFO);
				
				if( !$.floatMgr.timer ) $.floatMgr.adjustFO();
				
				//now making sure we are registered to all required window events
				if( !$.floatMgr.registeredEvents ) 
				{
						$(window).bind("resize", $.floatMgr.onChange);
						$(window).bind("scroll", $.floatMgr.onChange);
						$.floatMgr.registeredEvents = true;
				}		
			}, 
			
			adjustFO: function() 
			{
				$.floatMgr.timer = null;
				
				var moveFO = false;
				
				for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
				{
					 FO = $.floatMgr.FOArray[i];
					 if( FO.updateLocation() )  moveFO = true;
				}
				
				if( moveFO )
				{
					for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
					{
						FO = $.floatMgr.FOArray[i];
						FO.move();
					}
					
					if( !$.floatMgr.timer ) $.floatMgr.timer = setTimeout($.floatMgr.adjustFO,50);
				}
			},
			
			onChange: function()
			{
				if( !$.floatMgr.timer ) $.floatMgr.adjustFO();
			},
			
			removeObj: function(rjqObj)
			{
				for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
				{
					 FO = $.floatMgr.FOArray[i];
					 if( $(FO.jqObj).attr('id') == $(rjqObj).attr('id') )  {
					 	$.floatMgr.FOArray.splice(i,1);
					 	$(FO.jqObj).animate({'left': FO.origX,'top': FO.origY });

					 }
				}
			},
			isFloater: function(fjqObj)
			{
				for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
				{
					 FO = $.floatMgr.FOArray[i];
					 if( $(FO.jqObj).attr('id') == $(fjqObj).attr('id') )  {
					 	return true;
					 }
				}
				return false;
			}
		};
		
	/*----------------------------------------------------------------------------------
	Function: makeFloat
	-------------------------------------------------------------------------------------*/		
		$.fn.makeFloat = function(params) {
			var obj = this.eq(0); //we only operate on the first selected object;
			$.floatMgr.initializeFO(obj,params); 
			if( $.floatMgr.timer == null ) $.floatMgr.adjustFO();
			return obj;
		};
		$.fn.deFloat = function() {
			var obj = this.eq(0); //we only operate on the first selected object;
			$.floatMgr.removeObj(obj); 
			return obj;
		};
		$.fn.isFloater = function() {
			var obj = this.eq(0); //we only operate on the first selected object;
			return $.floatMgr.isFloater(obj); 
		};
	})(jQuery);


//Create an overlay on the map from a projected image...
//Author. John D. Coryat 01/2008
//USNaviguide LLC - http://www.usnaviguide.com
//Thanks go to Mile Williams EInsert: http://econym.googlepages.com/einsert.js, Google's GOverlay Example and Bratliff's suggestion...
//Opacity code from TPhoto: http://gmaps.tommangan.us/addtphoto.html
//This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
//Parameters: 
// imageUrl: URL of the image
// bounds: Bounds object of image destination
// addZoom: Added Zoom factor as a parameter to the imageUrl (include complete parameter, including separater like '?zoom='
//
	
function ProjectedOverlay(imageUrl, bounds, addZoom, id)
{
this.url_ = imageUrl ;
this.bounds_ = bounds ;
this.addZ_ = addZoom ;				// Add the zoom to the image as a parameter
this.id = id
// Is this IE, if so we need to use AlphaImageLoader

this.ie = false ;
var agent = navigator.userAgent.toLowerCase();
if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1))
{
this.ie = true ;
}
}

ProjectedOverlay.prototype = new GOverlay();

ProjectedOverlay.prototype.initialize = function(map)
{
var div = document.createElement("div") ;
div.style.position = "absolute" ;
div.setAttribute('id',this.id) ;
map.getPane(G_MAP_MAP_PANE).appendChild(div) ;
this.map_ = map ;
this.div_ = div ;
if( this.percentOpacity )
{
this.setOpacity(this.percentOpacity) ;
} else {
this.setOpacity(50) ;
}
}

//Remove the main DIV from the map pane

ProjectedOverlay.prototype.remove = function()
{
this.div_.parentNode.removeChild(this.div_);
delete(this.map) ;
delete(this.div) ;
}

//Copy our data to a new ProjectedOverlay...

ProjectedOverlay.prototype.copy = function()
{
return new ProjectedOverlay(this.url_, this.bounds_, this.addZ_);
}

//Redraw based on the current projection and zoom level...

ProjectedOverlay.prototype.redraw = function(force)
{
// We only need to redraw if the coordinate system has changed
if (!force)
{
return ;
}

var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());

// Now position our DIV based on the DIV coordinates of our bounds

this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
this.div_.style.height = Math.abs(c2.y - c1.y) + "px";
this.div_.style.left = Math.min(c2.x, c1.x) + "px";
this.div_.style.top = Math.min(c2.y, c1.y) + "px";

var url = this.url_ ;
var extn = url.substring(url.length - 4, 4) ;

if ( this.addZ_ )
{
url += this.addZ_ + this.map_.getZoom() ;
}

if (this.ie && extn.toLowerCase() == '.png')
{
var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod='scale');" ;
this.div_.innerHTML = '<div style="height:' + this.div_.style.height + 'px; width:' + this.div_.style.width + 'px; ' + loader + '" id="'+this.id+'" ></div>' ;
} else
{
this.div_.innerHTML = '<img src="' + url + '"  width=' + this.div_.style.width + ' height=' + this.div_.style.height + '  id="'+this.id+'">' ;
}
}

ProjectedOverlay.prototype.setOpacity=function(opacity)
{
if (opacity < 0)
{
opacity = 0 ;
}
if(opacity > 100)
{
opacity = 100 ;
}
var c = opacity/100 ;
var d = document.getElementById( this.id ) ;

if (typeof(d.style.filter) =='string')
{
d.style.filter = 'alpha(opacity:' + opacity + ')' ;
}
if (typeof(d.style.KHTMLOpacity) == 'string' )
{
d.style.KHTMLOpacity = c ;
}
if (typeof(d.style.MozOpacity) == 'string')
{
d.style.MozOpacity = c ;
}
if (typeof(d.style.opacity) == 'string')
{
d.style.opacity = c ;
}
}
