<?php
	
function get_nivo_slider_results($atts) {
	
	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 = 'nivo-slider-'.cloudfw_randomizer(4);
		
		if (is_numeric($slider_options["autorotation_speed"]))
			$slider_options["autorotation_speed"] = ($slider_options["autorotation_speed"] * 1000);
		else
			$slider_options["autorotation_speed"] = 10000;
			
		if ($slider_options["autorotation_speed"] < $slider_options["effect_speed"]) $slider_options["autorotation_speed"] = $slider_options["effect_speed"];
	
		echo '
		<script type="text/javascript">
			
			jQuery.getScript("'.TMP_URL.'/lib/js/nivo.slider.js'.'", function(){

					jQuery("#'.$unique_id.'").nivoSlider({
						'._isso(
							$slider_options["autorotation_speed"] > 0,
							'pauseTime: '.$slider_options["autorotation_speed"].',',
							'pauseTime: 3000,').'
						'._isso(($slider_options["effect_speed"] > 0 ),
							'animSpeed: '.$slider_options["effect_speed"].',',
							NULL).'
						effect: "'._isso(empty($slider_options["effect"]),'random',$slider_options["effect"]).'",
						slices: '._isso(empty($slider_options["slices"]),15,$slider_options["slices"]).',
						controlNav: '._isso(_isOnOff($slider_options["pagination"]),'true','false').',
						directionNav: '._isso(_isOnOff($slider_options["next_prev"]),'true','false').',
						captionOpacity: 0
					});	
					
					jQuery("#'.$unique_id.'").hover(function(){
							
							var $caption = jQuery(this).find(".nivo-caption");
							if ( $caption.find("p").html() != "" && $caption.find("p").html() != undefined )
								jQuery(this).find(".nivo-caption").stop(true).fadeTo(200,.65);
					
					},function(){
					
							jQuery(this).find(".nivo-caption").stop(true).fadeTo(200,0);
					
					});
				
			
			 });

		</script>
		
		';

		$html_caption = NULL;
		$width_height = cloudfw_skin_engine_make_attribute(NULL,'width',$slider_options["width"]). cloudfw_skin_engine_make_attribute(NULL,'height',$slider_options["height"]);
		$slider_padding = _isso(($slider_options["pagination"] !== 'FALSE'), 'margin-bottom:20px;');
	
		echo '<div class="full-width">
		<div id="'.$unique_id.'" class="nivoSlider" style="'.$width_height.$slider_padding.'">';
		
		// loop
		foreach ($slider_data as $slider_id => $slider){
			
			$slider_img = cloudfw_thumbnail(array('src' => $slider["slider_image"], 'w' => $slider_options["width"], 'h' => $slider_options["height"], 'cache' =>0));
			
			if ( !empty($slider["slider_caption"]) || !empty($slider["cation_text"])  ) {
				$html_caption_id = $unique_id.'-caption-'.$slider_id;
				$html_caption .= '<div id="'.$html_caption_id.'" class="nivo-html-caption"><span><strong>'.$slider["slider_caption"].'</strong></span></div>';
			}else
				unset($html_caption_id);
					
			echo $slider["slider_url"] ? '<a href="'.cloudfw_get_page_link($slider["slider_url"]).'"><img src="'.$slider_img.'" '._isso($html_caption_id, 'title="#'.$html_caption_id.'" ').'alt=""/></a>': '<img src="'.$slider_img.'" '._isso($html_caption_id, 'title="#'.$html_caption_id.'" ').'alt=""/>' ;
			

		}
		// end of loop
		
		echo '
		</div>
		</div>
		'.$html_caption;

	endif;


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