//	window.onload = googleMapInit;
	
	var initialLocation;
	
	var markerImage = '/graphics/youAreHere_icon.png';
	var markers = [];
	var marker;
	var iterator = 1;
	var zoomLevel = 12;
	var map;
	
	
	var geocoder;
	var directionDisplay;
	var endRoute;
	var startRoute;
	var currentLocation;
	var GeoLocationOn = true;
	var locationList = '';
	
	if(!mobile){
		var defaultStartPoint = new google.maps.LatLng(42.3875968, -71.0994968);
		var infowindow = new google.maps.InfoWindow();
		var directionsService = new google.maps.DirectionsService();
		google.maps.event.addDomListener(window, 'load', initialize);
	}
	//google.maps.event.addDomListener(window, 'load', initialize);
	
	$(window).resize(function() {
		setMapSize(resize = true);
	});
	function googleMapInit(){
		
		
		if(!mobile){
			setMapSize(resize = false);
			initialize();
		}else{
			GeoLocationOn = true;
			viewport = document.querySelector("meta[name=viewport]");
			viewport.setAttribute('content', 'width = 320, initial-scale = 1.0, maximum-scale = 1.0, user-scalable = 0');
			$(window).width($(document).width());
		
		}
		
		getGeoLocation();
		
		showPopUp('#mapDataCollector');
		
		$('#mapDataCollector a').click(function(){
			var popUpName = $(this).attr('popUp');
			showPopUp(popUpName)
		});
		
		if(!mobile){
			$('#travelType').bind('change', displayRoute);
			
			$('a.getDirections').live('click', getDirections);
			
			$('a.closeDirection').live('click', function(){
				showPopUp('#mapDataCollector');
			});
		}
	}
	/***********************************
		Creates Map 
	***********************************/
	function initialize() {
		
		geocoder = new google.maps.Geocoder();
		var mapOptions = {
			zoom: 2
			,mapTypeId: google.maps.MapTypeId.ROADMAP
			,center: defaultStartPoint
			
		};

		map = new google.maps.Map(
				document.getElementById("map_canvas")
				,mapOptions
			);
			
			
        directionsDisplay = new google.maps.DirectionsRenderer();
        directionsDisplay.setMap(map);
        directionsDisplay.setPanel(document.getElementById('directions-panel'));
	}
	
	/***********************************
		Gets current Location
	***********************************/
	function getGeoLocation(){
		// Try W3C Geolocation (Preferred)
		if(GeoLocationOn){
			if(navigator.geolocation) {
				browserSupportFlag = true;
				
				navigator.geolocation.getCurrentPosition(function(position) {
					
					if(!mobile){
						codeLatLng(position.coords.latitude + ', ' + position.coords.longitude);
						
						initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
						map.setCenter(initialLocation);
						showPopUp('#mapDataCollector');
						getLocations();
						map.setZoom(zoomLevel);
					}else{
						codeAddressLatLng(position.coords.latitude + ', ' + position.coords.longitude)
						getLocations(position.coords.latitude, position.coords.longitude)
						
					}
					
				}, function() {
						handleNoGeolocation(browserSupportFlag);
				});
				
			// Try Google Gears Geolocation
			} else if (google.gears) {
				browserSupportFlag = true;
				var geo = google.gears.factory.create('beta.geolocation');
				
				geo.getCurrentPosition(function(position) {
					if(!mobile){
						codeLatLng(position.coords.latitude + ', ' + position.coords.longitude);
						
						initialLocation = new google.maps.LatLng(position.latitude, position.longitude);
						map.setCenter(initialLocation);
						showPopUp('#mapDataCollector');
						getLocations();
						map.setZoom(zoomLevel);
					}else{
						codeAddressLatLng(position.coords.latitude + ', ' + position.coords.longitude)
						getLocations(position.coords.latitude, position.coords.longitude)
						
					}
					
					
				}, function() {
					handleNoGeoLocation(browserSupportFlag);
				});
			// Browser doesn't support Geolocation
			} else {
				browserSupportFlag = false;
				handleNoGeolocation(browserSupportFlag);
			}
		} else {
			browserSupportFlag = false;
			handleNoGeolocation(browserSupportFlag);
		}
		
	}
	
	
	/***********************************
		populates current location on the map
	***********************************/
	function handleNoGeolocation(errorFlag) {
		GeoLocationOn = false;
		var msg;
		if (errorFlag == true ) {
			msg = "Geolocation service failed.";
		} else {
			msg = "Your browser doesn't support geolocation.";
		}
		
		if( msg != ''){
			var tempHtml = '<p>'
								+'<span class="error">We could not locate your current address.</span>'
								+'<br />'
								+'<strong>Please enter an address or zip code:</strong>'
							+ '</p>'	
							+'<form action="#" onsubmit="manuallyGeoLocation(false); return false">'
								+'<div>'
									+'<input type="text" name="userAddress" class="mapSearchBox" id="userAddress"  />'
									+'<input type="image" src="/graphics/locations/shim.gif" class="searchBTN" value="Go!" />'
								+'</div>'
							+'</form>';
			$('#mapDataCollector').html(tempHtml)	
		}else{
			showPopUp('#mapDataCollector #body');
			//codeLatLng(currentLatLng);
			if(!mobile){
				map.setCenter(initialLocation);
				map.setZoom(zoomLevel);
				
				markers.push(new google.maps.Marker({
					position: initialLocation
					,map: map
					,animation: google.maps.Animation.DROP
					//,icon: markerImage
				}));
			}
			
			getLocations();
		}
		
	}
		
	/***********************************
		If getting the user address fails we ask then to enter there zip code they covert it to lat and lon
	***********************************/
	function manuallyGeoLocation(isReset){
		$('#locationList').html('<li class="loading">'
									+ '<img src="/graphics/ajax_loading.gif">'
								+ '</li>')
		if(isReset){
			var addressVal = "#updateAddress";
		}else{
			var addressVal = "#userAddress";
		}
		
		if( $(addressVal).val() != '' ){
			
			$('.searchResults span').html( $(addressVal).val() );
			track_search( $(addressVal).val() )
			
			
			if(mobile){
				codeAddressServer( $(addressVal).val() )
			}else{
				codeAddress( $(addressVal).val(), isReset );
			}
			
		}else{
			alert('Please enter your zip code.');
		}
		
	}
	function popuplateManualLocation(currentLocation, isReset){
		
		var latAndLng = getLatLongFromMap(currentLocation);
		
		initialLocation = new google.maps.LatLng(latAndLng[0], latAndLng[1]); 
		
		if(!isReset){
			showPopUp('#mapDataCollector');	
		}
		
		map.setZoom(zoomLevel);
		map.setCenter(initialLocation);

		markers.push(new google.maps.Marker({
				position: initialLocation
				,map: map
				,animation: google.maps.Animation.DROP
				//,icon: markerImage
			}));
		getLocations();		
	}
	/***********************************
		Builds list items
	***********************************/
	function buildLocationList(locations){
		var tempHtml = "";
		var firstDistance = 0;
		$.each(locations, function() {
			  $.each(this, function(k, v)  {
				
				var currentData = this;
				var thisAddress = this.STREET + ' ' + this.CITY + ', ' + this.STATEABBREV + ' ' + this.ZIP; 				  
				
				if(firstDistance == 0 && currentData.DISTANCE > 80 && !mobile){
					firstDistance = currentData.DISTANCE;
					map.setZoom(3);
				}
				
				tempHtml += "<li id=" + iterator + ">"
					tempHtml += "<p>"
						tempHtml += '<span></span>'
						tempHtml += '<a name="' + iterator + '"></a>'
						
						
						if(mobile){
							tempHtml += "<a href='http://maps.google.com/?q=" + this.STREET + ' ' + this.CITY + ', ' + this.STATEABBREV + ' ' + this.ZIP + "'>"	
							
								tempHtml += "<strong>" + this.STORENAME+ "</strong><br />"
							
							
								tempHtml += this.STREET + ' <br />' + this.CITY + ', ' + this.STATEABBREV + ' ' + this.ZIP 
							tempHtml += "</a>"
						
							if(this.PHONE != ''){
								var thisNumber = formatPhone( ""+ this.PHONE + "");
								tempHtml += "<a href='tel:" + thisNumber + "'>" + thisNumber + "</a>"
							}
							tempHtml += '<div class="clear"></div>';
							
						}else{
							if(locationList != ''){
								locationList += ", ";
							}
							if(this.URL != ''){
								tempHtml += "<strong><a href='http://" + removeHTTP(this.URL) + "' target='_blank'>" + this.STORENAME+ "</a></strong><br />"
							}else{
								tempHtml += "<strong>" + this.STORENAME+ "</strong><br />"
							}
							
							tempHtml += this.STREET + ' <br />' + this.CITY + ', ' + this.STATEABBREV + ' ' + this.ZIP + "<br />"
						
							if(this.PHONE != ''){
								tempHtml += formatPhone( ""+ this.PHONE + "") + "<br />"
							}
							
							if(this.TWITTER != ''){
								tempHtml += '<a href="http://' + removeHTTP(this.TWITTER) + '" target="_blank"  class="twitterLink" >'
									tempHtml += '<img src="/graphics/locations/twitter_icon.png" />'
								tempHtml += '</a>';
							}
							
							if(this.FACEBOOK != ''){
								tempHtml += '<a href="http://' + removeHTTP(this.FACEBOOK) + '" target="_blank" class="facebookLink">'
									tempHtml += '<img src="/graphics/locations/facebook_icon.png" />'
								tempHtml += '</a>'
							}
							locationList += this.STOREID;
						}
						
							
						//+ "Distance: " + roundNumber( this.DISTANCE, 2 ) + " miles <br />"
						
						
					tempHtml += "</p>"
				tempHtml += "</li>"
				
				if(!mobile){
					addMarker(thisAddress, currentData);
				}
				
			  });
		});
		$('#locationList').html(tempHtml)
		$('#locationList li').bind('click', setMapCenter);
		
		if(!mobile){
			getAllLocations();
		}
		//var control = document.getElementById('mapMarkerList');
        //map.controls[google.maps.ControlPosition.LEFT_CENTER].push(control);
	}
	/***********************************
		Adds marker to map
	***********************************/
	function addMarker(address, currentData) {
		/**********************************************************************************************
			Adds new marker to the map
		**********************************************************************************************/
		
		marker = new google.maps.Marker({
			position: new google.maps.LatLng(currentData.LAT, currentData.LON)
			,map: map
			,draggable: false
			,animation: google.maps.Animation.DROP
			,title: currentData.STORENAME
			/*********** custom marker ***********/
			/***  ,icon: markerImage + iterator ***/
		});
		
		
		/**********************************************************************************************
			Adds info window to this marker 
		**********************************************************************************************/
		google.maps.event.addListener(marker, 'mouseover', (function(marker, iterator){
			track_mouseover(currentData);
			return function() {
								
				var infoWindowContent = setInfoWindowContent(currentData, address);				
				window.location.hash=iterator;
				
				infowindow.setContent(infoWindowContent);
				infowindow.open(map, marker);
				
				//$('#locationList li').removeClass('on');
				//$('#locationList li#'+iterator).addClass('on');
			}
		})(marker, iterator));
		
		google.maps.event.addListener(marker, 'mouseout', (function(marker, iterator){
			return function() {
				$('#locationList li').removeClass('on');
			}
		})(marker, iterator));
		
		google.maps.event.addListener(marker, 'click', (function(marker, iterator) {
			return function() {
				var infoWindowContent = setInfoWindowContent(currentData, address);
				window.location.hash=iterator;
				
				track_click(currentData);
				
				infowindow.setContent(infoWindowContent);
				//infowindow.pixelOffset() //in pixels from the top-center
				infowindow.open(map, marker);/**/
				//endRoute = address;
				
				
				$('#locationList li').removeClass('selected');
				$('#locationList li#'+iterator).addClass('selected');
				
				//calcRoute()
			}
		})(marker, iterator));
		
		markers[iterator] = marker;
		markers[iterator][0] = currentData;
		
		iterator++;
	}

	/***********************************
		Center the map marker that you click from the list 
	***********************************/
	function setMapCenter (){
		var thisObj = $(this);
		var thisObjId = thisObj.attr("id");
		
		var thisAddress = markers[thisObjId][0].STREET + ' ' + markers[thisObjId][0].CITY + ', ' + markers[thisObjId][0].STATEABBREV + ' ' + markers[thisObjId][0].ZIP;
		
		var infoWindowContent = setInfoWindowContent(markers[thisObjId][0], thisAddress);
		$('#locationList li').removeClass('selected');
		thisObj.addClass('selected');
		
		//set tracking on click
		track_click(markers[thisObjId][0]);
		
		//pan map to this location
		map.panTo(markers[thisObjId].position)
		
		//opens window
		infowindow.setContent(infoWindowContent);
		infowindow.open(map, markers[thisObjId]);
	}
	
	
	function setInfoWindowContent(data, address){
		var url;
		if(data.URL != ''){
			
			url = "<a class='storeName' target='_blank' href='http://" + removeHTTP(data.URL) + "'>" 
						+ data.STORENAME  
					+ "</a>" 
		}else{
			url = '<span class="storeName">' + data.STORENAME + '</span>' ;
		}
		if(data.FACEBOOK != ''){
			facebook = "<a class='facebookInfoLink' href='http://" + removeHTTP(data.FACEBOOK)  + "'  target='_blank' ><img src='/graphics/locations/facebook_icon.png' /></a>";  
		}else{
			facebook = "";
		}
		
		if(data.TWITTER != ''){
			twitter = "<a class='twitterInfoLink' href='http://" + removeHTTP(data.TWITTER)  + "'  target='_blank' ><img src='/graphics/locations/twitter_icon.png' /></a><br />";  
		}else{
			twitter = "";
		}
		
		
		var thisInfoWindowContent ="<p class='infoWindow'>" 
				thisInfoWindowContent += url 
				thisInfoWindowContent += "<br />" 
				thisInfoWindowContent += data.STREET + ' '
				thisInfoWindowContent += data.STREET2 + ' '
				thisInfoWindowContent += "<br />" 
				thisInfoWindowContent += data.CITY + ', '  
				thisInfoWindowContent += data.STATEABBREV + ' ' 
				thisInfoWindowContent += data.ZIP
				thisInfoWindowContent += "<br />" 
				if(data.PHONE != ''){
					thisInfoWindowContent += formatPhone( ""+ data.PHONE +"" )
				}
				thisInfoWindowContent += "<br />" 
				thisInfoWindowContent += facebook
				thisInfoWindowContent += twitter
				//+ data.DESCRIPTION
				thisInfoWindowContent += "<a class='getDirections' end='" + address + "' href='javascript:;'>Get Directions</a>"
			thisInfoWindowContent += "</p>"
		return thisInfoWindowContent;						
		
	}
	/*****************************************
		Converts Address to lat and lng 
	*****************************************/
	function codeAddressServer(address) {
		$.ajax({
			type: "get",
			url: "/plugins/locations/cfc/locations_Ajax.cfc",
			dataType: "json",
			async: false,
			data: {
				method: "googleGeoCoder_Ajax"
				,address: address
			},
			success: function(data){
				$('.overlay').hide();
				$('#mapDataCollector').hide();
				getLocations(data[0].LATITUDE, data[0].LONGITUDE);
			},
			error: function(data) {
				alert("Error");
			}
		});
	}
	
	
	function codeAddress(address, isReset) {
		
		var address = address;
		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				/****
				
				ERROR
				if lat or lon is empty
				
				console.log(results[0].geometry.location)  
				*****/
				popuplateManualLocation(results[0].geometry.location, isReset)
			} else {
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}
	/*****************************************
		Converts lat and lng to an Address
	*****************************************/
	function codeLatLng(latlng) {
		var input = latlng;
		var latlngStr = input.split(",",2);
		var lat = parseFloat(latlngStr[0]);
		var lng = parseFloat(latlngStr[1]);
		var latlng = new google.maps.LatLng(lat, lng);
		var response;
		geocoder.geocode({'latLng': latlng}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				if (results[1]) {
					//$('#address').val(results[1].formatted_address);
					$('.searchResults span').html( results[1].formatted_address );
					track_search(results[1].formatted_address);
					return true;
				} else {
					return("No results found");
				}
			} else {
				return("Geocoder failed due to: " + status);
			}
		});
		return true;
	}
	
	function codeAddressLatLng(LatLng){
		$.ajax({
			type: "get",
			url: "/plugins/locations/cfc/locations_Ajax.cfc",
			dataType: "json",
			async: false,
			data: {
				method: "googleGeoCoderAddress_Ajax"
				,LatLng: LatLng
			},
			success: function(data){
				$('.searchResults span').html(data[0].FORMATTED_ADDRESS);
			},
			error: function(data) {
				alert("Error");
			}
		});
	}
	/*****************************************
		get all remaining locations from database
	*****************************************/
	function getAllLocations(){
		
		$.ajax({
			type: "get"
			,url: "/plugins/locations/cfc/locations_Ajax.cfc"
			,dataType: "json"
			,data: {
				method: "getAllLocation_Ajax",
				locationList: locationList
			}
			,success: function(data) {
				//buildLocationList(data);
				$.each(data, function() {
					$.each(this, function(k, v)  {
						var currentData = this;
						var thisAddress = this.STREET + ' ' + this.CITY + ', ' + this.STATEABBREV + ' ' + this.ZIP; 
						addMarker(thisAddress, currentData)
					})
				})
				
			}
			,error: function(response) {
				alert("Error: problem loading locations");
			}
		});
		
	}
	
	
	/*****************************************
		get locations from database
	******************************************/
	function getLocations(lat, lon){ 
	
		if(mobile){
			$.ajax({
				type: "get"
				,url: "/plugins/locations/cfc/locations_Ajax.cfc"
				,dataType: "json"
				,data: {
					//method: "getClosestLocationsByAddress"
					method: "getClosestLocation_Ajax"
					,currentLat: lat
					,currentLon: lon
					,calculateDistance: true
				}
				,success: function(data) {
					buildLocationList(data);
					if($('#mapDataCollector').css('display') == 'block'){
						$('#mapDataCollector').hide();
						$('.overlay').hide();
					}
				}
				,error: function(response) {
					alert("Error: problem loading locations");
				}
			});
			
			
		}else{
			
			var latAndLng = getLatLongFromMap(initialLocation);
			
			$.ajax({
				type: "get"
				,url: "/plugins/locations/cfc/locations_Ajax.cfc"
				,dataType: "json"
				,data: {
					//method: "getClosestLocationsByAddress"
					method: "getClosestLocation_Ajax"
					,currentLat: latAndLng[0]
					,currentLon: latAndLng[1]
					,calculateDistance: true
				}
				,success: function(data) {
					/*if(ie7){
						alert(locations);
					}*/
					buildLocationList(data);
				}
				,error: function(response) {
					alert("Error: problem loading locations");
				}
			});
		}
	}
	
	function show_custom_info_window(marker) {
	
	
	}
	
	/*****************************************
		direction
	*****************************************/
	function getDirections(){
		var thisObj = $(this);
		endRoute = thisObj.attr('end');
		calcRoute();
	}
	function getCurrentAddress(){
		showPopUp('#mapDataCollector');
		var tempStart = $('#directionAddress').val();
		calcRoute(tempStart)
	}
	function calcRoute(tempStart) {
		var isValid;
		var enterAddress ;
		
		if(tempStart == undefined){
			enterAddress = $('.searchResults span').text();
			isValid = validateAddress(enterAddress);
			
			var latAndLng = getLatLongFromMap(initialLocation);
			startRoute = latAndLng[0] + ', ' + latAndLng[1];
		}else{
			enterAddress = tempStart;
			isValid = validateAddress(tempStart);
			startRoute = tempStart;
		}
		
		if( isValid ){
			displayRoute();
		}
	}
	
	function displayRoute(){
		
		var travelType = $("#travelType").val();
		
		if(parseInt( $('#directions-panel').width() ) == 0){
			
			$('#mapContainer #map #map_canvas').animate({
				width: '-=254'
			}, 500);
			
			$('#directions-panel').animate({
				width: '+=254'
			}, 600);
			
		}
		var request = {
			origin: startRoute,
			destination: endRoute,
			travelMode: google.maps.DirectionsTravelMode[travelType]
			//WALKING, DRIVING, Bicycling
		};
		
		directionsService.route(request, function(response, status) {
			if (status == google.maps.DirectionsStatus.OK) {
				directionsDisplay.setDirections(response);
			}
		});
	}
	
	function validateAddress(enterAddress){
		
		
		if( isNaN( enterAddress ) ){
			return true;
		}else{
			showPopUp('#mapDataCollector')
			var tempHtml =  '<a class="closeDirection" href="javascript:;">Close</a>'
							+'<p class="enterStartRoute">'
								+'<strong>Directions to:<br /><span class="endRoute">' + endRoute 
								+ '</span><br />'
								+ 'Please enter your address.</strong>'
							+ '</p>'	
							+'<form action="#" onsubmit="getCurrentAddress(); return false">'
								+'<div >'
									+'<input type="text" name="directionAddress" class="mapSearchBox" id="directionAddress"  />'
									+'<input type="image" src="/graphics/locations/shim.gif" class="searchBTN" value="Go!" />'
								+'</div>'
							+'</form>';
			$('#mapDataCollector').html(tempHtml);
			return false;
		}
	}
	/*****************************************
		Reset Map
	*****************************************/
	function closeMap(){
		if(!mobile){
			$('#container').show();
			setMapSize(resize = false);
			$('#directions-panel').css('width', '0px')
			//$('#mapContainer #map #map_canvas').css('width', '815px')
			$('#directions-panel').html('');
			markers = [];
			marker;
			iterator = 1;
			locationList = '';
			$('#mapDataCollector').hide();
			$('#mapContainer').hide();
			$('.overlay').hide();
			$('#locationList').html('');
			$('.searchResults span').html('');
			$('#mapDataCollector').html('<p class="fetching">'
											+ '<strong>Fetching your location please wait.</strong>'
											+ '<img src="/graphics/ajax_loading.gif" width="41" height="39">'
										+ '</p>')
		}else{
			$('#resultsContainer').hide();
			$('#container').show();
			$('#locationList').html('');
			viewport = document.querySelector("meta[name=viewport]");
			viewport.setAttribute('content', 'width = 1024, initial-scale = 10, maximum-scale = 3.0, user-scalable = 1');
			updateLayout;
		}
	}
	
	function resetMap(){
		if(!mobile){
			setMapSize(resize = false);
			$('#directions-panel').css('width', '0px')
			//$('#mapContainer #map #map_canvas').css('width', '815px')
			$('#directions-panel').html('');
			markers = [];
			marker;
			iterator = 1;
			locationList = '';
			initialize();
		}else{
			$('.updateIphoneSearch').hide();
		}
		manuallyGeoLocation(isReset = true);
	}


	function getLatLongFromMap(obj){
		
		//var i = 1;
		var latLng = new Array();
		
		var str = obj.toString();
		var str = str.replace('(', '').replace(')', '');
		var substr = str.split(', ');
		latLng[0] =substr[0];
		latLng[1] =substr[1] ;
		
		/*
		for (var key in obj) {
			if(i == 1){
				latLng[0] = obj[key]
			}else if( i == 2){
				latLng[1] = obj[key]
				break;
			}
			i++;
		}*/
		//alert(latLng);
		return latLng;
	}
	/*****************************************
		Google Analytics
	******************************************/
	
	
	
	/*****************************************
		Track Search
	******************************************/
	function track_search(val){
		_gaq.push([
			'_trackEvent'
			, 'Search Terms'
			, 'Search'
			, val
		]);
	}
	
	/*****************************************
		Track marker clicks
	******************************************/
	function track_click(currentData){
		_gaq.push([
			'_trackEvent'
			, 'Marker'
			, 'Click'
			, currentData.STORENAME
		]);
	}
	
	
	
	
	
	
	/*****************************************
		Track marker mouseover
	******************************************/
	function track_mouseover(currentData){
		_gaq.push([
			'_trackEvent'
			, 'Marker'
			, 'mouseover'
			, currentData.STORENAME
		]);
	}
	
	
	
	
	/**************************************
		utils
	***************************************/
	
	/*****************************
		removes http:// form all links
	*****************************/
	function removeHTTP(urlLink){
		var str = urlLink;
		var str = str.split('http://');
		if(str[1] == undefined){
			str[1] = urlLink
		}
		return str[1];

	}
	function roundNumber(num, dec) {
		var result = Math.round( num * Math.pow( 10, dec ) ) / Math.pow( 10, dec );
		return result;
	}
	/************************************
		set Screen Size
	************************************/
	function setMapSize(resize){
		////////// set the document to the screen size
		
		$('#mapContainer').width( $(window).width() - 8);
		$('#mapContainer').height( $(window).height() -30 );
		
		if(resize){
			$('#map_canvas').width( ( ( $('#mapContainer').width() - $('#mapMarkerList').width() ) - $('#directions-panel').width() ) - 23 )
		}else{
			$('#map_canvas').width( ( $('#mapContainer').width() - $('#mapMarkerList').width() ) - 23 )
		}
		
		$('#locationList').height( ( $('#mapContainer').height() - $('#leftSideHeader').height() ) - 30 );
		$('#map_canvas').height( $('#mapContainer').height() - 23 );
		//$('#mapDataCollector').center();
	}
	/********************************
		format phone number
	***********************************/
	function formatPhone(currentNumber) {
		var phonenum = convertStringToPhone(currentNumber)
		var regexObj = /^(?:\+?1[-. ]?)?(?:\(?([0-9]{3})\)?[-. ]?)?([0-9]{3})[-. ]?([0-9]{4})$/;
		if (regexObj.test(phonenum)) {
			var parts = phonenum.match(regexObj);
			var phone = "";
			if (parts[1]) { phone += "(" + parts[1] + ") "; }
			phone += parts[2] + "-" + parts[3];
			return phone;
		}
		else {
			//invalid phone number
			return phonenum;
		}
	}
	/********************************
		removes all chars that are not numbers
	***********************************/
	function convertStringToPhone(phoneNum){
		var txt = phoneNum
		var numb = txt.match(/\d/g);
		var number = '';
		for( i = 0; i < numb.length; i++){
			number += numb[i]
			
		}
		return number
	}
	
	
	
	
	function showPopUp(popUpName){
		var thisObj 	= $(this);
		var popUp		= popUpName;
		var isVisible   = $(popUp).css("display");
		
		if(isVisible == 'block'){
			$(popUp).hide();
			//$('.overlay').hide();
		}else{
			
			if(mobile){
				$(popUp).css("left", (($(window).width() - $(popUp).outerWidth()) / 2) + $(window).scrollLeft() + "px");
				$(popUp).show()
				$('.overlay').show();
			}else{
				$(popUp).show();
				$('.overlay').FullScreen().show();
			}
		}
		
	}

	jQuery.fn.center = function () {
		//this.css("position","absolute");
		this.css("top", ( ( $(window).height() - this.outerHeight() ) / 2 ) + $(window).scrollTop() + "px");
		this.css("left", ( ( $(window).width() - this.outerWidth() ) / 2 ) + $(window).scrollLeft() + "px");
		return this;
	}
	jQuery.fn.FullScreen = function () {
		this.css("height", $(document).height() + "px");
		this.css("width", $(document).width() + "px");
		return this;
	}
	
	


