	/*
		*
		* 	Author: Ark Rozycki
	*/
	
	// init the application, create the google map, listen for loaded, load the initial markers
	function init(){
		// load the query string params to array
		propMapr.queryString = utility.queryStringtoArray();
		
		// load the cookie mgr array for easy access
		cookieMgr.setCookie();
		
		// load the google map
		propMapr.loadGoogleMap();
		
		// listen for the map to load before we continue loading everything
		var listener = google.maps.event.addListener(propMapr.map, 'tilesloaded', function(){
			// assign the map to the marker manager
			// propMapr.mapMgr = new MarkerManager(propMapr.map);

			// remove the loaded listener
			google.maps.event.removeListener(listener);
			
			// check cookies for saved filters
			if(cookieMgr.cookie['search']){
				// setup the global cookie store
				cookieMgr.setCookie();
				
				// configure the filter form with the cookie data
				propMapr.loadFormData();

				// cookies found, get the properties for conditions if we aren't asking for a URL param request
				if(!propMapr.queryString['iid'])
					propMapr.runPropertySearch();
					
			} else {
				// no cookie filters found display the welcome screen
				winMgr.center('#welcome');
			}
			
			/*
			// configure a listener to listen for a zoom change
			google.maps.event.addListener(propMapr.map, 'zoom_changed', function() {
				// if the zoom is greater than 7 we need to get the properties
				if(propMapr.isZoomed == false && propMapr.map.getZoom() > 8){
					propMapr.getProperties();	
					propMapr.isZoomed = true;			
				} 
				
				if(propMapr.map.getZoom() < 8)
					propMapr.isZoomed = false;
	
			});
			*/
			// loads either instance or property detail layouts
			propMapr.loadURLRequests();
			
		});

		// we are done loading, set the initalLoad to true
		propMapr.initialLoad = true;
		
		$("#largeImageLink").click(function() {
			// TODO: Fix this reference
			var ei = [];
			for(var i = 0; i < propMapr.arrCurrentImages.length; i++)
				ei.push(propMapr.arrCurrentImages[i]);
			$.fancybox(
				ei, 
				{
					'width': 1000,
					'padding': 0,
					'type': 'image',	
					'transitionIn': 'elastic',
					'transitionOut': 'elastic',
					'easingIn': 'easeOutBack',
					'easingOut': 'easeInBack',
					'autoScale': true
				}
			);
		});
	}
	
	$(document).ready(function(){
	   	
	 });


	
