<?php
/**
 * @package Module Sliding Image Gallery XML v2 for Joomla! 1.5
 * @version $Id: mod_slidingimagegalleryxmlv2.php 14 March 2009 $
 * @author FlashBlue
 * @copyright (C) 2009 FlashBlue
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
**/

defined('_JEXEC') or die('Restricted access');

if (!function_exists('simplexml_load_file')) {
	echo "<!-- fxphpversion: ".phpversion()." -->";
} else {
	$slidingimagegalleryxmlv2_path = $params->get('slidingimagegalleryxmlv2_path');
	if (strpos($slidingimagegalleryxmlv2_path, '/') !== 0) {
		$slidingimagegalleryxmlv2_path = '/'.$slidingimagegalleryxmlv2_path;
		$params->def('slidingimagegalleryxmlv2_path', $slidingimagegalleryxmlv2_path);
	}
	$slidingimagegalleryxmlv2_swf = 'banner.swf';
	$xml_file_name = $params->get('slidingimagegalleryxmlv2_xmlUrl');
	if (empty($xml_file_name)) {
		$xml_file_name = 'xml/banner.xml';
	}
	if (file_exists(JPATH_BASE.$slidingimagegalleryxmlv2_path.$xml_file_name)) {
		$xml = simplexml_load_file(JPATH_BASE.$slidingimagegalleryxmlv2_path.$xml_file_name);
		$slidingimagegalleryxmlv2_width = (int)$xml->globals->attributes()->width;
		$slidingimagegalleryxmlv2_height = (int)$xml->globals->attributes()->height;
		if ($slidingimagegalleryxmlv2_width == 0 || $slidingimagegalleryxmlv2_height == 0) {
			$slidingimagegalleryxmlv2_width = (int)$params->get('slidingimagegalleryxmlv2_width');
			$slidingimagegalleryxmlv2_height = (int)$params->get('slidingimagegalleryxmlv2_height');
		}
		if ($slidingimagegalleryxmlv2_width > 0 && $slidingimagegalleryxmlv2_height > 0) {
			$joomla_install_dir_in_url = rtrim(JURI::root(true), '/');
			if (!empty($joomla_install_dir_in_url) && strpos($joomla_install_dir_in_url, '/') !== 0) {
				$joomla_install_dir_in_url = '/' . $joomla_install_dir_in_url;
			}
			global $mainframe;
			$mainframe->addCustomHeadTag('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>');
			echo '<div id="slidingimagegalleryxmlv2"></div><script type="text/javascript">'."swfobject.embedSWF('{$joomla_install_dir_in_url}{$slidingimagegalleryxmlv2_path}{$slidingimagegalleryxmlv2_swf}', 'slidingimagegalleryxmlv2', '{$slidingimagegalleryxmlv2_width}', '{$slidingimagegalleryxmlv2_height}', '9.0.0.0', '', {".($xml_file_name != 'xml/banner.xml' ? "xmlUrl: '{$xml_file_name}'" : '')."}, {base: '{$joomla_install_dir_in_url}{$slidingimagegalleryxmlv2_path}', scale: 'noscale', salign: 'tl', wmode: 'transparent', allowScriptAccess: 'sameDomain', allowFullScreen: true }, {});</script>";
		} else {
			echo '<!--  invalid Sliding Image Gallery XML v2 width / height -->';
		}
	}
}
