		var map;
	   	var geocoder;
	  	var baseIcon = new GIcon();
	   	var centerpoint;
		var text;
		var gmarkers = [];
	
	
		
		
		var FadeInterval = 100;

		// This is where the fade will start, if you want it to be faster and start with a lighter color, make this number smaller
		// It corresponds directly to the FadeSteps below
		var StartFadeAt = 7;

		// This is list of steps that will be used for the color to fade out
		var FadeSteps = new Array();
			FadeSteps[1] = "ff";
			FadeSteps[2] = "ee";
			FadeSteps[3] = "dd";
			FadeSteps[4] = "cc";
			FadeSteps[5] = "bb";
			FadeSteps[6] = "aa";
			FadeSteps[7] = "99";
			
			
		///////////////////////////////////////////////////////
		/// ONLoad
		$(document).ready(function(){
			$("td.day").ToolTipDemo("#fef", "#e00");
		});
	
		function DoFade(colorId, targetId) {
		    if (colorId >= 1) {
				document.getElementById(targetId).style.backgroundColor = "#ffff" + FadeSteps[colorId];
		
		        // If it's the last color, set it to transparent
		        if (colorId==1) {
		            document.getElementById(targetId).style.backgroundColor = "#61845b";
				}
		        colorId--;
		
		        // Wait a little bit and fade another shade
		        setTimeout("DoFade("+colorId+",'"+targetId+"')", FadeInterval);
			}
		}
		
		
		
		
		
	function load() {

	   	      if (GBrowserIsCompatible()) {
	   	        map = new GMap2(document.getElementById("map_canvas"));
	   	    	geocoder = new GClientGeocoder();
	   			//showAddressFast('54911', true);
				//showAddress('Mansfield,OH',true);
	   			setStart(start_lat,start_lng);
				//map.addControl(new GLargeMapControl());
				map.addControl(new GLargeMapControl3D());   	        
				map.addControl(new GMapTypeControl());
	   	
	   		
	   			if(typeof(data) != 'undefined'){
					// Create a base icon for all of our markers that specifies the
					// shadow, icon dimensions, etc.
					//baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
					//baseIcon.iconSize = new GSize(28, 34);
					
					if(marker_fold == 'marker4'){
						baseIcon.iconSize = new GSize(28, 34);
						baseIcon.shadow = "http://hotfootlabs.com/resources/classmap/_original/images/marker4/marker4shadow.png";
					}else{
						baseIcon.iconSize = new GSize(20, 34);
						baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
					}
						
					baseIcon.shadowSize = new GSize(37, 34);
					baseIcon.iconAnchor = new GPoint(9, 34);
					baseIcon.infoWindowAnchor = new GPoint(9, 2);
					baseIcon.infoShadowAnchor = new GPoint(18, 25);
	   				//alert(data.length);
		   				//for(x=0;x < 5;x++){
					for(x=0;x < data.length;x++){
			   			//alert(data[x]);
			   			showAddressFast(data[x],false,x);
			   		}
				}
	   	  }
	   	}
	   	
	   		function showAddress(address, setcenter,x) {
	   		  geocoder.getLatLng(
	   		    address,
	   		    function(point) {
	   		      if (!point) {
	   		        //alert(address + " not found");
	   		      }else{
	   		       // alert(point);
					if(setcenter){
	   					map.setCenter(point, 11);
						centerpoint=point;
	   				}else{
	   		        //var marker = new GMarker(point);
	   		        // map.addOverlay(marker);
	   		        // 		        marker.openInfoWindowHtml(address);
	   					alert(address+'\n\n'+point);
						map.addOverlay(createMarker(point, address,x));
	   				}
	   			
	   		      }
	   		    }
	   		  );
	   		}
	
	
			function setStart(lat,lng){
					//alert(lat);
					if(zoom_level < 1)
						zoom_level = 10;
					point = new GLatLng(lat,lng);
					map.setCenter(point, zoom_level);
					centerpoint=point;
			}
			
			
			function showAddressFast(address,setcenter,x){
	 
				
				//	point = new GLatLng(40.6686,-82.5968);
				//	alert('Create Marker');
				if(setcenter){
					point = new GLatLng(44.519511,-87.902830);
					map.setCenter(point, 10);
					centerpoint=point;
				}else{
					point = new GLatLng(lat[x],lon[x]);
					//point = new GLatLng(40.761307,-82.522964);
					map.addOverlay(createMarker(point, address,x));
				}
	   		
			}
	   		
	   		function createMarker(point, address,x) {
	   			 // Create a lettered icon for this point using our icon class
				//	alert(x);
	  		
				//var letter = String.fromCharCode("A".charCodeAt(0) + x);
	  			//var letteredIcon = new GIcon(baseIcon);
	  			//letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	
				//var letter = String.fromCharCode("A".charCodeAt(0) + x);
	  		
				var letteredIcon = new GIcon(baseIcon);
	  			//alert(disp_num[x]);
				letteredIcon.image = "http://hotfootlabs.com/resources/classmap/_original/images/"+marker_fold+"/"+disp_num[x]+".png";
//	alert(letteredIcon.image);
	
				//letteredIcon.image = "http://hotfootlabs.com/resources/classmap/_original/images/markers/8888.png";
				
	  			// Set up our GMarkerOptions object
	  			markerOptions = { icon:letteredIcon };
			//	alert(markerOptions);
	  			var marker = new GMarker(point, markerOptions);
	   	     	//alert(marker);
		  		//var marker = new GMarker(point);
	   		     //alert(x);
	   			 //marker.value = x;
		//	alert(iid[x]);
				marker.value = iid[x];
	   		    //	alert(desc[x]);  
			
				GEvent.addListener(marker,"click", function() {
																		//text for window
															
																text='<div style="font-size: 18px;text-align:left;">'+address+'</div>'; 
																
													   				var moretext = '<div style="margin:6px 0;text-align:left;border-top:1px solid #ccc;padding-top:5px;font-size:11px;">'+desc[x]+'<div>';
																if(hrs[x]!= '')
																	moretext += '<div class="hours" style="margin:6px 0;text-align:left;border-top:1px solid #ccc;padding-top:10px;font-size:11px;">'+hrs[x]+'  <span style="margin-left:0px;background-color:#fff;font-weight:normal;color:#c45045;">Ad Id: '+ad_id[x]+'</span></div>';
													   				text += moretext;
																		text+='<form target="_blank" method="get" name="dir" action="http://maps.google.com/maps" style="margin:0;padding:0;">';
															   				text+='<div style="background-color:#ededed;padding:5px 7px;text-align:left;margin-top:10px;margin:bottom:0;border:1px solid #ccc;">Get Directions: &nbsp;';
															   				text+='<input type="hidden" name="daddr" value="'+address+'" />';
															   				text+='<input id="saddr" type="text" size="35" name="saddr" value="Type Your Address" OnFocus="if(this.value==\'Type Your Address\'){this.value=\'\';}"/>'; 
															   	            text+='<input type="submit" name="btnG" value="GO"/></div></form>';
																	
																	// Email, Add List Links
																	var linkers = '<div style="margin:0px 0 15px 0;text-align:left;border-top:0px solid #ccc;padding-top:10px;padding-bottom:15px;font-size:11px;"><a href="faves_email.php?iidclassloc='+iid[x]+'&pub_id='+iidpub+'&market_id='+iidmarket+'">Email Sale</a>';
																	if(infaves(iid[x])){
																		linkers += '<span style="margin:0 14px;">-</span> <span id="win_ad_'+iid[x]+'">Added to MyList</span>';
																	}else{
																		linkers += '<span style="margin:0 14px;">-</span> <span id="win_ad_'+iid[x]+'"><a href="javascript:mylist('+iid[x]+');"  >Add to MyList</a></span>';
																	}
																	linkers += '<div>';
																text += linkers;
																// Get directions
															
																map.openInfoWindowHtml(point, text);
																			   		      });
		
			GEvent.addListener(marker,"panner", function() {
																	//text for window
																			text='<div style="font-size: 18px;text-align:left;">'+address+'</div>'; 

																   				var moretext = '<div style="margin:6px 0;text-align:left;border-top:1px solid #ccc;padding-top:5px;font-size:11px;">'+desc[x]+'<div>';
																			if(hrs[x]!= '')
																				moretext += '<div class="hours" style="margin:6px 0;text-align:left;border-top:1px solid #ccc;padding-top:10px;font-size:11px;">'+hrs[x]+'  <span style="margin-left:0px;background-color:#fff;font-weight:normal;color:#c45045;">Ad Id: '+ad_id[x]+'</span></div>';
																   				text += moretext;
																					text+='<form target="_blank" method="get" name="dir" action="http://maps.google.com/maps" style="margin:0;padding:0;">';
																		   				text+='<div style="background-color:#ededed;padding:5px 7px;text-align:left;margin-top:10px;margin:bottom:0;border:1px solid #ccc;">Get Directions: &nbsp;';
																		   				text+='<input type="hidden" name="daddr" value="'+address+'" />';
																		   				text+='<input id="saddr" type="text" size="35" name="saddr" value="Type Your Address" OnFocus="if(this.value==\'Type Your Address\'){this.value=\'\';}"/>'; 
																		   	            text+='<input type="submit" name="btnG" value="GO"/></div></form>';

																				// Email, Add List Links
																				var linkers = '<div style="margin:0px 0 15px 0;text-align:left;border-top:0px solid #ccc;padding-top:10px;padding-bottom:15px;font-size:11px;"><a href="faves_email.php?iidclassloc='+iid[x]+'&pub_id='+iidpub+'&market_id='+iidmarket+'">Email Sale</a>';
																				if(infaves(iid[x])){
																					linkers += '<span style="margin:0 14px;">-</span> <span id="win_ad_'+iid[x]+'">Added to MyList</span>';
																				}else{
																					linkers += '<span style="margin:0 14px;">-</span> <span id="win_ad_'+iid[x]+'"><a href="javascript:mylist('+iid[x]+');"  >Add to MyList</a></span>';
																				}
																				linkers += '<div>';
																			text += linkers;
																			// Get directions
																			   		 		map.openInfoWindowHtml(point, text);
																			   		      });
																GEvent.addListener(marker,"closer", function() {
																			   		      	map.closeInfoWindow();
																			   		      });	
						
				gmarkers[iid[x]] = marker;
				// alert(marker);
				// 			obj = eval(marker);
				// 			var temp = "";
				// 			for (x in obj)
				// 			        temp += x + ": " + obj[x] + "\n";
				// 			alert (temp);
				
				return marker;
				
	   		}
	   		
	   		function panto(lat,lng,x) {
				point = new GLatLng(lat,lng);
				map.setCenter(point, 15);
	   			GEvent.trigger(gmarkers[x],"panner");
				location.href = '#top_of_page';
	   		}
			
		function center(){
			map.setCenter(centerpoint, 10);
			for(k=0;k < gmarkers.length;k++){
				GEvent.trigger(gmarkers[k],"closer");
			}
		}
		
		function infaves(iid){
			var i;
			for (i=0; i < faves.length; i++) {
				if (faves[i] === iid) {
					return true;
				}
			}
			return false;
		}
		
		// function mylist(iid){
		// 			document.bits.iidclassloc.value = iid;
		// 			document.bits.submit();
		// 		}
		
		function mylist(iid){			
			gourl = "add_loc.php";
		//	alert(sess_id);
			$.post(gourl, { iidclassloc:iid,PHPSESSID:sess_id }, function(data){
				if(data == '1'){
					// Success
					locs++;
					$("#locs").html(locs);
					col = '#col_'+iid;
					$(col).html('Added');
					win = '#win_ad_'+iid;
					$(win).html('Added to MyList');
					DoFade(7,'mylocs');
				}else{
					// Fail
					if(data == '2'){
						win = '#win_ad_'+iid;
						$(win).html('Added to MyList');
					}else{
						
						alert('An error occurred and your location did not save.\n\n  Please try again:.'+data);
					}
				}
			});
		}
		
		function tog_map(){
			$("#map_canvas").slideToggle("slow");
			$("#map_hide").toggle();
			$("#map_show").toggle();
		}
		
		function size_map(big){
				h = $("#map_canvas").height();
				if(h == 300)
					h = 500;
				else
					h = 300;
				$("#map_canvas").height(h);
				$("#map_big").toggle();
				$("#map_small").toggle();
				load();
				$.post('set_size.php', { map_size:h }, function(data){
					//alert(data);
				});
		}

		function CheckIsIE(){ 
			if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER'){ 
				return true;
			}else{
				return false; 
			} 
		} 
		
		
		function change_market(idmarket){
		//	alert(idmarket);
			location.href = 'index.php?pub_id='+iidpub+'&market_id='+idmarket;
		}
		
		function change_city(city){
		//	alert(idmarket);
			location.href = 'index.php?pub_id='+iidpub+'&market_id='+iidmarket+'&city='+city;
		}
		
		







