<?php
	
function get_galleria_results($atts) {
	
	static $iGalleria;
	
	$iGalleria++;
	if ($iGalleria > 1)
		return cloudfw_fatalError( __('Galleria script only can be used one time on the same page','cloudfw') );

	
	extract(cloudfw_make_var(array(
		'id'				=> NULL,
	), $atts));	
	
		
	$slider_options = cloudfw_get_slider_options($id);
	
	if ($slider_options["source"] == 'gallery')
		$slider_data = cloudfw_get_post_gallery_source(get_the_ID());
	else
		$slider_data = cloudfw_get_slider($id);
	
	
	ob_start();	

	if (is_array($slider_data)):
	

	
		$unique_id = 'galleria_'.cloudfw_randomizer(4);
		
		if (is_numeric($slider_options["pausetime"]))
			$slider_options["pausetime"] = ($slider_options["pausetime"] * 1000);
		else
			$slider_options["pausetime"] = 5000;
			
		if ($slider_options["pausetime"] < $slider_options["effect_speed"]) $slider_options["pausetime"] = $slider_options["effect_speed"];
	
		echo '<div class="full-width">
		<div id="'.$unique_id.'" class="galleria">';
		
		// loop
		foreach ($slider_data as $slider_id => $slider){
			$data .= '
				{ image: "'.($slider["slider_image"]).'", title: "'.esc_attr($slider["slider_title"]).'", description: "'.esc_attr($slider["slider_caption"]).'", link: "'.cloudfw_get_page_link($slider["slider_url"]).'"},
			';
		}
		// end of loop
		
		echo '
		</div>
		</div>';
		
		echo '
		
		<script type="text/javascript">
			
			jQuery.getScript("'.TMP_URL.'/lib/js/galleria.js'.'", function(){
				
					Galleria.loadTheme("'.TMP_URL.'/lib/css/galleria/classic/galleria.classic.min.js");

					var galleriaData_'.$unique_id.' =  ['.$data.'];

					jQuery("#'.$unique_id.'").galleria({
						'._isso(($slider_options["width"] > 0 ),
							'width: '.$slider_options["width"].',',
							NULL).'
						'._isso(($slider_options["height"] > 0 ),
							'height: '.$slider_options["height"].',',
							NULL).'
						
						'._isso(
							$slider_options["pausetime"] > 0,
							'autoplay: '.$slider_options["pausetime"].',',
							'autoplay: false,').'
						'._isso(($slider_options["effect_speed"] > 0 ),
							'transitionSpeed: '.$slider_options["effect_speed"].',',
							NULL).'
						transition: "'._isso(empty($slider_options["effect"]),'fade',$slider_options["effect"]).'",
						thumbnails: '._isso(_isOnOff($slider_options["thumbnails"]),'true','false').',
						imageCrop: '._isso(_isOnOff($slider_options["imageCrop"]),'true','false').',
						preload: 2,
						dataSource: galleriaData_'.$unique_id.',
						

					});					
			
			 });

		</script>
		
		';

	endif;
	

	
	ob_end_flush;
	$out = ob_get_contents();
	ob_end_clean();
	
	return $out;
			
}
	
?>