<?php 

$DYN_galleryheight	= ($DYN_galleryheight	!="") ? $DYN_galleryheight	: '415';
$DYN_imgheight 		= ($DYN_imgheight		!="") ? $DYN_imgheight		: '160';
$DYN_imgwidth 		= ($DYN_imgwidth		!="") ? $DYN_imgwidth		: '290';
$DYN_shadowsize		= "shadow-medium";

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.

?>

<div class="gallery-wrap clearfix" <?php if($DYN_galleryheight) { ?> style="height: <?php echo $DYN_galleryheight; ?>px" <?php } else { ?> style="height:415px;" <?php } ?>>
	<div class="slidernav-left">
<?php if($post_count>"3") { ?>
		<div class="slidernav">
			<a id="leftnav" href="#"><img src="<?php bloginfo("template_url"); ?>/images/blank.gif" width="22px" height="32px" alt="navigate left" /></a>
		</div>
<?php } ?>
	</div>
     
	<div class="group-slider">

<?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/group-gallery-frame.php'; ?>  

<?php endwhile; 

if($postcount!="0") { $postcount="0"; // Check to see if end tag needs to be set ?>
	</div><!--  / panelwrap -->
<?php } 

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;

?>

<div class="gallery-wrap clearfix" <?php if($DYN_galleryheight) { ?> style="height: <?php echo $DYN_galleryheight; ?>px" <?php } else { ?> style="height:415px;" <?php } ?>>
	<div class="slidernav-left">
<?php if($post_count>"3") { ?>
		<div class="slidernav">
			<a id="leftnav" href="#"><img src="<?php bloginfo("template_url"); ?>/images/blank.gif" width="22px" height="32px" alt="navigate left" /></a>
		</div>
<?php } ?>
	</div>
     
	<div class="group-slider">

<?php 

$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/group-gallery-frame.php'; ?>  

<?php 
$z++;
endwhile; 

if($postcount!="0") { $postcount="0"; // Check to see if end tag needs to be set ?>
	</div><!--  / panelwrap -->
<?php } 

}

$postcount = 0; ?>


</div><!-- / groupslider -->
<div class="slidernav-right">
<?php if($post_count>"3") { ?>
	<div class="slidernav">
		<a id="rightnav" href="#"><img src="<?php bloginfo("template_url"); ?>/images/blank.gif" width="22px" height="32px" alt="navigate left" /></a>
	</div>
<?php } ?>
</div>
<div class="clear"></div>
</div><!-- / gallerywrap -->

<script type="text/javascript">
<!--
jQuery(window).load(function() {

	jQuery('.group-slider').cycle({ 
		fx:     'scrollHorz', 
		timeout: 0,
		speed: 750,
		before:  onBefore,
		after:  onAfter,		
		easing: 'easeInOutExpo',
		prev: '#leftnav',
		next: '#rightnav'
	});

});

	function onBefore() { 
   		var videoid = jQuery(this).find('.jwplayer').attr("id");
			
		jQuery('.jwplayer').each(function(index) {
					str='';
					str = jQuery(this).attr("id");
					if(str!=videoid) {
						if(str.search("video")==-1) {
						jwplayer(str).stop();
						}
					}					 
		});
	
	} 

	function onAfter() { 

   		var videoid = jQuery(this).find('.jwplayer').attr("id");
			
		jQuery('.jwplayer').each(function(index) {
					str='';
					str = jQuery(this).attr("id");
					autostart = jQuery(this).attr("class");
					if(str==videoid) {
						if(str.search("video")==-1 && autostart.search("autostart")!=-1) {
						jwplayer(str).play();
						}
					}					 
		});
					
	} 

	jQuery(document).ready(function() {
		var firstvideo = jQuery(this).find('.jwplayer.first').attr("id");
		if(firstvideo) {
			var autostart = jQuery('#'+firstvideo).attr("class");
			if(autostart.search("autostart")!=-1) {
				jwplayer(firstvideo).play();
			}
		}
	});

//-->
</script>