
/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.X
 *	LICENSE: FL0M2SG681CQ - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Pets Classifieds
 *	DOMAIN: pupsnshop.com
 *	FILE: LIB.JS
 *
 *	The software is a commercial product delivered under single, non-exclusive, 
 *	non-transferable license for one domain or IP address. Therefore distribution, 
 *	sale or transfer of the file in whole or in part without permission of Flynax 
 *	respective owners is considered to be illegal and breach of Flynax License End 
 *	User Agreement. 
 *
 *	You are not allowed to remove this information from the file without permission
 *	of Flynax respective owners.
 *
 *	Flynax Classifieds Software 2014 |  All copyrights reserved. 
 *
 *	http://www.flynax.com/
 *
 ******************************************************************************/

var streetViewInit = function(mode, location) {
	if ( mode == 'direct' ) {
		location = location.split(",");
		
		var point = new google.maps.LatLng(location[0], location[1]);
		var streetViewService = new google.maps.StreetViewService();
		var STREETVIEW_MAX_DISTANCE = 50; // in meters
	
		streetViewService.getPanoramaByLocation(point, STREETVIEW_MAX_DISTANCE, function (streetViewPanoramaData, status) {
			if ( status === google.maps.StreetViewStatus.OK ) {
				var options = {
					position: point
				};
				
				var panorama = new google.maps.StreetViewPanorama(document.getElementById('street_view'), options);
			}
			else {
				$('#street_view').hide();
				$('#no_street_view').fadeIn();
			}
		});
	}
	else {
		var geocoder = new google.maps.Geocoder();
		
		geocoder.geocode( {'address': location}, function(results, status) {
			if ( status == google.maps.GeocoderStatus.OK ) {
				var point = results[0].geometry.location.lat()+','+results[0].geometry.location.lng();
				streetViewInit('direct', point);
			}
			else {
				$('#street_view').hide();
				$('#no_street_view').fadeIn();
			}
		});
	}
}