<?php
/**
* LayerSlider v5.1.2 - Responsive Slideshow Module http://layerslider.webshopworks.com
*
*  @author    WebshopWorks <info@webshopworks.com>
*  @copyright 2015 WebshopWorks
*  @license   One Domain Licence
*/

if (!defined('_PS_VERSION_'))
	exit;

if (!defined('LS_INCLUDE'))
{
	$id = 0;
	$ls_defaults = array();
	$slides = array();
	$data = array();
}

$slider = array();

if (has_filter('layerslider_override_defaults'))
{
	$new_defaults = apply_filters('layerslider_override_defaults', $ls_defaults);
	if (!empty($new_defaults) && is_array($new_defaults))
	{
		$ls_defaults = $new_defaults;
		unset($new_defaults);
	}
}
if (has_filter('layerslider_pre_parse_defaults'))
{
	$result = apply_filters('layerslider_pre_parse_defaults', $slides);
	if (!empty($result) && is_array($result))
		$slides = $result;
}

$slides['properties'] = apply_filters('ls_parse_defaults', $ls_defaults['slider'], $slides['properties']);
$slides['properties']['attrs']['skinsPath'] = __PS_BASE_URI__.'modules/layerslider/views/css/base/skins/';
if (isset($slides['properties']['autoPauseSlideshow']))
{
	switch ($slides['properties']['autoPauseSlideshow'])
	{
		case 'auto':
			$slides['properties']['autoPauseSlideshow'] = 'auto';
			break;
		case 'enabled':
			$slides['properties']['autoPauseSlideshow'] = true;
			break;
		case 'disabled':
			$slides['properties']['autoPauseSlideshow'] = false;
			break;
	}
}

if (isset($slides['layers']) && is_array($slides['layers']))
{
	foreach ($slides['layers'] as $slidekey => $slide)
	{
		$slider['slides'][$slidekey] = apply_filters('ls_parse_defaults', $ls_defaults['slides'], $slide['properties']);
		if (isset($slide['sublayers']) && is_array($slide['sublayers']))
		{
			foreach ($slide['sublayers'] as $layerkey => $layer)
			{
				if (!empty($layer['transition']))
					$layer = array_merge($layer, Tools::jsonDecode(call_user_func('stripslashes', $layer['transition']), true));

				$slider['slides'][$slidekey]['layers'][$layerkey] = apply_filters('ls_parse_defaults', $ls_defaults['layers'], $layer);
			}
		}
	}
}

if (has_filter('layerslider_post_parse_defaults'))
{
	$result = apply_filters('layerslider_post_parse_defaults', $slides);
	if (!empty($result) && is_array($result))
		$slides = $result;
}

$init = array();
foreach ($slides['properties']['attrs'] as $key => $val)
{
	if (is_bool($val))
	{
		$val = $val ? 'true' : 'false';
		$init[] = $key.': '.$val;
	}
	elseif (is_numeric($val))
		$init[] = $key.': '.$val;
	elseif (Tools::substr($key, 0, 2) == 'cb' && empty($val))
		continue;
	elseif (strpos($val, 'function(') === 0)
		$init[] = $key.': '.$val;
	else

		$init[] = "$key: '$val'";

}
$init = implode(', ', $init);

$data[] = '<script type="text/javascript">'.NL;
$data[] = '(window.lsjq||jQuery)(document).ready(function($) {'.NL;
$data[] = 'if(typeof $.fn.layerSlider == "undefined")  lsShowNotice(\'layerslider_'.$id.'\',\'jquery\'); '.NL;
$data[] = 'else {'.NL;
$data[] = '$("#layerslider_'.$id.'").layerSlider({'.$init.'})'.NL;
$data[] = '}'.NL;
$data[] = '});'.NL;
$data[] = '</script>';