/*

	// global variables
	var dataURL = 'http://default.proptrackr.com/pt-app/PropMapr/PropMapr';
	var map;
	var map_mgr = null;
	var movement;
	var currentBoundaries;
	var dh = Ext.DomHelper;
	var arrFilters = [];
	var filtersShowing = false;
	var initialLoad = false;
	var zoomed = false;
	
	// init the application, create the google map, listen for loaded, load the initial markers
	function init(){
				
		// create the google maps, assign it to the canvas, center coordinates are about middle of country
		map = new google.maps.Map(
			document.getElementById("map_canvas"), 
			{
				zoom: 5,
				center: new google.maps.LatLng(37.0625,-95.677068),
				mapTypeId: google.maps.MapTypeId.TERRAIN,
				streetViewControl: true
				// ROADMAP
			}
		);
		
		// listen for the map to load before we get the initial markers
		var listener = google.maps.event.addListener(map, 'tilesloaded', function(){
			// assign the map to the marker manager
			map_mgr = new MarkerManager(map);
			
			// set the initial state of the filters and load the state map
			setFilters(document.filterForm);
			initialLoad = true;
			
			// remove the loaded listener
			google.maps.event.removeListener(listener);
			
			google.maps.event.addListener(map, 'zoom_changed', function() {
				if(map.getZoom() > 7){
					getProperties();	
					zoomed = true;			
				}
			  });
		});
		
	}


	// get the initial properties by state and the count for each state
	function setMarkersStateCount(){
		if(initialLoad){			
			map_mgr.clearMarkers();
		}
		Ext.Ajax.request({
			url: 'proxy.php?url=' + dataURL + '/getPropertiesByState/' + getfilters(),
			method: 'GET',
			success: function(response, opts) {
				var obj = Ext.util.JSON.decode(response.responseText);
				
				// loop through the response and create markers for each state with numbers using the google charts API
				// using an array to store them all before adding them to the marker manager
				var markers = [];
				for (var intIndex = 0; intIndex < obj.contents.propsByState.length; intIndex++){
					if(obj.contents.propsByState[intIndex]['Latitude'] != '' && obj.contents.propsByState[intIndex]['Longitude'] != ''){
						markers.push(
							new google.maps.Marker({
								clickable: false,
								map: map,
								visible: true,
								icon: 'http://chart.apis.google.com/chart?chst=d_map_spin&chld=1.0|0|F8F8F8|10|b|'+obj.contents.propsByState[intIndex]['state']+'|'+obj.contents.propsByState[intIndex]['cnt'],
								position: new google.maps.LatLng(obj.contents.propsByState[intIndex]['Latitude'],obj.contents.propsByState[intIndex]['Longitude'])
							})
						);
					}
				}
				map_mgr.addMarkers(markers, 5, 7);
			},
			failure: function(response, opts) {
			}
		});
		
		if(filtersShowing)
			hideFilters();
	}
	
	// get property by state
	function getProperties(){
		// display a please wait loading message
		displayLoading();
		
		// send the ajax request for get properties
		Ext.Ajax.request({
			url: 'proxy.php?url=' + dataURL + '/getProperties/' + getfilters(),
			method: 'GET',
			success: function(response, opts) {
				var obj = Ext.util.JSON.decode(response.responseText);
				var markers = [];
				for (var intIndex = 0; intIndex < obj.contents.props.length; intIndex++){
					markers.push( addMarker(obj.contents.props[intIndex]['InstanceID'], obj.contents.props[intIndex]['id'], obj.contents.props[intIndex]['lat'], obj.contents.props[intIndex]['lng']));
				}
				map_mgr.addMarkers(markers, 8);
				//configBoundaryListener();
			
				// the markers are now loaded, lets hide the loading pop up
				hideLoading();
			},
			failure: function(response, opts) {
				hideLoading();
			}
		});
		
		return;
	}
	
	// create a marker and a click event for the marker
	function addMarker(inst, pid, lat, lng){
		var marker = new google.maps.Marker({
			instance: inst,
			pid: pid,
			clickable: true,
			map: map,
			visible: true,
			position: new google.maps.LatLng(lat, lng)
		});
		
		// create the listener for the marker click
		google.maps.event.addListener(marker, 'dblclick', function() {
			// upon a click the property details are requested
			getProperty(marker.instance, marker.pid);
		});
		return marker;
	}
	
	// gets the property details from the server
	function getProperty(instance, id){
		Ext.Ajax.request({
			url: 'proxy.php?url=' + dataURL + '/getProperty/' + instance + '/' + id + '/',
			method: 'GET',
			success: function(response, opts) {
				var obj = Ext.util.JSON.decode(response.responseText);
				
				// show the property data received in a nice pop up window
				showProperty(instance, id, obj.contents.property[0], obj.contents.photos);
			},
			failure: function(response, opts) {
				// TODO:
			}
		});
	}
	
	// shows the property details for the marker clicked on by the user
	function showProperty(instanceID, propertyID, objProp, objPhotos){
		// center the window
		Ext.fly('objProperty').setStyle( {display : 'block'} );
		var x = getScreenX() - 250;
		var y = getScreenY() - 250;
		Ext.fly('objProperty').setXY([x, y]);
		
		// center the window
		Ext.fly('propClose').setStyle( {display : 'block'} );
		var x = getScreenX() + 150;
		var y = getScreenY() - 265;
		Ext.fly('propClose').setXY([x, y]);
		
		// format the property type
		var propType = '';
		if(objProp.propertyType != ''){
			if(objProp.propertyType == 'Residential')
				propType = (objProp.residenceType != '') ? objProp.residenceType : 'Residential';
			else
				propType = (objProp.commercialType != '') ? objProp.commercialType : 'Commercial';
		}
		
		// manage the property photos, the first one is the main or initial photo
		var mainPhoto = '<img src="/res/images/noPhoto.png" />';
		var thumbPhotos = '';
		for (var intIndex = 0; intIndex < objPhotos.length; intIndex++){
			if(intIndex == 0)
				mainPhoto = '<img id="mainPropPhoto" src="http://default.proptrackr.com/res/propertyPhotos/'+instanceID+'/'+objPhotos[intIndex].filename+'" height="200" width="300"/>';
			thumbPhotos += '<a href="javascript://" onclick="viewPhoto(this.childNodes[0].src);" ><img src="http://default.proptrackr.com/res/propertyPhotos/'+instanceID+'/thumb_'+ objPhotos[intIndex].filename +'" width="40" height="40"/></a>';
		}
		
		// create the HTML for the property details
		var HTML = 	'<div class="pdAddress">' + objProp.address + '<br/>' +
						objProp.city + ', ' + objProp.state + ' ' + objProp.zip + 
					'</div>' +							
					'<div class="pdLeft">'+
						'<div class="pdMainPhoto">' + mainPhoto + '</div>'+
						'<div class="pdTools">' +
							'<div class="pdClickTools" onClick="displayStreetView('+objProp.lat+','+objProp.lng+');">Street View</div>' +
						'</div>' +
						'<div class="pdPhotoThumbs">'+thumbPhotos+'</div>'+
					'</div>' +
					'<div class="pdDetails">'+
						'<table class="pdTbl" border="0" cellpadding="0" cellspacing="0">';
						HTML += (objProp.currentListingPrice && objProp.currentListingPrice != 0) ? '<tr><td>Price</td><td>' + CurrencyFormatted(objProp.currentListingPrice) + '</td></tr>' : '';
						HTML += (propType) ? '<tr><td>Type</td><td>' + propType + '</td></tr>' : '';
						HTML += (objProp.bedrooms && objProp.bedrooms != 0) ? '<tr><td>Beds</td><td>' + objProp.bedrooms + '</td></tr>' : '';
						HTML += (objProp.bathrooms && objProp.bathrooms != 0) ? '<tr><td>Baths</td><td>' + objProp.bathrooms + '</td></tr>' : '';
						HTML += (objProp.garage && objProp.garage != 0) ? '<tr><td>Garage</td><td>' + objProp.garage + '</td></tr>' : '';
						HTML += (objProp.squarefeet  && objProp.squarefeet != 0) ? '<tr><td>Fin Sqft</td><td>' + objProp.squarefeet + '</td></tr>' : '';
						HTML += (objProp.lotSize && objProp.lotSize != 0) ? '<tr><td>Lot Size</td><td>' + objProp.lotSize + '</td></tr>' : '';
						HTML += (objProp.basementSQFT && objProp.basementSQFT != 0) ? '<tr><td>Basement</td><td>' + objProp.basementSQFT + '</td></tr>' : '';
						HTML += (objProp.yearBuilt && objProp.yearBuilt != 0) ? '<tr><td>Year Built</td><td>' + objProp.yearBuilt + '</td></tr>' : '';
						HTML += (objProp.MLS && objProp.MLS != 0) ? '<tr><td>MLS</td><td>' + objProp.MLS + '</td></tr>' : '';
						HTML += '</table>';
						HTML += '<div class="pdReqInfo" onClick="displayMoreInfo('+instanceID+', '+propertyID+');">Request More Info</div>';
						HTML += '<div class="pdInstance">'+
									'<a href="http://' + objProp.InstanceID + '.myproptrackr.com">'+ objProp.Company +'</a>' +
									'<div class="pdPhoneEmail">'+ objProp.ContactPhone + ' &nbsp; ' + '<a href="mailto:'+ objProp.CustomerServiceEmail +'">'+ objProp.CustomerServiceEmail +'</a></div>' +
									'</div>' +					
					'</div>';
		// push out the HTML to the DIV
		dh.overwrite('objPropDetails', HTML);
	}
	
	// open the streetview and set to the passed in coordinates
	function displayStreetView(lat,lng){
		// center the window
		Ext.fly('objStreetView').setStyle( {display : 'block'} );
		var x = getScreenX() - 325;
		var y = getScreenY() - 275;
		Ext.fly('objStreetView').setXY([x, y]);
		
		// center the window
		Ext.fly('objStreetViewClose').setStyle( {display : 'block'} );
		var x = getScreenX() + 200;
		var y = getScreenY() - 290;
		Ext.fly('objStreetViewClose').setXY([x, y]);
		
		var sv = new google.maps.StreetViewPanorama(
			document.getElementById("objStreetView"), 
			{
		  		position: new google.maps.LatLng(lat,lng),
		  		pov: {
		    		heading: 90,
		    		pitch: 10,
		    		zoom: 1
				}
		  	}
		);
		console.log(sv);
		// load the street view in the div
		map.setStreetView(sv);
	}
	
	// hide the street view pop up
	function hideStreetView(){
		Ext.fly('objStreetView').setStyle( {display : 'none'} );
		Ext.fly('objStreetViewClose').setStyle( {display : 'none'} );
	}
	
	// hide the property pop up window
	function hideProperty(){
		Ext.fly('objProperty').setStyle( {display : 'none'} );
		Ext.fly('propClose').setStyle( {display : 'none'} );
	}
	
	function viewPhoto(src){
		document.getElementById('mainPropPhoto').src = src.replace('thumb_', '');
	}
	
	// display the more information form
	function displayMoreInfo(instance, propertyID){
		// if the user is cookied do something, not sure what yet
		
		// center the window
		Ext.fly('objMoreInfo').setStyle( {display : 'block'} );
		var x = getScreenX() - 125;
		var y = getScreenY() - 175;
		Ext.fly('objMoreInfo').setXY([x, y]);
		
		Ext.fly('moreInfoClose').setStyle( {display : 'block'} );
		var x = getScreenX() + 25;
		var y = getScreenY() - 190;
		Ext.fly('moreInfoClose').setXY([x, y]);
		
	}
	
	// hide the more info box
	function hideMoreInfo(instance, propertyID){
		Ext.fly('objMoreInfo').setStyle( {display : 'none'} );
		Ext.fly('moreInfoClose').setStyle( {display : 'none'} );
	}
	
	// get cookie and populate filters

	// set cookie variables
	
	// display the loading properties window
	function displayLoading(){
		Ext.fly('objLoading').setStyle( {display : 'block'} );
		var x = getScreenX() - 100;
		var y = getScreenY() - 50;
		Ext.fly('objLoading').setXY([x, y]);
	}
	
	// hide the loading properties window
	function hideLoading(){
		Ext.fly('objLoading').setStyle( {display : 'none'} );
	}

	// display filters popup
	function displayFilters(){
		filtersShowing = true;
		Ext.fly('objFilters').setStyle( {display : 'block'} );
		var x = getScreenX() - 100;
		var y = getScreenY() - 200;
		Ext.fly('objFilters').setXY([x, y]);
		
		Ext.fly('filterClose').setStyle( {display : 'block'} );
		var x = getScreenX() + 80;
		var y = getScreenY() - 215;
		Ext.fly('filterClose').setXY([x, y]);
	}
	
	// filter the properties with the defined params
	function setFilters(filters){
		// clear the existing markers from the manager, and get the new state ones
		
		arrFilters['state'] = filters['state'].value;
		arrFilters['priceLow'] = filters['priceLow'].value;
		arrFilters['priceHigh'] = filters['priceHigh'].value;
		arrFilters['sqftLow'] = filters['sqftLow'].value;
		arrFilters['sqftHigh'] = filters['sqftHigh'].value;
		arrFilters['bedsLow'] = filters['bedsLow'].value;
		arrFilters['bedsHigh'] = filters['bedsHigh'].value;
		arrFilters['bathsLow'] = filters['bathsLow'].value;
		arrFilters['bathsHigh'] = filters['bathsHigh'].value;
		arrFilters['garageLow'] = filters['garageLow'].value;
		arrFilters['garageHigh'] = filters['garageHigh'].value;
		
		setMarkersStateCount();
		
		// if they are already zoomed, get the zoom level properties too
		if(map.getZoom() > 7 || zoomed){
			getProperties();				
		}
		
		// check the zoom level, and get the individual properties at filter prefs too
		return false;
	}
	
	// get the filters array
	function getfilters(){
		return arrFilters['state'] + '/' +
				arrFilters['priceLow'] + '/' +
				arrFilters['priceHigh'] + '/' +
				arrFilters['sqftLow'] + '/' +
				arrFilters['sqftHigh'] + '/' +
				arrFilters['bedsLow'] + '/' +
				arrFilters['bedsHigh'] + '/' +
				arrFilters['bathsLow'] + '/' +
				arrFilters['bathsHigh'] + '/' +
				arrFilters['garageLow'] + '/' +
				arrFilters['garageHigh'] + '/';
	}

	// hide the filter window popup
	function hideFilters(){
		filtersShowing = false;
		Ext.fly('objFilters').setStyle( {display : 'none'} );
		Ext.fly('filterClose').setStyle( {display : 'none'} );
	}

	// find center of screen X-axis
	function getScreenX(){
		return Ext.fly('body').getRight() / 2;
	}

	// find center of Y-axis
	function getScreenY(){
		return Ext.fly('body').getBottom() / 2;
	}
	
	// format currency
	function CurrencyFormatted(strValue)
	{
		strValue = strValue.toString().replace(/\$|\,/g,'');
		dblValue = parseFloat(strValue);

		blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
		dblValue = Math.floor(dblValue*100+0.50000000001);
		intCents = dblValue%100;
		strCents = intCents.toString();
		dblValue = Math.floor(dblValue/100).toString();
		if(intCents<10)
			strCents = "0" + strCents;
		for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
			dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
			dblValue.substring(dblValue.length-(4*i+3));
		return (((blnSign)?'':'-') + '$' + dblValue);
	}



*/


