    //<![CDATA[

	google.load("maps", "2.x");
	var dataUrl;
	var map;
	var newMap;
	var zoomDelayId;
	var maxZoom = 20; 
	var marker;
	var gmarkers = [];
	var gmarkersHTML = [];
	var customIcons = [];
	
   
  // Call this function when the page has been loaded
	function initialize() {
		var greenPlantIcon = new GIcon(); 
		greenPlantIcon.image = 'http://www.wildcrafting.net/forage/images/greenPlantIcon.png';
		greenPlantIcon.iconSize = new GSize(20, 34);
		greenPlantIcon.iconAnchor = new GPoint(6, 20);
		greenPlantIcon.infoWindowAnchor = new GPoint(5, 1);
		
		var greenSroomIcon = new GIcon(); 
		greenSroomIcon.image = 'http://www.wildcrafting.net/forage/images/greenSroomIcon.png';
		greenSroomIcon.iconSize = new GSize(20, 34);
		greenSroomIcon.iconAnchor = new GPoint(6, 20);
		greenSroomIcon.infoWindowAnchor = new GPoint(5, 1);
		
		var redPlantIcon = new GIcon(); 
		redPlantIcon.image = 'http://www.wildcrafting.net/forage/images/redPlantIcon.png';
		redPlantIcon.iconSize = new GSize(20, 34);
		redPlantIcon.iconAnchor = new GPoint(6, 20);
		redPlantIcon.infoWindowAnchor = new GPoint(5, 1);
	
		var redSroomIcon = new GIcon(); 
		redSroomIcon.image = 'http://www.wildcrafting.net/forage/images/redSroomIcon.png';
		redSroomIcon.iconSize = new GSize(20, 34);
		redSroomIcon.iconAnchor = new GPoint(6, 20);
		redSroomIcon.infoWindowAnchor = new GPoint(5, 1);
		
		customIcons['plantn'] = greenPlantIcon;
		customIcons['planty'] = redPlantIcon;
		customIcons['mushroomy'] = redSroomIcon;
		customIcons['mushroomn'] = greenSroomIcon;	
		
		//map = new GMap2(document.getElementById("plantTab2"))
		map = new google.maps.Map2(document.getElementById("favMap"));
		map.setCenter(new google.maps.LatLng(41.902277040963696, -96.50390625), 3, G_HYBRID_MAP);
		map.addMapType(G_PHYSICAL_MAP);
		map.removeMapType(G_NORMAL_MAP);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		
		setTimeout('loadData();', 50);
		
	}
	
	function loadData() {
		var bogusNum = new Date().getTime();
		dataUrl = "http://www.wildcrafting.net/forage/include/googlemapsdata.php";
		GDownloadUrl(dataUrl + "?all=Y&userId=" + userId + 'bogus=' + bogusNum, function(data) {
			  var xml = GXml.parse(data);
			  var markers = xml.documentElement.getElementsByTagName("marker");
			  for (var i = 0; i < markers.length; i++) {
				var id = markers[i].getAttribute("id");
				var name = markers[i].getAttribute("name");
				var info = markers[i].getAttribute("info");
				var createdBy = markers[i].getAttribute("createdBy");
				var plantType = markers[i].getAttribute("plantType");
				var private = markers[i].getAttribute("private");
				var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
										parseFloat(markers[i].getAttribute("lng")));
				var newMarker = createMarker(point, id, name, info, createdBy, plantType, private);
				//map.addOverlay(newMarker);
				//var marker = new GMarker(point);
				//gmarkers.push(marker);
			  }
			  //clusterer options - http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/docs/reference.html
			  var mcOptions = {gridSize: 30, maxZoom: 16};
			  var markcluster = new MarkerClusterer(map, gmarkers, mcOptions);
		});
		
	}
	
	function addressPan() {
		var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
		var pars = 'action=addressPan&address='+$('address').value;
		var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onComplete:function(o) {
			var cords = o.responseText.split(",");
			map.setCenter(new GLatLng(parseFloat(cords[0]), parseFloat(cords[1])), 12);
		}});
	}
	
	function getCommentsList (id, userId) {
		var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
		var pars = 'action=listComments&id='+id+'&userId='+userId+'&uGroup='+userGroup;
		var target = "commentsWindow";
		var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars});
	}
	
	function getPhotoList (id, userId) {
		var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
		var pars = 'action=getPhotos&id='+id+'&userId='+userId+'&uGroup='+userGroup;
		var target = "infoWindowTabPhotos";
		var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars});
	}
	
	function addFavs (id, uid) {
		var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
		var pars = 'action=addFavs&id='+id+'&userId='+uid;
		var target = "locFavs";
		var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars, onComplete:updateWindow(id, uid)});
	}
	
	 function createMarker(point, id, name, info, createdBy, plantType, private) {
		var Type = plantType + private;
		Type = Type.toLowerCase(); 
		var newMarker = new GMarker(point, customIcons[Type]);
		//var newMarker = new GMarker(point);
		
		var html = [new GInfoWindowTab('About','<div class="aboutLoc"><div id="aboutInfo"></div><div id="removeBtn"></div><div id="locFavs"></div> <div id="ratingIcons"></div></div>'), new GInfoWindowTab('Comments', '<div id="commentsWindow"></div><input id="addCom-btn" value="Add Comment" type="button" onClick="getInfoBox('+id+');">'), new GInfoWindowTab('Photos', '<div id="infoWindowTabPhotos"></div><input id="addPhoto-btn" value="Add Photo" type="button" onClick="addPhoto('+id+', '+createdBy+');">')];
		//var html = 'hello';
		gmarkers.push(newMarker);
		gmarkersHTML.push(html);
		  
		GEvent.addListener(newMarker, 'click', function () {
			map.openInfoWindowTabsHtml(point, html);
			
			var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
			setTimeout("getAbout("+id+", "+userId+", "+userGroup+")",400);
			setTimeout("getCommentsList("+id+", "+userId+")",400);
			setTimeout("getPhotoList("+id+", "+userId+")",400);
			setTimeout("getToolBar("+id+", "+userId+", "+userGroup+")",500);
			
		});
		
		return newMarker;
    }
	
	function getToolBar(id, uid, ugroup) {
		var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
		var pars = 'action=getToolBar&id='+id+'&userId='+uid+'&ugroup='+ugroup;
		var target = "toolBar";
		var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars});
	}
	
	function getAbout(id, uid, ugroup) {
		var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
		var pars = 'action=getAboutInfo&id='+id+'&userId='+uid+'&uGroup='+ugroup;
		var target = "aboutInfo";
		var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars});
	}
	
	function removeLoc(id, uId) {
		var sure = confirm('Are you sure you wish to delete this location?');
		if(sure) {
			var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
			var pars = 'action=removeLoc&locId='+id+'&userId='+uId;;
			var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars});
			initialize();
		}
		
	}
	
	
	function delCom(id, locId) {
		var sure = confirm('Are you sure you wish to delete this comment?');
		if(sure){
			var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
			var pars = 'action=delComments&id='+id+'&locId='+locId+'&userId='+userId;
			var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars});
			setTimeout("getCommentsList("+locId+", "+userId+")",200);
		}
	}
	
	function delPhoto(id, locId) {
		var sure = confirm('Are you sure you wish to delete this photo?');
		if(sure){
			var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
			var pars = 'action=delPhoto&id='+id;
			var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars});
			getPhotoList(locId, userId);
		}
	}
	
	function addRating(locId, uid, type) {
		var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
		var pars = 'action=addRating&locId='+locId+'&userId='+userId+'&type='+type;
		var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onComplete:updateWindow(locId, uid)});
	}
	
	function updateWindow(id, uid) {
		setTimeout("getAbout("+id+", "+uid+", "+userGroup+")",100);
		setTimeout("getToolBar("+id+", "+uid+", "+userGroup+")",200);
	}
	
	function remFavs(id, locId, uid) {
		var sure = confirm('Are you sure you wish to remove this location from your favorites?');
		if(sure) {
			var url = 'http://www.wildcrafting.net/forage/include/ajax.php';
			var pars = 'action=remFav&id='+id;;
			var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onComplete:updateWindow(locId, uid)});
		}
		
	}
		google.setOnLoadCallback(initialize);
    //]]>
	
	Ext.namespace('Ext.exampledata');
	Ext.exampledata.closed = [
		['Y', 'Yes'],
		['N', 'No']
		];
	Ext.exampledata.plantType = [
		['Plant', 'Plant'],
		['Mushroom', 'Mushroom']
		];

