<?php
/*------------------------------------------------------------------------
# mod_servicearea
# author    PluginValley - developer@PluginValley.com
# copyright Copyright (C) 2012 PluginValley.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.PluginValley.com
# Support:  Please leave your comments at product page of this extension - PluginValley.com
-------------------------------------------------------------------------*/
// no direct access
defined('_JEXEC') or die('');
  
	$baseurl 		=	 JURI::base( );   
   
	// get a parameter from the module's configuration
	$width 			= 	$params->get('width', '400px');
	$height 		= 	$params->get('height', '400px');
	$mapStyle 		= 	$params->get('mapstyle', 'padding:5px; border:4px solid #C9C9C9;  margin-top:10px;');
	$lat 			= 	$params->get('lat', '34.147896');
	$lon 			= 	$params->get('lon', '-118.428632');
	$pin 			= 	$params->get('pin', 'modules/mod_servicearea/images/pin1.png');
	$companytitle 	= 	$params->get('companytitle', 'Your Company Name');
	$addressline1 	= 	$params->get('addressline1', 'Your address line 1');
	$addressline2 	= 	$params->get('addressline2', 'Your address line 2');
	$phonefax	 	= 	$params->get('phonefax', 'Your Phone Fax');
	$miles		 	= 	$params->get('miles', '1');
	$distance		= 	$params->get('distance', '50');
	$strokecolor	= 	$params->get('strokecolor', '#5DC30C');
	$strokeopacity	= 	$params->get('strokeopacity', '0.6');
	$strokeweight	= 	$params->get('strokeweight', '3');
	$fillcircle		= 	$params->get('fillcircle', '#0C3A6D');
	$fillopacity	= 	$params->get('fillopacity', '0.6');
	$maptype		= 	$params->get('maptype', 'ROADMAP');
	$mapzoom		= 	$params->get('mapzoom', '8');
	
  $document = &JFactory::getDocument();
			$document->addScript( 'http://maps.google.com/maps/api/js?sensor=false' ); ?>
  
 <script type="text/javascript">
 // stores
var companycenter = new google.maps.LatLng(<?php echo $lat;?>, <?php echo $lon;?>);

// Create an object containing LatLng, population.

var citymap = {};
citymap['companycenter'] = {
  center: companycenter,
};


var cityCircle;

function initialize() {
  var mapOptions = {
    zoom: <?php echo $mapzoom; ?>,
    center: companycenter,
    mapTypeId: google.maps.MapTypeId.<?php echo $maptype; ?>
  };

  var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

	// marker	
	var imageMerkez = '<?php echo $pin; ?>';
	var marker = new google.maps.Marker({
      position: companycenter,
      map: map,
	  icon: imageMerkez,
	  title:"<?php echo $companytitle; ?>"
	});

	// Creating an InfoWindow object
	var contentcompanycenter = 	'<span style="color:#137AB9; font-weight:bold;"><?php echo $companytitle; ?></span><br/>'+
								'<?php echo $addressline1; ?><br />'+
								'<?php echo $addressline2; ?><br />'+
								'<?php echo $phonefax; ?><br/>';
	var infowindow = new google.maps.InfoWindow({
	  content: contentcompanycenter
	});
	
	// open default
	infowindow.open(map, marker);

	// open when marker click
	google.maps.event.addListener(marker, 'click', function() {
	  infowindow.open(map, marker);
	});

  for (var city in citymap) {
    // Construct the circle for each value in citymap. We scale population by 20.
    var populationOptions = {
      strokeColor: "<?php echo $strokecolor; ?>",
      strokeOpacity: <?php echo $strokeopacity; ?>,
      strokeWeight: <?php echo $strokeweight; ?>,
      fillColor: "<?php echo $fillcircle; ?>",
      fillOpacity: <?php echo $fillopacity; ?>,
      map: map,
      center: citymap[city].center,
      radius: <?php if ( $miles ) { echo ( $distance * 1000 ); } else { echo ( $distance * 1000 * 0.6214  ); } ?>
    };
    cityCircle = new google.maps.Circle(populationOptions);
  } 
}
</script>
  <script type="text/javascript">window.onload = initialize;</script>
  <div id="map_canvas" style="width:<?php echo $width;?>; height:<?php echo $height;?>; <?php echo $mapStyle;?>"></div>