<?php 

if($DYN_imgheight) {
$DYN_galleryheight=$DYN_imgheight; // No Reflection
} else {
$DYN_galleryheight="350"; // Set default Gallery Height
$DYN_imgheight="350"; // Set default Gallery Height
}

$DYN_gallerywidth="940";

?>

<div id="cwz-accordion" class="accordion-gallery-wrap <?php if($DYN_imageeffect=="shadow") { ?>shadow<?php } elseif($DYN_imageeffect=="reflection") { ?>reflection<?php } elseif($DYN_imageeffect=="shadowreflection") { ?>shadowreflection<?php } ?> stage">
    <ul class="accordion-gallery stage" style="height:<?php echo $DYN_galleryheight; ?>px">
	 
<?php 

if(!$DYN_slidesetid) { // If no Slide Set is selected use Categories

$postcount = 0;

if($DYN_gallerycat) {
foreach ($DYN_gallerycat as $catlist) { // Get category ID Array
	$cats = $cats.",".$catlist;
}

if($DYN_gallerynumposts) { // Number of posts to display
	$numposts = $DYN_gallerynumposts;
} else {
	$numposts = -1;
}

if($DYN_gallerysortby) { // Sort Posts by
	$sortby = $DYN_gallerysortby;
} else {
	$sortby = "meta_value";
}

if($DYN_galleryorderby) {
	$orderby = $DYN_galleryorderby;
} else {
	$orderby = "ASC";
}

$cats = lTrim($cats,',');

   $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
	  'meta_key' => 'Order',
	  'cat' => $cats,
	  'paged' => $paged,
	  'orderby' => $sortby,
	  'order' => $orderby,
	  'posts_per_page' => $numposts,
      'caller_get_posts'=> 1,
      );

	$featured_query = new wp_query($args); 

}
else { // If no options select display all categories

$args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
	  'meta_key' => 'Order',
	  'paged' => $paged,
	  'orderby' => $sortby,
	  'order' => $orderby,
	  'posts_per_page' => $numposts,
      'caller_get_posts'=> 1
      );


	$featured_query = new wp_query($args);
} 


$post_count = $featured_query->post_count; // Check how many posts in query.

$DYN_imagewidth=$DYN_gallerywidth / $post_count;
$DYN_imagewidth=round($DYN_gallerywidth - $DYN_imagewidth);

?>

<?php 
while ($featured_query->have_posts()) : $featured_query->the_post(); 

/******************  Get custom field data ******************/             

$pdata = maybe_unserialize(get_post_meta( $post->ID, 'pgopts', true ));

$DYN_movieurl = $pdata["movieurl"]; // Movie File URL
$DYN_previewimgurl=$pdata["previewimgurl"]; // Preview Image URL
$DYN_imgzoomcrop=$pdata["imgzoomcrop"];
$DYN_disablegallink=$pdata["disablegallink"];
$DYN_disablereadmore=$pdata["disablereadmore"];
$DYN_galexturl=$pdata["galexturl"];
$DYN_videotype=$pdata["videotype"];
$DYN_videoautoplay=$pdata["videoautoplay"];

if($DYN_videoautoplay) {
	$DYN_videoautoplay = "1";
} else {
	$DYN_videoautoplay ="0";	
}

/****************** / Get custom field data *****************/ 

$do_not_duplicate[] = get_the_ID();

$postcount++;

$image = catch_image(); // Check for images within post

$slide_id='';
$slide_id="slide-".$post->ID;

?>

<?php require CWZ_FILES .'/inc/accordion-gallery-frame.php'; ?>  

<?php endwhile; 

wp_reset_query();

} else { // Get Slide Set Data

$postcount=0;

$get_slideset_num = get_option('slideset_number');
$get_slideset_data = get_option('slideset_data');

$gallery_count = $get_slideset_num;
                
for($i = 0; $i < $gallery_count; $i++) { // Find Slide Set ID Number from Slide Set ID Name	
	if($DYN_slidesetid==$get_slideset_data['slideset_id'.$i.'_id']) {
		$slideset_id = $i;
	}
}


$get_slides_count = $get_slideset_data['slideset_id'.$slideset_id.'_slide_count']; 
$post_count = $get_slides_count;

$DYN_imagewidth=$DYN_gallerywidth / $post_count;
$DYN_imagewidth=$DYN_gallerywidth - $DYN_imagewidth;

$z = 0;
while ($z < $get_slides_count):

/******************  Get Slide Set data ******************/ 	

$DYN_disablegallink="";
	
$DYN_movieurl = $get_slideset_data['slideset_id'.$slideset_id.'_videourl_'.$z]; // Movie File URL
$DYN_previewimgurl=$get_slideset_data['slideset_id'.$slideset_id.'_url_'.$z]; // Preview Image URL
$DYN_imgzoomcrop=strtolower($get_slideset_data['slideset_id'.$slideset_id.'_crop_'.$z]);

if(!$get_slideset_data['slideset_id'.$slideset_id.'_link_'.$z]) {
$DYN_disablegallink="yes";
} 

$DYN_disablereadmore=$get_slideset_data['slideset_id'.$slideset_id.'_disreadmore_'.$z];

$DYN_galexturl=$get_slideset_data['slideset_id'.$slideset_id.'_link_'.$z];
$DYN_videotype=strtolower($get_slideset_data['slideset_id'.$slideset_id.'_embed_'.$z]);

$DYN_videoautoplay=$get_slideset_data['slideset_id'.$slideset_id.'_autoplay_'.$z];
$DYN_posttitle=stripslashes($get_slideset_data['slideset_id'.$slideset_id.'_title_'.$z]);
$DYN_description=stripslashes($get_slideset_data['slideset_id'.$slideset_id.'_desc_'.$z]);

if($DYN_videoautoplay) {
	$DYN_videoautoplay = "1";
} else {
	$DYN_videoautoplay ="0";	
}	

/******************  / Get Slide Set data ******************/

$postcount++; 

$slide_id='';
$slide_id="slideset".$slideset_id."-".$z;

?>

<?php require CWZ_FILES .'/inc/accordion-gallery-frame.php'; ?>  

<?php 
$z++;
endwhile; 

}

$postcount = 0; ?>

	</ul>
</div><!-- / accordion-gallery -->
<?php if(!$DYN_stagetimeout) { $DYN_stagetimeout = "10"; }; ?>
<?php if(!$DYN_accordionautoplay) {$DYN_accordionautoplay="false";} else {$DYN_accordionautoplay="true";} ?>
<script type="text/javascript">
<!--
	jQuery().ready(function() {
		jQuery('.accordion-gallery.stage').kwicks({
		autorotation: <?php echo $DYN_accordionautoplay; ?>,
		event: 'mouseover',
		autorotationSpeed:<?php echo $DYN_stagetimeout; ?>,
		easing: 'easeInOutCubic',
		duration: 700,
		id: 'cwz-accordion'
		});
	});	

//-->
</script>