<?php 
/*
 *
 * @package		ARI Smart Content
 * @author		ARI Soft
 * @copyright	Copyright (c) 2011 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 */

(defined('_JEXEC') && defined('ARI_FRAMEWORK_LOADED')) or die;

AriKernel::import('Application.ARISmartContent.Plugin.LightboxPlugin');

class plgArismartcontent_integrationSexylightbox_lightbox extends AriSmartContentPluginLightbox
{
	function processLinkImpl(&$linkAttrs, $group, $options)
	{
		if ($linkAttrs)
		{
			$linkAttrs['rel'] = 'sexylightbox' . ($group ? '[' . $group . ']' : '');
		}
		
		$uri = null;
		$link = $linkAttrs['href'];
		$bgColor = AriUtils::getParam($options, 'bgColor');
		
		if ($bgColor)
		{
			$uri = new JURI($link);
			$uri->setVar('background', $bgColor);
		}

		if ($this->isLink($link))
		{
			$width = AriUtils::getParam($options, 'width');
			$height = AriUtils::getParam($options, 'height');

			if (is_null($uri))
				$uri = new JURI($link);

			$uri->setVar('TB_iframe', 'true');
			
			if ($width && !$uri->getVar('width'))
				$uri->setVar('width', $width);
				
			if ($height && !$uri->getVar('height'))
				$uri->setVar('height', $height);
		}
		
		if (!is_null($uri))
			$linkAttrs['href'] = $uri->toString();
	}
	
	function getInitClientCodeImpl($container, $group)
	{
		return ';SexyLightbox.refresh();';
	}

	function loadAssets()
	{
		jimport('arismartcontent.sexylightbox.sexylightbox');
		
		$sexyLightbox = new AriSmartContentWidgetSexyLightbox($this->params);
		$sexyLightbox->loadAssets();
	}
}