<?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_integrationFancybox_lightbox extends AriSmartContentPluginLightbox
{
	function processLinkImpl(&$linkAttrs, $group, $options)
	{
		if ($linkAttrs)
		{
			if (!isset($linkAttrs['class']))
				$linkAttrs['class'] = '';

			$linkAttrs['class'] .= ' fancybox';

			if ($group)
				$linkAttrs['data-fancybox-group'] = 'fancybox_' . $group;

			$link = $linkAttrs['href'];
			if ($this->isLink($link))
			{
				$linkAttrs['class'] .= ' fancybox.iframe';
				
				$width = AriUtils::getParam($options, 'width');
				$height = AriUtils::getParam($options, 'height');

				if ($width)
					$linkAttrs['data-fancybox-width'] = $width;

				if ($height)
					$linkAttrs['data-fancybox-height'] = $height;
			}
		}
	}

	function getInitClientCodeImpl($container, $group)
	{
		jimport('arismartcontent.fancybox.fancybox');

		$fancybox = new AriSmartContentWidgetFancybox($this->params);
		$jsOptions = $fancybox->getJsOptions();
		
		return sprintf(
			';var fbOpts = %2$s;if (typeof(fancybox_beforeLoad_handler) != "undefined") fbOpts["beforeLoad"] = fancybox_beforeLoad_handler;(window["ascJQuery"] || jQuery)("%1$s .fancybox").fancybox(fbOpts);',
			$container,
			!empty($jsOptions) ? json_encode($jsOptions) : '{}'
		);
	}

	function loadAssets()
	{
		jimport('arismartcontent.fancybox.fancybox');

		$fancybox = new AriSmartContentWidgetFancybox($this->params);
		$fancybox->loadAssets();
	}
}