<?php

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport('joomla.application.component.view');

class fabrikViewGooglemap extends JView
{
	var $_isMambot = null;

	function display($tmpl = 'default')
	{
		FabrikHelperHTML::slimbox();
		$document 		=& JFactory::getDocument();
		FabrikHelperHTML::packageJS();
		$usersConfig 	= &JComponentHelper::getParams('com_fabrik');
		$model				= &$this->getModel();
		$model->setId(JRequest::getVar('id', $usersConfig->get('visualizationid', JRequest::getInt('visualizationid', 0))));
		$this->row 		=& $model->getVisualization();
		$model->setTableIds();

		$js = $model->getJs();
		$this->txt = $model->getText();
		$this->params =& $model->getParams();

		$params =& $model->getPluginParams();
		$this->assignRef('params', $params);
		$tmpl = $params->get('fb_gm_layout', $tmpl);
		$tmplpath = COM_FABRIK_FRONTEND.DS.'plugins'.DS.'visualization'.DS.'googlemap'.DS.'views'.DS.'googlemap'.DS.'tmpl'.DS.$tmpl;
		FabrikHelperHTML::packageJS();
		FabrikHelperHTML::script('table.js', 'media/com_fabrik/js/', true);

		if ($params->get('fb_gm_center') == 'userslocation') {
			$document->addScript('http://code.google.com/apis/gears/gears_init.js');
			FabrikHelperHTML::script('geo.js', 'components/com_fabrik/libs/geo-location/');
		}

		$this->get('PluginJsClasses');
		$tableplugins = "window.addEvent('domready', function(){\n"
		.$this->get('PluginJsObjects')
		."\n});";
		FabrikHelperHTML::addScriptDeclaration($tableplugins);
		JHTML::stylesheet('table.css', 'media/com_fabrik/css/');
		global $ispda;
		if ($ispda == 1) { //pdabot
		  $template = 'static';
		  $this->assign('staticmap', $this->get('StaticMap'));
		} else {
			$document->addScript('http://maps.google.com/maps?file=api&amp;v=2&amp;key=' . $this->params->get('fb_gm_key'));

			FabrikHelperHTML::script('googlemap.js', 'components/com_fabrik/plugins/visualization/googlemap/', true);

			if($this->params->get('fb_gm_clustering') == 1) {
				FabrikHelperHTML::script('ClusterMarker-uncompressed.js', 'components/com_fabrik/libs/googlemaps/clustermarker/', true);
			}else if ($this->params->get('fb_gm_clustering') == 2) {
				FabrikHelperHTML::script('markerclusterer.js', 'components/com_fabrik/libs/googlemaps/markerclusterer/1.0/src/', true);
			} else {
				FabrikHelperHTML::script('markermanager.js', 'components/com_fabrik/libs/googlemaps/', true);
			}
			FabrikHelperHTML::addScriptDeclaration($js);
			$ab_css_file = $tmplpath.DS.'template.css';

			if (file_exists($ab_css_file))
			{
				JHTML::stylesheet('template.css', 'components/com_fabrik/plugins/visualization/googlemap/views/googlemap/tmpl/'.$tmpl.'/', true);
			}
			$template = null;
		}
		//check and add a general fabrik custom css file overrides template css and generic table css
		FabrikHelperHTML::stylesheetFromPath("media".DS."com_fabrik".DS."css".DS."custom.css");
		//check and add a specific biz  template css file overrides template css generic table css and generic custom css
		FabrikHelperHTML::stylesheetFromPath("components".DS."com_fabrik".DS."plugins".DS."visualization".DS."googlemap".DS."views".DS."googlemap".DS."tmpl".DS.$tmpl.DS."custom.css");
		$this->assignRef('filters', $this->get('Filters'));
		$this->assign('showFilters', JRequest::getInt('showfilters', 1) === 1 ?  1 : 0);
		$this->assign('filterFormURL', $this->get('FilterFormURL'));
		$this->_setPath('template', $tmplpath);

		$this->assign('containerId', $this->get('ContainerId'));
		//ensure we don't have an incorrect version of mootools loaded
		FabrikHelperHTML::cleanMootools();
		if ($this->_isMambot) {
			return $this->loadTemplate($template);
		} else {
			parent::display($template);
		}
	}

}
?>