Ext.onReady(function(){
					 
	Ext.QuickTips.init();
    
    var msg = function(title, msg){
        Ext.Msg.show({
            title: title, 
            msg: msg,
            minWidth: 200,
            modal: true,
            icon: Ext.Msg.INFO,
            buttons: Ext.Msg.OK
        });
    };
	

		window.getInfoBox = function (id){
			var addComWinDiv = document.createElement('div');
			addComWinDiv.id='addComWin';
			addComWinDiv.setAttribute('class','x-hidden');
			document.body.appendChild(addComWinDiv);
			var addComForm = '';
			addComForm = new Ext.FormPanel({
				title: 'Add Plant Location Comment',
				defaults: {width: 230},
				defaultType: 'textfield',
				url:'http://www.wildcrafting.net/forage/include/ajax.php',
				items: [{
						fieldLabel: 'Comment',
						name: 'commentText',
						xtype: 'textarea',
						height: 100,
						width: 250
				}],
				buttons: [{
							text: 'Save',
							type: 'submit',
							handler: function() { 
									addComForm.getForm().submit({
										method: 'POST',
										params:{
											action: 'addCom',
											createdBy: userId,
											locId: id
										},
										waitMsg:'Saving...',
										success: function(fp, o){
											addComWin.close();
											getCommentsList(id, userId);
										}
									})
									//initialize();		
								}
				
							},{
							text     : 'Close',
							handler  : function(){
								addComWin.close();
								
							}
						}]
			});
			
			// create the window on the first click and reuse on subsequent clicks
				if(!addComWin){
					var addComWin = new Ext.Window({
						applyTo     : 'addComWin',
						y			: 450,
						layout      : 'fit',
						width       : 400,
						height      : 190,
						plain       : true,
						items		:	addComForm
					});
				}
				addComWin.show(this);
	};
	
	
		window.addPhoto = function (locId, uId){
			var addPhotoWinDiv = document.createElement('div');
			addPhotoWinDiv.id='addPhotoWin';
			addPhotoWinDiv.setAttribute('class','x-hidden');
			document.body.appendChild(addPhotoWinDiv);
			var addPhotoForm = '';
			addPhotoForm = new Ext.FormPanel({
				fileUpload: true,
				width: 300,
				frame: true,
				title: 'File Upload Form',
				autoHeight: true,
				bodyStyle: 'padding: 10px 10px 0 10px;',
				labelWidth: 50,
				defaults: {
					anchor: '95%',
					allowBlank: false,
					msgTarget: 'side'
				},
				items: [{
					xtype: 'fileuploadfield',
					width: 250,
					id: 'form-file',
					emptyText: 'Select an image',
					fieldLabel: 'Photo',
					name: 'photo-path',
					buttonCfg: {
						text: '',
						iconCls: 'upload-icon'
					}
				}],
				buttons: [{
							text: 'Save',
							handler: function(){
								if(addPhotoForm.getForm().isValid()){
									addPhotoForm.getForm().submit({
										waitMsg: 'Uploading your photo...',
										url:'http://www.wildcrafting.net/forage/include/ajax.php',
										params:{
												action: 'addPhoto',
												userId: uId,
												locId: locId
										},
										success: function(fp, o){
											
											//msg('Success', 'uploaded file "'+o.result.file+'" to the server');
											addPhotoWin.close();
											getPhotoList(locId, uId);
										}
									});
									
								}
							}
						},{
							text: 'Reset',
							handler: function(){
								addPhotoForm.getForm().reset();
							}
						}]
			});
			
			// create the window on the first click and reuse on subsequent clicks
				if(!addPhotoWin){
					var addPhotoWin = new Ext.Window({
						applyTo     : 'addPhotoWin',
						y			: 450,
						layout      : 'fit',
						width       : 400,
						height      : 190,
						plain       : true,
						items		:	addPhotoForm
						
					});
				}
				addPhotoWin.show();
	};
	
		window.editLoc = function (id){
			var editLocWinDiv = document.createElement('div');
			editLocWinDiv.id='editLocWin';
			editLocWinDiv.setAttribute('class','x-hidden');
			document.body.appendChild(editLocWinDiv);

			var editLocForm ='';
			editLocForm = new Ext.FormPanel({
				frame: true,
				title: 'Edit Plant Location',
				waitMsgTarget: true,
				reader : new Ext.data.XmlReader({
					record : 'location',
					success: '@success'
				}, [
					{name: 'name', mapping:'name'},
					'info', 'private', 'plantType'// custom mapping
				]),
				items: [ 
					new Ext.form.FieldSet({
						title: 'Location Information',
						autoHeight: true,
						defaultType: 'textfield',
						items: [{
								fieldLabel: 'Name',
								name: 'name',
								width:300
							},{
								fieldLabel: 'Info',
								name: 'info',
								xtype: 'textarea',
								height: 50,
								width:300
							},
							new Ext.form.ComboBox({
								fieldLabel: 'Private',
								hiddenName:'private',
								store: new Ext.data.SimpleStore({
									fields: ['value', 'name'],
									data : Ext.exampledata.closed // from states.js
								 }),
								valueField:'value',
								displayField:'name',
								typeAhead: true,
								mode: 'local',
								triggerAction: 'all',
								emptyText:'Select One...',
								width:100,
								selectOnFocus:true
							})
						]
					})
				],
				buttons: [{
					text: 'Save',
					type: 'submit',
					handler: function() { 
							editLocForm.getForm().submit({
								url: '/forage/include/ajax.php',
								method: 'POST',
								params:{
									action: 'editLoc',
									id: id
								},
								waitMsg:'Saving...',
								success: function(fp, o){
									editLocWin.close();
									getAbout(id, userId, userGroup);
									setTimeout("getToolBar("+id+", "+userId+", "+userGroup+")",100);
								}
								
							})
							
							
						}
		
					},{
					text     : 'Close',
					handler  : function(){
						editLocWin.close();
					}
				}]
			});
			
			// create the window on the first click and reuse on subsequent clicks
				if(!editLocWin){
					var editLocWin = new Ext.Window({
						applyTo     : 'editLocWin',
						y			: 450,
						layout      : 'fit',
						width       : 500,
						height      : 250,
						plain       : true,
						items		:	editLocForm
					});
				}
				editLocWin.show();
				editLocForm.getForm().load({url:'http://www.wildcrafting.net/forage/include/data.php?id='+id, waitMsg:'Loading'});
	};
	
	 
	window.viewImg = function (img){
			var viewImgWinDiv = document.createElement('div');
			viewImgWinDiv.id='viewImgWin';
			viewImgWinDiv.setAttribute('class','x-hidden');
			document.body.appendChild(viewImgWinDiv);

			
			// create the window on the first click and reuse on subsequent clicks
				if(!viewImgWin){
					var viewImgWin = new Ext.Window({
						applyTo     : 'viewImgWin',
						y			: 450,
						layout      : 'fit',
						width       : 700,
						height      : 500,
						plain       : true,
						bodyCfg: { tag: 'iframe', src: img, style: "border:0px none;"}
					});
				}
				viewImgWin.show();
	};
	
	
});


