// JavaScript Document


jQuery.GoogleMap = {
	
	map : '',
	zoom : 13,
	marker : true,
	controls : 'none',
	overlay: false,
	scale : true,
	type : 'map',
	el : '',
	streetview : '',
	
	getLatLong: function(lat, long){
		var LatLng = new google.maps.LatLng(lat, long);
		return LatLng;
	},
	
	geocode: function(address, func){
		new GClientGeocoder().getLatLng(address, func);
	},
	
	init: function(el, location, type){
		jQuery.GoogleMap.type = type;
		jQuery.GoogleMap.el = el;
		jQuery.GoogleMap.map = new google.maps.Map2( el );
		if( typeof(location) == 'string' ){
			jQuery.GoogleMap.geocode(location, jQuery.GoogleMap.addMap);
		}else if( typeof(location == 'array') ){
			jQuery.GoogleMap.addMap( jQuery.GoogleMap.getLatLong( location[0], location[1] ) );	
		}else{
			jQuery.GoogleMap.addMap(location);	
		}
	},
	
	addMap: function(point){
		if( point ){
			if( jQuery.GoogleMap.type == 'map' ){
				jQuery.GoogleMap.map.setCenter(point, jQuery.GoogleMap.zoom);
				jQuery.GoogleMap.addMarker(point);
			}else if( jQuery.GoogleMap.type == 'streetview'){
				panoramaOptions = { latlng:point };
				jQuery.GoogleMap.streetview = new GStreetviewPanorama(jQuery.GoogleMap.el, panoramaOptions);
			}
		}
	},
	
	addMarker: function(point){
		if( jQuery.GoogleMap.marker === true ){
			this.map.addOverlay(new GMarker( point, { clickable : false } ) )
		}
	},
	
	addControls: function(){
		if( jQuery.GoogleMap.controls != 'none'){
			switch(jQuery.GoogleMap.controls){
				case "basic" :
					jQuery.GoogleMap.map.addControl( new GSmallZoomControl3D() );
					break;
				case "reduced" :
					jQuery.GoogleMap.map.addControl( new GSmallMapControl() );
					jQuery.GoogleMap.map.addControl( new GMapTypeControl() );
					break;
				case "full" :
					jQuery.GoogleMap.map.addControl( new GLargeMapControl3D() );
					jQuery.GoogleMap.map.addControl( new GMapTypeControl() );
					break;
			}
			if( jQuery.GoogleMap.overlay ) this.map.addControl( new GOverviewMapControl() );
			if( jQuery.GoogleMap.scale ) this.map.addControl( new GScaleControl() );
		}
	}
}

jQuery.Streetview = {
	
	map : '',
	zoom : 13,
	marker : true,
	controls : 'none',
	overlay: false,
	scale : true,
	type : 'map',
	el : '',
	streetview : '',
	
	getLatLong: function(lat, long){
		var LatLng = new google.maps.LatLng(lat, long);
		return LatLng;
	},
	
	geocode: function(address, func){
		new GClientGeocoder().getLatLng(address, func);
	},
	
	init: function(el, location, type){
		jQuery.Streetview.type = type;
		jQuery.Streetview.el = el;
		jQuery.Streetview.map = new google.maps.Map2( el );
		if( typeof(location) == 'string' ){
			jQuery.Streetview.geocode(location, jQuery.Streetview.addMap);
		}else if( typeof(location == 'array') ){
			jQuery.Streetview.addMap( jQuery.Streetview.getLatLong( location[0], location[1] ) );	
		}else{
			jQuery.Streetview.addMap(location);	
		}
	},
	
	addMap: function(point){
		if( point ){
			var POV = {yaw:45, pitch:-10};
			var features = {
				streetView: true,
				userPhotos: false
		  	};
			var panoramaOptions = { latlng:point, pov:POV, feature:features };
			jQuery.Streetview.streetview = new GStreetviewPanorama(jQuery.Streetview.el, panoramaOptions);
		}
	},
	
	addMarker: function(point){
		if( jQuery.Streetview.marker === true ){
			this.map.addOverlay(new GMarker( point, { clickable : false } ) )
		}
	},
	
	addControls: function(){
		if( jQuery.Streetview.controls != 'none'){
			switch(jQuery.Streetview.controls){
				case "basic" :
					jQuery.Streetview.map.addControl( new GSmallZoomControl3D() );
					break;
				case "reduced" :
					jQuery.Streetview.map.addControl( new GSmallMapControl() );
					jQuery.Streetview.map.addControl( new GMapTypeControl() );
					break;
				case "full" :
					jQuery.Streetview.map.addControl( new GLargeMapControl3D() );
					jQuery.Streetview.map.addControl( new GMapTypeControl() );
					break;
			}
			if( jQuery.Streetview.overlay ) this.map.addControl( new GOverviewMapControl() );
			if( jQuery.Streetview.scale ) this.map.addControl( new GScaleControl() );
		}
	}
}


jQuery.fn.googleMap = function( location ){
	jQuery.GoogleMap.init(this[0], location, 'map');	
}

jQuery.fn.streetview = function( location ){
	jQuery.Streetview.init( this[0], location, 'streetview' );	
}
