	

	jq = window.jq || {};
	jq.mediplex = jq.mediplex || {};

	jQuery(document).ready(function () {
		jq.mediplex.pulldown.init();
	});
	
	jq.mediplex.pulldown = {
		
		isActive: false,
		
		googleInit: false,
		
		onEvent: function(e) {
			var sc = e.data.scope;
			var fn = e.data.fn;
			sc[fn] && sc[fn].call(sc, e);
		},	
		
		init: function() {
			jQuery(document).bind('click', {fn: 'onDocClick', scope: this}, this.onEvent);
			jQuery('a.membercontact-toggle').bind('click', {fn: 'onTriggerClick', scope: this}, this.onEvent);
			jQuery('a.membercontact-close').bind('click', {fn: 'hide', scope: this}, this.onEvent);
		},
		
		onTriggerClick: function(e) {
			var n = e.currentTarget;
			e.preventDefault();
			e.stopPropagation();
			jQuery(n).blur();
			jQuery('div.membercontact-inner').css('display', 'block');
			
			this.initGoogleMap();
			
			this.isActive = true;
		},
		
		onDocClick: function(e) {
			if (!this.isActive)
				return;
			var n = e.target;
			var hit = jQuery(n).parents('div.membercontact-outer');
			if (!hit.length) {
				this.hide();
			}
		},
		
		hide: function() {
			jQuery('div.membercontact-inner').css('display', 'none');
			this.isActive = false;
		},
		
		initGoogleMap: function() {
			
			if (!window.currentAddress || this.googleInit == true)
				return;
			
			var map = new GMap2(document.getElementById("membercontact-google"));
			var geocoder = new GClientGeocoder();
			geocoder.getLatLng(window.currentAddress,  function(point) {
	            if (!point) {
	            } else {
	              map.setCenter(point, 15);
				  map.addControl(new GSmallMapControl());
	        	  map.addControl(new GMapTypeControl());
				  var marker = new GMarker(point);
	        	  map.addOverlay(marker);
				}
			});
			
			this.googleInit = true;
			
		}
		
		
		
		
	};