/*
 *
 * Copyright (c) 2006 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

 
/*
 * jQuery ToolTip Demo. Demo of how to add elements and get mouse coordinates
 *	There is also a ToolTip plugin found at http://interface.eyecon.ro/,
 *	  which uses a CSS class to style the tooltip, but shows it below the input/anchor, rather than where the mouse is
 *
 *
 * @name     ToolTipDemo 
 * @param    bgcolour  Background colour
 * @param    fgcolour  Foreground colour (i.e. text colour)
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $("a,input").ToolTipDemo('#fff');
 *
 */
$.fn.ToolTipDemo = function(bgcolour, fgcolour)
{
	this.mouseover(
		function(e)
		{
			if((!this.title && !this.alt) && !this.tooltipset) return;
			// get mouse coordinates
			// based on code from http://www.quirksmode.org/js/events_properties.html
			var mouseX = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
			var mouseY = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
			mouseX += 10;
			mouseY += 10;
			bgcolour = bgcolour || "#eee";
			fgcolour = fgcolour || "#000";
			// if there is no div containing the tooltip
			if(!this.tooltipdiv)
			{
				// create a div and style it
				var div = document.createElement("div");
				this.tooltipdiv = div;
				$(div).css(
				{
					border: "1px outset #fbf6ce",
					padding: "10px",
					backgroundColor: "#fbf6ce",
					color: "#000",
					position: "absolute"
				})
				// add the title/alt attribute to it
				.html((this.title || this.alt));
				this.title = "";
				this.alt = "";
				$("body").append(div);
				this.tooltipset = true;
			}
			$(this.tooltipdiv).show().css({left: mouseX + "px", top: mouseY + 3 + "px"});
		}
	).mouseout(
		function()
		{
			if(this.tooltipdiv)
			{
				$(this.tooltipdiv).hide();
			}
		}
	);
	return this;
}