<?php 
settings_fields( 'gallery-settings-group' );

$get_slideset_num = get_option('slideset_number');
$filter_categories_str = get_option('filter_categories');

if (!$get_slideset_num) {
	 $get_slideset_num = 1;
}

$get_gallery_data = get_option('slideset_data'); ?>


<div class="wrap gallerycreator">
        <form method="post" action="">
 
        <p><input type="submit" class="button-primary add_gal" value="Add New Slide Set" /></p>
		
        <input name="slideset_number" class="slideset_number count_hide_rm" type="hidden" value="<?php echo $get_slideset_num; ?>" />
		<input name="filter_categories" class="filter_categories" type="hidden" value="<?php echo $filter_categories_str; ?>" />

		<table class="widefat">
            <thead>
                <tr style="cursor: move;">
                    <th>
                       <label>Add Grid Gallery Filter Category: </label><input name="newcategory" class="newcategory" type="text" value="" />
                       <input type="button" class="button-secondary apply adddatacat" id="<?php echo $i; ?>" value="Add Category" />
                       <select style="margin-left:40px;" class="filter_categories_select" id="filter_categories_select" name="filter_categories_select">
                       <?php
               		
               		
               		$filter_categories = explode(",", $filter_categories_str);
               		
               		
                  		if($filter_categories) {
               			if(is_array($filter_categories)) {
                        		foreach ($filter_categories as $filter_categories) {
                        		echo"<option value='". $filter_categories ."'>". $filter_categories."</option>";
                        		}
               			} else {
               			    echo"<option value='". $filter_categories ."'>". $filter_categories."</option>";
               			}	
               		}	
               		?>
                       </select>
                       <input type="button" class="button-secondary apply deldatacat" id="<?php echo $i; ?>" value="Delete Category" />
                    </th>
                </tr>
            </thead>
		</table>

			
        <?php 
        
        $gallery_count = $get_slideset_num +"1";
        
        for($i = 0; $i < $gallery_count; $i++) {
        
        if (!$get_gallery_data['slideset_id'.$i.'_slide_count']) {
            $get_gallery_data['slideset_id'.$i.'_slide_count'] = 1;
        } 
        
        
        ?>

        <div class="table_wrap <?php if ($i+1 == $gallery_count) echo ' hidden'; if($i+1 == $gallery_count) echo ' clone_gal';?>">
		<?php $slide_set = $get_gallery_data['slideset_id'.$i.'_id'];  
		?>
       
        <div id="table-<?php echo $i ?>" class="multitables selected_custom correct_gallery_num">
                
        
        <input name="slideset_id<?php echo $i; ?>_slide_count" id="slideset_id<?php echo $i; ?>_slide_count" class="slide_counter count_hide_rm correct_num" type="hidden" value="<?php echo $get_gallery_data['slideset_id'.$i.'_slide_count'] ?>" />
        <table class="widefat">
            <thead>
                <tr style="cursor: move;">
                    <th>
                    
                    <label style="padding-top:4px;">Slide Set ID:</label> <input style="padding:2px;" class="correct_num" id="slideset_id<?php echo $i; ?>_id" name="slideset_id<?php echo $i; ?>_id" type="text" value="<?php echo $slide_set; ?>" /> 
                    </th>
                </tr>
            </thead>
        
            <tfoot>
                <tr>
                    <th></th>
                </tr>
            </tfoot>
            <tr>
            
        	<tbody>
            
            <tr>
                <td>
               
                <div class="reveal"><a href="#"><img src="<?php bloginfo('template_directory') ?>/lib/adm/imgs/blank.gif" alt="slide set control" width="17" height="17" /></a></div>
                
                <div class="reveal-content">
                <p style="padding:5px 0 5px 0;"><input type="button" style="float:right" class="button-secondary apply del_gal correct_gallery_num" id="delgal_<?php echo $i; ?>" value="Delete Slide Set" /><input type="submit" class="button-primary apply add_row correct_gallery_num" id="<?php echo $i; ?>" value="Add New Slide" /> <a title="Add an Image" class="button cwz thickbox" href="media-upload.php?type=image&amp;TB_iframe=1&amp;width=640&amp;height=338">Get Image URL</a></p>
                
                       
                
                <table class="widefat table_sort" tabindex="<?php echo $i; ?>">
                
                    <thead>
                        <tr style="cursor: move;">
                            <th width="50px">Order</th>
                            <th width="25px">&nbsp;</th>
                            <th width="325px">Setting</th>
                            <th width="325px">Description</th>
                            <th width="325px">&nbsp;</th>
                            <th>&nbsp;</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>
                    </tfoot>                    
                
                    <tbody>
                      <?php 
                     
                      $count = $get_gallery_data['slideset_id'.$i.'_slide_count'] +1;
                      for($z = 0; $z < $count; $z++) {
                      ?>
                    <tr class="multitable multitable_hide_rm<?php if ($z+1 == $count) echo ' hidden'; if($z+1 == $count) echo ' clone_row';?>">
                        
                    <td class="slider_drag">
                      <span class="changenumber"><?php echo $z+1; ?></span>
                    </td>
                      
                    <td>
                      <a href='#' title="Delete Row" tabindex="<?php echo $i; ?>" class='del_row' id='del_number_<?php echo $z + 1; ?>'><img src="<?php bloginfo('template_directory') ?>/lib/adm/imgs/delete.png" alt="Delete Slide" /></a>
                    </td>
                      
                    <td>
                      <div style="float:left;width:110px;">Image URL</div>
                      <input class="correct_num" id="slideset_id<?php echo $i; ?>_url_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_url_<?php echo $z; ?>" type="text" value="<?php echo $get_gallery_data['slideset_id'.$i.'_url_'.$z] ?>" /> <br />
                      <div style="float:left;width:110px;">Link URL</div>
                      <input class="correct_num" id="slideset_id<?php echo $i; ?>_link_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_link_<?php echo $z; ?>" type="text" value="<?php echo $get_gallery_data['slideset_id'.$i.'_link_'.$z] ?>" /><br />
                
                      <div style="float:left;width:110px;">Disable Link Text</div>
                      <?php if($get_gallery_data['slideset_id'.$i.'_disreadmore_'.$z]){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
                      <input class="correct_num" type="checkbox" id="slideset_id<?php echo $i; ?>_disreadmore_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_disreadmore_<?php echo $z; ?>" value="true" <?php echo $checked; ?> /><small class="description">Disable Read More text.</small><br class="clear" />
              
				      
                      <div style="float:left;width:110px;">Image Crop</div>
                      <select class="correct_num" id="slideset_id<?php echo $i; ?>_crop_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_crop_<?php echo $z; ?>">
                      <?php
                      $crop_image = array("Crop","Zoom");
                      foreach ($crop_image as $crop_image) {
                      if ($get_gallery_data['slideset_id'.$i.'_crop_'.$z] == $crop_image && $z+1 != $count){
                      $selected = "selected='selected'";	
                      }else{
                      $selected = "";		
                      }
                      echo"<option $selected value='". $crop_image."'>". $crop_image."</option>";
                      }
                      ?>
                      </select><br />
                      <div style="float:left;width:110px;">Stage Content</div>
                      <select class="correct_num" id="slideset_id<?php echo $i; ?>_stagecontent_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_stagecontent_<?php echo $z; ?>">
                      <?php
                      $stage_content = array("Image Only","Text/Image (Left Align)","Text/Image (Right Align)","Text Only");
                      foreach ($stage_content as $stage_content) {
                      if ($get_gallery_data['slideset_id'.$i.'_stagecontent_'.$z] == $stage_content && $z+1 != $count){
                      $selected = "selected='selected'";	
                      }else{
                      $selected = "";
                      }
					   echo"<option $selected value='". $stage_content ."'>". $stage_content."</option>";
                      }
                      ?>
                      </select><br />
                      
                    </td>
                      
                    <td>
                    <div style="float:left;width:110px;">Title</div>
                    <input class="correct_num" id="slideset_id<?php echo $i; ?>_title_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_title_<?php echo $z; ?>" type="text" value="<?php echo stripslashes(htmlspecialchars($get_gallery_data['slideset_id'.$i.'_title_'.$z])); ?>" /><br />          
                    <div style="float:left;width:110px;">Description</div><textarea rows="2" class="correct_num" id="slideset_id<?php echo $i; ?>_desc_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_desc_<?php echo $z; ?>"><?php echo stripslashes(htmlspecialchars($get_gallery_data['slideset_id'.$i.'_desc_'.$z])); ?></textarea><br />
                      <div style="float:left;width:110px;">Title Overlay</div>
                      <select class="correct_num" id="slideset_id<?php echo $i; ?>_overlay_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_overlay_<?php echo $z; ?>">
                      <?php
                      $overlay = array("Disabled","Center Left Light","Center Left Light","Center Middle Light","Center Left Dark","Center Right Dark","Center Middle Dark","Center Left Light","Top Left Light","Top Right Light","Top Middle Light","Top Left Dark","Top Right Dark","Top Middle Dark Text","Bottom Left Light","Bottom Right Light","Bottom Middle Light","Bottom Left Dark","Bottom Right Dark","Bottom Middle Dark");
                      foreach ($overlay as $overlay) {
                      if ($get_gallery_data['slideset_id'.$i.'_overlay_'.$z] == $overlay && $z+1 != $count){
                      $selected = "selected='selected'";	
                      }else{
                      $selected = "";
                      }
                      if($overlay!="Disabled") {
                        echo"<option $selected value='". $overlay."'>". $overlay."</option>";
                      } else {
                        echo"<option $selected value=''>". $overlay."</option>";				  
                      }
                      }
                      ?>
                      </select><br />
                    </td>
            
            
                    <td>
                    <div style="float:left;width:110px;">Video URL</div>
                    <input class="correct_num" id="slideset_id<?php echo $i; ?>_videourl_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_videourl_<?php echo $z; ?>" type="text" value="<?php echo stripslashes(htmlspecialchars($get_gallery_data['slideset_id'.$i.'_videourl_'.$z])); ?>" /><br />   
                      <div style="float:left;width:110px;">Embed Type</div>
                      <select class="correct_num" id="slideset_id<?php echo $i; ?>_embed_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_embed_<?php echo $z; ?>">
                      <?php
                      $video_embed = array("Disabled","Vimeo","YouTube","SWF","3dvid","jwp");
                      foreach ($video_embed as $video_embed) {
                      if ($get_gallery_data['slideset_id'.$i.'_embed_'.$z] == $video_embed && $z+1 != $count){
                      $selected = "selected='selected'";	
                      }else{
                      $selected = "";		
                      }
                      if($video_embed!="Disabled") {
					  	if($video_embed=="3dvid") {
					     echo"<option $selected value='". $video_embed."'>Video (3d Gallery Only)</option>";					  
						} elseif($video_embed=="jwp") {
						 echo"<option $selected value='". $video_embed."'>JW Player</option>";	
						} else {
                          echo"<option $selected value='". $video_embed."'>". $video_embed."</option>";
						}
                      } else {
                        echo"<option $selected value=''>". $video_embed."</option>";				  
                      }
                      }
                      ?>
                      </select><br />
                           
                    <div style="float:left;width:110px;">Timeout</div>
                    <input class="correct_num" style="width:30px" id="slideset_id<?php echo $i; ?>_timeout_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_timeout_<?php echo $z; ?>" type="text" value="<?php echo stripslashes(htmlspecialchars($get_gallery_data['slideset_id'.$i.'_timeout_'.$z])); ?>" /><small class="description">Seconds</small><br />
                    <div style="float:left;width:110px;">Autoplay</div>
                    <?php if($get_gallery_data['slideset_id'.$i.'_autoplay_'.$z]){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
                    <input class="correct_num" type="checkbox" id="slideset_id<?php echo $i; ?>_autoplay_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_autoplay_<?php echo $z; ?>" value="true" <?php echo $checked; ?> /> <small class="description">(YouTube, Vimeo, Video(3d) Embed)</small><br />
            
                    </td>

                    <td>
                      <div style="float:left;width:110px;">Filter Category</div>
                      <select class="correct_num catselect" id="slideset_id<?php echo $i; ?>_catselect_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_catselect_<?php echo $z; ?>">
                      <?php
					  echo"<option value=''>Select Category</option>";	
					  $filter_categories = explode(",", $filter_categories_str);
					  
					  if(is_array($filter_categories)) {
                        foreach ($filter_categories as $filter_categories) {
                          if ($get_gallery_data['slideset_id'.$i.'_catselect_'.$z] == $filter_categories && $z+1 != $count){
                          $selected = "selected='selected'";	
                          } else{
                          $selected = "";		
                          }
    					  
                          if($filter_categories!="Disabled") {
                            echo"<option $selected value='". $filter_categories."'>". $filter_categories."</option>";
                          } else {
                            echo"<option $selected value=''>". $filter_categories."</option>";				  
                          }
                        }
					  } else {
                          if ($get_gallery_data['slideset_id'.$i.'_catselect_'.$z] == $filter_categories && $z+1 != $count){
                          $selected = "selected='selected'";	
                          } else{
                          $selected = "";		
                          }					  
                         if($filter_categories!="Disabled") {
                            echo"<option $selected value='". $filter_categories."'>". $filter_categories."</option>";
                          } else {
                            echo"<option $selected value=''>". $filter_categories."</option>";				  
                          }					  
					  }
                      ?>
                      </select><br />
                      <div class="reveal threed"><a href="#"><img src="<?php bloginfo('template_directory') ?>/lib/adm/imgs/blank.gif" alt="slide set control" width="17" height="17" /> </a><div class="revealtext">3d Gallery Settings</div></div>
					  <div class="reveal-content">
					  <br />
					  <div style="float:left;width:110px;">Pieces</div>
                      <input class="correct_num" style="width:40px" id="slideset_id<?php echo $i; ?>_segments_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_segments_<?php echo $z; ?>" type="text" value="<?php echo stripslashes(htmlspecialchars($get_gallery_data['slideset_id'.$i.'_segments_'.$z])); ?>" /><br />

					  <div style="float:left;width:110px;">Transition</div>
                      
	                  <select class="correct_num" id="slideset_id<?php echo $i; ?>_transition_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_transition_<?php echo $z; ?>">
                      <?php
					  echo"<option value=''>Select</option>";
                      $tween_types = array("linear","easeInSine","easeOutSine", "easeInOutSine", "easeInCubic", "easeOutCubic", "easeInOutCubic", "easeOutInCubic", "easeInQuint", "easeOutQuint", "easeInOutQuint", "easeOutInQuint", "easeInCirc", "easeOutCirc", "easeInOutCirc", "easeOutInCirc", "easeInBack", "easeOutBack", "easeInOutBack", "easeOutInBack", "easeInQuad", "easeOutQuad", "easeInOutQuad", "easeOutInQuad", "easeInQuart", "easeOutQuart", "easeInOutQuart", "easeOutInQuart", "easeInExpo", "easeOutExpo", "easeInOutExpo", "easeOutInExpo", "easeInElastic", "easeOutElastic", "easeInOutElastic", "easeOutInElastic", "easeInBounce", "easeOutBounce", "easeInOutBounce", "easeOutInBounce");
		 
                      foreach ($tween_types as $tween_type) {
                      if ($get_gallery_data['slideset_id'.$i.'_transition_'.$z] == $tween_type && $z+1 != $count){
                      $selected = "selected='selected'";	
                      }else{
                      $selected = "";		
                      }
                      if($video_embed!="Disabled") {
                          echo"<option $selected value='". $tween_type ."'>". $tween_type ."</option>";
                      } 
                      }
                      ?>
                      </select><br />				  
 					  <div style="float:left;width:110px;">Transition Time</div>
                      <input class="correct_num" style="width:40px" id="slideset_id<?php echo $i; ?>_transtime_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_transtime_<?php echo $z; ?>" type="text" value="<?php echo stripslashes(htmlspecialchars($get_gallery_data['slideset_id'.$i.'_transtime_'.$z])); ?>" /><small class="description">Seconds (Default 1.2)</small><br class="clear" />

 					  <div style="float:left;width:110px;">Delay</div>
                      <input class="correct_num" style="width:40px" id="slideset_id<?php echo $i; ?>_transdelay_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_transdelay_<?php echo $z; ?>" type="text" value="<?php echo stripslashes(htmlspecialchars($get_gallery_data['slideset_id'.$i.'_transdelay_'.$z])); ?>" /><small class="description">Seconds (Default 0.1)</small><br />

 					  <div style="float:left;width:110px;">Depth Offset</div>
                      <input class="correct_num" style="width:40px" id="slideset_id<?php echo $i; ?>_depthoffset_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_depthoffset_<?php echo $z; ?>" type="text" value="<?php echo stripslashes(htmlspecialchars($get_gallery_data['slideset_id'.$i.'_depthoffset_'.$z])); ?>" /><small class="description">(-200 to 700)</small><br />

 					  <div style="float:left;width:110px;">Cube Distance</div>
                      <input class="correct_num" style="width:40px" id="slideset_id<?php echo $i; ?>_cubedistance_<?php echo $z; ?>" name="slideset_id<?php echo $i; ?>_cubedistance_<?php echo $z; ?>" type="text" value="<?php echo stripslashes(htmlspecialchars($get_gallery_data['slideset_id'.$i.'_cubedistance_'.$z])); ?>" /><small class="description">(Default 20)</small><br />
               
   
					  </div>        	
					  	
          
                    	</td>                    
                      </tr>
                      <?php } ?>
                    </tbody>
                
                </table>
                <p>&nbsp;</p>
				<input type="submit" class="button-primary apply add_row correct_gallery_num" id="<?php echo $i; ?>" value="Add New Slide" /> <a title="Add an Image" class="button cwz thickbox" href="media-upload.php?type=image&amp;TB_iframe=1&amp;width=640&amp;height=338">Get Image URL</a></p>                
                </div>
            </td>
            </tr>
            </tbody>
        </table>
        </div>
        </div>
        <?php 
        }
        ?>
        <p class="submit">
        <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" name="save" />
        </p>
        
        
        <input type="hidden" name="action" value="update" />
                 
        </form>

</div>
