<?php

// OptionsFramework Admin Interface

/*-----------------------------------------------------------------------------------*/
/* Options Framework Admin Interface - optionsframework_add_admin */
/*-----------------------------------------------------------------------------------*/

// Load static framework options pages 
$functions_path = OF_FILEPATH . '/admin/';

function optionsframework_add_admin() {

    global $query_string;
    
    $themename =  get_option('of_themename');      
    $shortname =  get_option('of_shortname'); 
   
    if ( isset($_REQUEST['page']) && $_REQUEST['page'] == 'optionsframework' ) {
		if (isset($_REQUEST['of_save']) && 'reset' == $_REQUEST['of_save']) {
			$options =  get_option('of_template'); 
			of_reset_options($options,'optionsframework');
			header("Location: admin.php?page=optionsframework&reset=true");
			die;
		}
    }
	$of_page = add_theme_page( $themename, 'Theme Options', 'edit_theme_options', 'optionsframework', 'optionsframework_options_page', 'http://cdn2.iconfinder.com/data/icons/oxygen/16x16/actions/color-line.png', 29 );
	
	// Add framework functionaily to the head individually
	add_action("admin_print_scripts-$of_page", 'of_load_only');
	add_action("admin_print_styles-$of_page",'of_style_only');
} 

add_action('admin_menu', 'optionsframework_add_admin');

/*-----------------------------------------------------------------------------------*/
/* Options Framework Reset Function - of_reset_options */
/*-----------------------------------------------------------------------------------*/

function of_reset_options($options,$page = ''){

	global $wpdb;
	$query_inner = '';
	$count = 0;
	
	$excludes = array( 'blogname' , 'blogdescription' );
	
	foreach($options as $option){
			
		if(isset($option['id'])){ 
			$count++;
			$option_id = $option['id'];
			$option_type = $option['type'];
			
			//Skip assigned id's
			if(in_array($option_id,$excludes)) { continue; }
			
			if($count > 1){ $query_inner .= ' OR '; }
			if($option_type == 'multicheck'){
				$multicount = 0;
				foreach($option['options'] as $option_key => $option_option){
					$multicount++;
					if($multicount > 1){ $query_inner .= ' OR '; }
					$query_inner .= "option_name = '" . $option_id . "_" . $option_key . "'";
					
				}
				
			} else if(is_array($option_type)) {
				$type_array_count = 0;
				foreach($option_type as $inner_option){
					$type_array_count++;
					$option_id = $inner_option['id'];
					if($type_array_count > 1){ $query_inner .= ' OR '; }
					$query_inner .= "option_name = '$option_id'";
				}
				
			} else {
				$query_inner .= "option_name = '$option_id'";
			}
		}
			
	}
	
	//When Theme Options page is reset - Add the of_options option
	if($page == 'optionsframework'){
		$query_inner .= " OR option_name = 'of_options'";
	}
	
	//echo $query_inner;
	
	$query = "DELETE FROM $wpdb->options WHERE $query_inner";
	$wpdb->query($query);
		
}


/*-----------------------------------------------------------------------------------*/
/* Build the Options Page - optionsframework_options_page */
/*-----------------------------------------------------------------------------------*/

function optionsframework_options_page(){
    $options =  get_option('of_template');      
    $themename =  get_option('of_themename');
?>

<div class="wrap" id="of_container">

<?php 
	global $theme__name, $cversion; 
?>
<?php if( $cversion =="1.0") { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/11.jpg"/></a></div>
<?php } else if($cversion =="1.1" ) { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/12.jpg"/></a></div>
<?php } else if($cversion =="1.2") { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/13.jpg"/></a></div>
<?php } else if($cversion =="1.3")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/14.jpg"/></a></div>
<?php } else if($cversion =="1.4")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/15.jpg"/></a></div>
<?php } else if($cversion =="1.5")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/16.jpg"/></a></div>
<?php } else if($cversion =="1.6")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/17.jpg"/></a></div>
<?php } else if($cversion =="1.7")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/18.jpg"/></a></div>
<?php } else if($cversion =="1.8")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/19.jpg"/></a></div>
<?php } else if($cversion =="1.9")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/20.jpg"/></a></div>
<?php } else if($cversion =="2.0")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/21.jpg"/></a></div>
<?php } else if($cversion =="2.1")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/22.jpg"/></a></div>
<?php } else if($cversion =="2.2")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/23.jpg"/></a></div>
<?php } else if($cversion =="2.3")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/24.jpg"/></a></div>
<?php } else if($cversion =="2.4")  { ?>
	<div class="new_version"><a href="http://themeforest.net/user/madza/portfolio" title="Download"><img title="Download" src="http://www.madza-wordpress-premium-themes.com/version/<?php echo $theme__name; ?>/25.jpg"/></a></div>
<?php } ?>
  <div id="of-popup-save" class="of-save-popup">
    <div class="of-save-save">Options Updated</div>
  </div>
  <div id="of-popup-reset" class="of-save-popup">
    <div class="of-save-reset">Options Reset</div>
  </div>
  <form action="" enctype="multipart/form-data" id="ofform">
    <div id="header">
      <div class="logo">
        <h2><?php wp_title(); ?>Theme Settings</h2>
        <p>For future updates follow me <a  href="http://themeforest.net/user/madza/follow">@themeforest</a> or <a target="_blank" href="http://twitter.com/#!/madzathemes">@twitter</a></p>
      </div>
      <div class="icon-option"></div>
      <div class="clear"></div>
    </div>
    <?php 
		// Rev up the Options Machine
        $return = optionsframework_machine($options);
        ?>
    <div id="main">
      <div id="of-nav">
        <ul>
          <?php echo $return[1] ?>
        </ul>
      </div>
      <div id="content"> <?php echo $return[0]; /* Settings */ ?> </div>
      <div class="clear"></div>
    </div>
    <div class="save_bar_top">
    <img style="display:none" src="<?php get_stylesheet_directory_uri(); ?>/admin/images/loading-bottom.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="Working..." />
    <input type="submit" value="Save All Changes" class="button-primary" />
  </form>
  <form action="<?php echo esc_attr( $_SERVER['REQUEST_URI'] ) ?>" method="post" style="display:inline" id="ofform-reset">
    <span class="submit-footer-reset">
    <input name="reset" type="submit" value="Reset Options" class="button submit-button reset-button" onclick="return confirm('Click OK to reset. Any settings will be lost!');" />
    <input type="hidden" name="of_save" value="reset" />
    </span>
  </form>
</div>
<?php  if (!empty($update_message)) echo $update_message; ?>
<div style="clear:both;"></div>
</div>
<!--wrap-->
<?php
}

/*-----------------------------------------------------------------------------------*/
/* Load required styles for Options Page - of_style_only */
/*-----------------------------------------------------------------------------------*/

function of_style_only() {
    
	wp_enqueue_style('admin-style', OF_DIRECTORY.'/admin/admin-style.css');
	wp_enqueue_style('color-picker', OF_DIRECTORY.'/admin/css/colorpicker.css');
    wp_enqueue_style('checkboxes_stylers', OF_DIRECTORY.'/includes/checkboxe/style.css');
    wp_enqueue_style('slider_size', OF_DIRECTORY.'/admin/jquery_ui_slider.css');
}	


/*-----------------------------------------------------------------------------------*/
/* Load required javascripts for Options Page - of_load_only */
/*-----------------------------------------------------------------------------------*/

function of_load_only() {

	add_action('admin_head', 'of_admin_head');
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js', false); 
    wp_enqueue_script( 'jquery' );
    wp_deregister_script( 'jquery-ui' );
    wp_register_script('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js', array( 'jquery' ));
    wp_enqueue_script( 'jquery-ui' );
    wp_enqueue_script('jquery-slider', 'http://jqueryui.com/ui/jquery.ui.slider.js', array( 'jquery' ));
	wp_register_script('jquery-input-mask', OF_DIRECTORY.'/admin/js/jquery.maskedinput-1.2.2.js', array( 'jquery' ));
	wp_enqueue_script('jquery-input-mask');
	wp_enqueue_script('color-picker', OF_DIRECTORY.'/admin/js/colorpicker.js', array('jquery'));
	wp_enqueue_script('ajaxupload', OF_DIRECTORY.'/admin/js/ajaxupload.js', array('jquery'));
   
    
    wp_enqueue_script('checkboxesr', OF_DIRECTORY.'/includes/checkboxe/jquery/iphone-style-checkboxes.js', array('jquery'));
    
    ?><link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Lobster"><?php

	function of_admin_head() { 
	?>
    <script type="text/javascript" language="javascript">
    jQuery(window).load(function() {
      
      jQuery(':checkbox').iphoneStyle();
      
    });</script>
<script type="text/javascript" language="javascript">
 
		jQuery(document).ready(function(){
			
			
			//Color Picker
			<?php $options = get_option('of_template');
			
			foreach($options as $option){ 
			if($option['type'] == 'color' OR $option['type'] == 'typography' OR $option['type'] == 'typography_description' OR $option['type'] == 'border' OR $option['type'] == 'background' OR $option['type'] == 'headings'){
				if($option['type'] == 'typography' OR $option['type'] == 'typography_description' OR $option['type'] == 'border' OR $option['type'] == 'background' OR $option['type'] == 'headings'){
					$option_id = $option['id'];
					$temp_color = get_option($option_id);
					$option_id = $option['id'] . '_color';
					$color = $temp_color['color'];
				}
				else {
					$option_id = $option['id'];
					$color = get_option($option_id);
				}
				?>
				 jQuery('#<?php echo $option_id; ?>_picker').children('div').css('backgroundColor', '<?php echo $color; ?>');    
				 jQuery('#<?php echo $option_id; ?>_picker').ColorPicker({
					color: '<?php echo $color; ?>',
					onShow: function (colpkr) {
						jQuery(colpkr).fadeIn(500);
						return false;
					},
					onHide: function (colpkr) {
						jQuery(colpkr).fadeOut(500);
						return false;
					},
					onChange: function (hsb, hex, rgb) {
						//jQuery(this).css('border','1px solid red');
						jQuery('#<?php echo $option_id; ?>_picker').children('div').css('backgroundColor', '#' + hex);
						jQuery('#<?php echo $option_id; ?>_picker').next('input').attr('value','#' + hex);
						
					}
				  });
			  <?php } } ?>
		 
		});
		
		</script>
		
		<?php
		//AJAX Upload
		?>

<script type="text/javascript">

			jQuery(document).ready(function(){
			
			var flip = 0;
				
			jQuery('#expand_options').click(function(){
				if(flip == 0){
					flip = 1;
					jQuery('#of_container #of-nav').hide();
					jQuery('#of_container #content').width(755);
					jQuery('#of_container .group').add('#of_container .group h2').show();
	
					jQuery(this).text('[-]');
					
				} else {
					flip = 0;
					jQuery('#of_container #of-nav').show();
					jQuery('#of_container #content').width(595);
					jQuery('#of_container .group').add('#of_container .group h2').hide();
					jQuery('#of_container .group:first').show();
					jQuery('#of_container #of-nav li').removeClass('current');
					jQuery('#of_container #of-nav li:first').addClass('current');
					
					jQuery(this).text('[+]');
				
				}
			
			});
			
				jQuery('.group').hide();
				jQuery('.group:first').fadeIn();
				
				jQuery('.group .collapsed').each(function(){
					jQuery(this).find('input:checked').parent().parent().parent().nextAll().each( 
						function(){
           					if (jQuery(this).hasClass('last')) {
           						jQuery(this).removeClass('hidden');
           						return false;
           					}
           					jQuery(this).filter('.hidden').removeClass('hidden');
           				});
           		});
           					
				jQuery('.group .collapsed input:checkbox').click(unhideHidden);
				
				function unhideHidden(){
					if (jQuery(this).attr('checked')) {
						jQuery(this).parent().parent().parent().nextAll().removeClass('hidden');
					}
					else {
						jQuery(this).parent().parent().parent().nextAll().each( 
							function(){
           						if (jQuery(this).filter('.last').length) {
           							jQuery(this).addClass('hidden');
									return false;
           						}
           						jQuery(this).addClass('hidden');
           					});
           					
					}
				}
				
				jQuery('.of-radio-img-img').click(function(){
					jQuery(this).parent().parent().find('.of-radio-img-img').removeClass('of-radio-img-selected');
					jQuery(this).addClass('of-radio-img-selected');
					
				});
				jQuery('.of-radio-img-label').hide();
				jQuery('.of-radio-img-img').show();
				jQuery('.of-radio-img-radio').hide();
				jQuery('#of-nav li:first').addClass('current');
				jQuery('#of-nav li a').click(function(evt){
				
						jQuery('#of-nav li').removeClass('current');
						jQuery(this).parent().addClass('current');
						
						var clicked_group = jQuery(this).attr('href');
		 
						jQuery('.group').hide();
						
							jQuery(clicked_group).fadeIn();
		
						evt.preventDefault();
						
					});
				
				if('<?php if(isset($_REQUEST['reset'])) { echo $_REQUEST['reset'];} else { echo 'false';} ?>' == 'true'){
					
					var reset_popup = jQuery('#of-popup-reset');
					reset_popup.fadeIn();
					window.setTimeout(function(){
						   reset_popup.fadeOut();                        
						}, 2000);
						//alert(response);
					
				}
					
			//Update Message popup
			jQuery.fn.center = function () {
				this.animate({"top":( jQuery(window).height() - this.height() - 200 ) / 2+jQuery(window).scrollTop() + "px"},100);
				this.css("left", 250 );
				return this;
			}
		
			
			jQuery('#of-popup-save').center();
			jQuery('#of-popup-reset').center();
			jQuery(window).scroll(function() { 
			
				jQuery('#of-popup-save').center();
				jQuery('#of-popup-reset').center();
			
			});
			
			
		
			//AJAX Upload
			jQuery('.image_upload_button').each(function(){
			
			var clickedObject = jQuery(this);
			var clickedID = jQuery(this).attr('id');	
			new AjaxUpload(clickedID, {
				  action: '<?php echo admin_url("admin-ajax.php"); ?>',
				  name: clickedID, // File upload name
				  data: { // Additional data to send
						action: 'of_ajax_post_action',
						type: 'upload',
						data: clickedID },
				  autoSubmit: true, // Submit file after selection
				  responseType: false,
				  onChange: function(file, extension){},
				  onSubmit: function(file, extension){
						clickedObject.text('Uploading'); // change button text, when user selects file	
						this.disable(); // If you want to allow uploading only 1 file at time, you can disable upload button
						interval = window.setInterval(function(){
							var text = clickedObject.text();
							if (text.length < 13){	clickedObject.text(text + '.'); }
							else { clickedObject.text('Uploading'); } 
						}, 200);
				  },
				  onComplete: function(file, response) {
				   
					window.clearInterval(interval);
					clickedObject.text('Upload Image');	
					this.enable(); // enable upload button
					
					// If there was an error
					if(response.search('Upload Error') > -1){
						var buildReturn = '<span class="upload-error">' + response + '</span>';
						jQuery(".upload-error").remove();
						clickedObject.parent().after(buildReturn);
					
					}
					else{
						var buildReturn = '<img class="hide of-option-image" id="image_'+clickedID+'" src="'+response+'" alt="" />';

						jQuery(".upload-error").remove();
						jQuery("#image_" + clickedID).remove();	
						clickedObject.parent().after(buildReturn);
						jQuery('img#image_'+clickedID).fadeIn();
						clickedObject.next('span').fadeIn();
						clickedObject.parent().prev('input').val(response);
					}
				  }
				});
			
			});
			
			//AJAX Remove (clear option value)
			jQuery('.image_reset_button').click(function(){
			
					var clickedObject = jQuery(this);
					var clickedID = jQuery(this).attr('id');
					var theID = jQuery(this).attr('title');	
	
					var ajax_url = '<?php echo admin_url("admin-ajax.php"); ?>';
				
					var data = {
						action: 'of_ajax_post_action',
						type: 'image_reset',
						data: theID
					};
					
					jQuery.post(ajax_url, data, function(response) {
						var image_to_remove = jQuery('#image_' + theID);
						var button_to_hide = jQuery('#reset_' + theID);
						image_to_remove.fadeOut(500,function(){ jQuery(this).remove(); });
						button_to_hide.fadeOut();
						clickedObject.parent().prev('input').val('');
						
						
						
					});
					
					return false; 
					
				});   	 	
			
			//Save everything else
			jQuery('#ofform').submit(function(){
				
					function newValues() {
					  var serializedValues = jQuery("#ofform").serialize();
					  return serializedValues;
					}
					jQuery(":checkbox, :radio").click(newValues);
					jQuery("select").change(newValues);
					jQuery('.ajax-loading-img').fadeIn();
					var serializedReturn = newValues();
					 
					var ajax_url = '<?php echo admin_url("admin-ajax.php"); ?>';
				
					 //var data = {data : serializedReturn};
					var data = {
						<?php if(isset($_REQUEST['page']) && $_REQUEST['page'] == 'optionsframework'){ ?>
						type: 'options',
						<?php } ?>

						action: 'of_ajax_post_action',
						data: serializedReturn
					};
					
					jQuery.post(ajax_url, data, function(response) {
						var success = jQuery('#of-popup-save');
						var loading = jQuery('.ajax-loading-img');
						loading.fadeOut();  
						success.fadeIn();
						window.setTimeout(function(){
						   success.fadeOut(); 
						   
												
						}, 2000);
					});
					
					return false; 
					
				});   	 	
				
			});
            
     
            
		</script>
<?php }
}

/*-----------------------------------------------------------------------------------*/
/* Ajax Save Action - of_ajax_callback */
/*-----------------------------------------------------------------------------------*/

add_action('wp_ajax_of_ajax_post_action', 'of_ajax_callback');

function of_ajax_callback() {
	global $wpdb; // this is how you get access to the database
	
		
	$save_type = $_POST['type'];
	//Uploads
	if($save_type == 'upload'){
		
		$clickedID = $_POST['data']; // Acts as the name
		$filename = $_FILES[$clickedID];
       	$filename['name'] = preg_replace('/[^a-zA-Z0-9._\-]/', '', $filename['name']); 
		
		$override['test_form'] = false;
		$override['action'] = 'wp_handle_upload';    
		$uploaded_file = wp_handle_upload($filename,$override);
		 
				$upload_tracking[] = $clickedID;
				update_option( $clickedID , $uploaded_file['url'] );
				
		 if(!empty($uploaded_file['error'])) {echo 'Upload Error: ' . $uploaded_file['error']; }	
		 else { echo $uploaded_file['url']; } // Is the Response
	}
	elseif($save_type == 'image_reset'){
			
			$id = $_POST['data']; // Acts as the name
			global $wpdb;
			$query = "DELETE FROM $wpdb->options WHERE option_name LIKE '$id'";
			$wpdb->query($query);
	
	}	
	elseif ($save_type == 'options' OR $save_type == 'framework') {
		$data = $_POST['data'];
		
		parse_str($data,$output);
		//print_r($output);
		
		//Pull options
        	$options = get_option('of_template');
		
		foreach($options as $option_array){

			$id = $option_array['id'];
			$old_value = get_option($id);
			$new_value = '';
			
			if(isset($output[$id])){
				$new_value = $output[$option_array['id']];
			}
	
			if(isset($option_array['id'])) { // Non - Headings...

			
					$type = $option_array['type'];
					
					if ( is_array($type)){
						foreach($type as $array){
							if($array['type'] == 'text'){
								$id = $array['id'];
								$std = $array['std'];
								$new_value = $output[$id];
								if($new_value == ''){ $new_value = $std; }
								update_option( $id, stripslashes($new_value));
							}
						}                 
					}
					elseif($new_value == '' && $type == 'checkbox'){ // Checkbox Save
						
						update_option($id,'false');
					}
					elseif ($new_value == 'true' && $type == 'checkbox'){ // Checkbox Save
						
						update_option($id,'true');
					}
					elseif($type == 'multicheck'){ // Multi Check Save
						
						$option_options = $option_array['options'];
						
						foreach ($option_options as $options_id => $options_value){
							
							$multicheck_id = $id . "_" . $options_id;
							
							if(!isset($output[$multicheck_id])){
							  update_option($multicheck_id,'false');
							}
							else{
							   update_option($multicheck_id,'true'); 
							}
						}
					} 
					elseif($type == 'typography'){
							
						$typography_array = array();	
						
						$typography_array['size'] = $output[$option_array['id'] . '_size'];
                        
                        $typography_array['descriptionsize'] = $output[$option_array['id'] . '_descriptionsize'];                                                
							
						$typography_array['face'] = stripslashes($output[$option_array['id'] . '_face']);
							
						$typography_array['style'] = $output[$option_array['id'] . '_style'];
							
						$typography_array['color'] = $output[$option_array['id'] . '_color'];
							
						update_option($id,$typography_array);
							
					}
                    elseif($type == 'typography_description'){
							
						$typography_description_array = array();	
						
						$typography_description_array['size'] = $output[$option_array['id'] . '_size'];
                        
                        $typography_description_array['descriptionsize'] = $output[$option_array['id'] . '_descriptionsize'];
							
						$typography_description_array['face'] = stripslashes($output[$option_array['id'] . '_face']);
							
						$typography_description_array['style'] = $output[$option_array['id'] . '_style'];
							
						$typography_description_array['color'] = $output[$option_array['id'] . '_color'];
							
						update_option($id,$typography_description_array);
							
					}                    
					elseif($type == 'border'){
							
						$border_array = array();	
						
						$border_array['width'] = $output[$option_array['id'] . '_width'];
							
						$border_array['style'] = $output[$option_array['id'] . '_style'];
							
						$border_array['color'] = $output[$option_array['id'] . '_color'];
							
						update_option($id,$border_array);
							
					}
                    
                    elseif($type == 'headings'){
							
						$heading_array = array();	
						
						$heading_array['color'] = $output[$option_array['id'] . '_color'];
							
						$heading_array['fonttype'] = $output[$option_array['id'] . '_fonttype'];
							
						update_option($id,$heading_array);
							
					}
                    
                    elseif($type == 'background'){
							
						$background_array = array();	
						
						$background_array['color'] = $output[$option_array['id'] . '_color'];
							
						$background_array['position'] = $output[$option_array['id'] . '_position'];
							
						$background_array['repeate'] = $output[$option_array['id'] . '_repeate'];
							
						update_option($id,$background_array);
							
					}
                    
					elseif($type != 'upload_min'){
					
						update_option($id,stripslashes($new_value));
					}
				}
			}	
	
	}

  die();

}



/*-----------------------------------------------------------------------------------*/
/* Generates The Options Within the Panel - optionsframework_machine */
/*-----------------------------------------------------------------------------------*/

function optionsframework_machine($options) {
        
    $counter = 0;
	$menu = '';
	$output = '';
    
        
         
	foreach ($options as $value) {
	   
    
		$counter++;
		$val = '';
		//Start Heading
         
		 //End Heading  
		  if ( $value['type'] != "heading" )
		 {
		 	

		  
         
         if ( $value['type'] == "line" ){
               $class = ''; if(isset( $value['class'] )) { $class = $value['class']; }
			//$output .= '<div class="section section-'. $value['type'] .'">'."\n".'<div class="option-inner">'."\n";
			$output .= '<div class="section section-'.$value['type'].' '. $class .'">'."\n";
                $output .= '<div class="line_title">'. $value['name'] .'
                
                
                <input type="submit" value="Save" class="button-primary-save" />
                <div class="clear"></div>
                
                </div>'."\n";
    			$output .= '<div class="option">'."\n" . '<div class="controls">'."\n";
            
            } else {
                $class = ''; if(isset( $value['class'] )) { $class = $value['class']; }
    			//$output .= '<div class="section section-'. $value['type'] .'">'."\n".'<div class="option-inner">'."\n";
    			$output .= '<div class="section section-'.$value['type'].' '. $class .'">'."\n";
    			$output .= '<div class="heading-left"><h4 class="heading">'. $value['name'] .'</h4></div>'."\n";
               
               
                $output .= '<div class="option">'."\n" . '<div class="controls">'."\n";
            }
         
         }
         
         
		$select_value = '';                                   
		switch ( $value['type'] ) {
		
        
    
		case 'text':
			$val = $value['std'];
			$std = get_option($value['id']);
			if ( $std != "") { $val = $std; }
			$output .= '<input class="of-input" name="'. $value['id'] .'" id="'. $value['id'] .'" type="'. $value['type'] .'" value="'. $val .'" />';
		break;
        
        case 'slider':
            
			$val = $value['value'];
			$std = get_option($value['id']);
			if ( $std != "") { $val = $std; }
            $output .= '<script>
                    	$(function() {
                    		$( "#'. $value['sliderid'] .'" ).slider({
                    			range: "'. $value['range'] .'",
                    			value: '. $val .',
                                step: '. $value['step'] .',
                    			min: '. $value['min'] .',
                    			max: '. $value['max'] .',
                    			slide: function( event, ui ) {
                    				$( "#'. $value['id'] .'" ).val( ui.value );
                    			}
                    		});
                    		$( "#'. $value['id'] .'" ).val( $( "#'. $value['sliderid'] .'" ).slider( "value" ) );
                    	});
                    	</script>';
			$output .= '<div class="slider-all-frame"><div class="slider-class">
                            <div id="'. $value['sliderid'] .'" >
                            </div>
                        </div> 
                        <div class="slider-frame-class">
                            <input class="of-input-slider" type="textslider" name="'. $value['id'] .'" id="'. $value['id'] .'"  />
                            <label>'. $value['object'] .'</label>
                        </div></div>
                        <div class="clear"></div>
                        <div class="slider-first-value">'. $value['min'] .' '. $value['object'] .'</div><div class="slider-second-value">'. $value['max'] .' '. $value['object'] .'</div>
                        ';
        break;
		
		case 'select':

			$output .= '<select class="of-input" name="'. $value['id'] .'" id="'. $value['id'] .'">';
		
			$select_value = get_option($value['id']);
			 
			foreach ($value['options'] as $option) {
				
				$selected = '';
				
				 if($select_value != '') {
					 if ( $select_value == $option) { $selected = ' selected="selected"';} 
			     } else {
					 if ( isset($value['std']) )
						 if ($value['std'] == $option) { $selected = ' selected="selected"'; }
				 }
				  
				 $output .= '<option'. $selected .'>';
				 $output .= $option;
				 $output .= '</option>';
			 
			 } 
			 $output .= '</select>';

			
		break;
		case 'select2':

			$output .= '<select class="of-input" name="'. $value['id'] .'" id="'. $value['id'] .'">';
		
			$select_value = get_option($value['id']);
			 
			foreach ($value['options'] as $option => $name) {
				
				$selected = '';
				
				 if($select_value != '') {
					 if ( $select_value == $option) { $selected = ' selected="selected"';} 
			     } else {
					 if ( isset($value['std']) )
						 if ($value['std'] == $option) { $selected = ' selected="selected"'; }
				 }
				  
				 $output .= '<option'. $selected .' value="'.$option.'">';
				 $output .= $name;
				 $output .= '</option>';
			 
			 } 
			 $output .= '</select>';

			
		break;
		case 'textarea':
			
			$cols = '8';
			$ta_value = '';
			
			if(isset($value['std'])) {
				
				$ta_value = $value['std']; 
				
				if(isset($value['options'])){
					$ta_options = $value['options'];
					if(isset($ta_options['cols'])){
					$cols = $ta_options['cols'];
					} else { $cols = '8'; }
				}
				
			}
				$std = get_option($value['id']);
				if( $std != "") { $ta_value = stripslashes( $std ); }
				$output .= '<textarea class="of-input" name="'. $value['id'] .'" id="'. $value['id'] .'" cols="'. $cols .'" rows="8">'.$ta_value.'</textarea>';
			
			
		break;
		case "radio":
			
			 $select_value = get_option( $value['id']);
				   
			 foreach ($value['options'] as $key => $option) 
			 { 

				 $checked = '';
				   if($select_value != '') {
						if ( $select_value == $key) { $checked = ' checked'; } 
				   } else {
					if ($value['std'] == $key) { $checked = ' checked'; }
				   }
				$output .= '<input class="of-input of-radio" type="radio" name="'. $value['id'] .'" value="'. $key .'" '. $checked .' />' . $option .'<br />';
			
			}
			 
		break;
		case "checkbox": 
  
		   $std = $value['std'];  
		   
		   $saved_std = get_option($value['id']);
		   
		   $checked = '';
			
			if(!empty($saved_std)) {
				if($saved_std == 'true') {
				$checked = 'checked="checked"';
                
				}
				else{
				   $checked = '';
                   
				}
			}
			elseif( $std == 'true') {
			   $checked = 'checked="checked"';
               
			}
			else {
				$checked = ''; 
               
			}
			$output .= '<input type="checkbox" class="checkbox of-input" name="'.  $value['id'] .'" id="'. $value['id'] .'" value="true" '. $checked .' />';

		break;
		case "multicheck":
		
			$std =  $value['std'];         
			
			foreach ($value['options'] as $key => $option) {
											 
			$of_key = $value['id'] . '_' . $key;
			$saved_std = get_option($of_key);
					
			if(!empty($saved_std)) 
			{ 
				  if($saved_std == 'true'){
					 $checked = 'checked="checked"';  
				  } 
				  else{
					  $checked = '';     
				  }    
			} 
			elseif( $std == $key) {
			   $checked = 'checked="checked"';
			}
			else {
				$checked = '';                                                                                    }
			$output .= '<input type="checkbox" class="checkbox of-input" name="'. $of_key .'" id="'. $of_key .'" value="true" '. $checked .' /><label for="'. $of_key .'">'. $option .'</label><br />';
										
			}
		break;
		case "upload":
			
			$output .= optionsframework_uploader_function($value['id'],$value['std'],null);
			
		break;
		case "upload_min":
			
			$output .= optionsframework_uploader_function($value['id'],$value['std'],'min');
			
		break;
		case "color":
			$val = $value['std'];
			$stored  = get_option( $value['id'] );
			if ( $stored != "") { $val = $stored; }
			$output .= '<div id="' . $value['id'] . '_picker" class="colorSelector"><div></div></div>';
			$output .= '<input class="of-color" name="'. $value['id'] .'" id="'. $value['id'] .'" type="text" value="'. $val .'" />';
		break;   
		
		case "typography":
		
			$default = $value['std'];
			$typography_stored = get_option($value['id']);
			
			/* Font Size */
			$val = $default['size'];
			if ( $typography_stored['size'] != "") { $val = $typography_stored['size']; }
			$output .= '<select class="of-typography of-typography-size" name="'. $value['id'].'_size" id="'. $value['id'].'_size">';
				for ($i = 9; $i < 71; $i++){ 
					if($val == $i){ $active = 'selected="selected"'; } else { $active = ''; }
					$output .= '<option value="'. $i .'" ' . $active . '>'. $i .'px</option>'; }
			$output .= '</select>';
   
                         
			/* Font Face */
			$val = $default['face'];
			if ( $typography_stored['face'] != "") 
				$val = $typography_stored['face']; 

			$font01 = ''; 
			$font02 = ''; 
			$font03 = ''; 
			$font04 = ''; 
			$font05 = ''; 
			$font06 = ''; 
			$font07 = ''; 
			$font08 = '';
			$font09 = '';

			if (strpos($val, 'Arial, sans-serif') !== false){ $font01 = 'selected="selected"'; }
			if (strpos($val, 'Verdana, Geneva') !== false){ $font02 = 'selected="selected"'; }
			if (strpos($val, 'Trebuchet') !== false){ $font03 = 'selected="selected"'; }
			if (strpos($val, 'Georgia') !== false){ $font04 = 'selected="selected"'; }
			if (strpos($val, 'Times New Roman') !== false){ $font05 = 'selected="selected"'; }
			if (strpos($val, 'Tahoma, Geneva') !== false){ $font06 = 'selected="selected"'; }
			if (strpos($val, 'Palatino') !== false){ $font07 = 'selected="selected"'; }
			if (strpos($val, 'Helvetica') !== false){ $font08 = 'selected="selected"'; }
			
			$output .= '<select class="of-typography of-typography-face" name="'. $value['id'].'_face" id="'. $value['id'].'_face">';
			$output .= '<option value="Arial, sans-serif" '. $font01 .'>Arial</option>';
			$output .= '<option value="Verdana, Geneva, sans-serif" '. $font02 .'>Verdana</option>';
			$output .= '<option value="&quot;Trebuchet MS&quot;, Tahoma, sans-serif"'. $font03 .'>Trebuchet</option>';
			$output .= '<option value="Georgia, serif" '. $font04 .'>Georgia</option>';
			$output .= '<option value="&quot;Times New Roman&quot;, serif"'. $font05 .'>Times New Roman</option>';
			$output .= '<option value="Tahoma, Geneva, Verdana, sans-serif"'. $font06 .'>Tahoma</option>';
			$output .= '<option value="Palatino, &quot;Palatino Linotype&quot;, serif"'. $font07 .'>Palatino</option>';
			$output .= '<option value="&quot;Helvetica Neue&quot;, Helvetica, sans-serif" '. $font08 .'>Helvetica*</option>';
			$output .= '</select>';
			
			/* Font Weight */
			$val = $default['style'];
			if ( $typography_stored['style'] != "") { $val = $typography_stored['style']; }
				$normal = ''; $italic = ''; $bold = ''; $bolditalic = '';
			if($val == 'normal'){ $normal = 'selected="selected"'; }
			if($val == 'italic'){ $italic = 'selected="selected"'; }
			if($val == 'bold'){ $bold = 'selected="selected"'; }
			if($val == 'bold italic'){ $bolditalic = 'selected="selected"'; }
			
			$output .= '<select class="of-typography of-typography-style" name="'. $value['id'].'_style" id="'. $value['id'].'_style">';
			$output .= '<option value="normal" '. $normal .'>Normal</option>';
			$output .= '<option value="italic" '. $italic .'>Italic</option>';
			$output .= '<option value="bold" '. $bold .'>Bold</option>';
			$output .= '<option value="bold italic" '. $bolditalic .'>Bold/Italic</option>';
			$output .= '</select>';
			
			/* Font Color */
			$val = $default['color'];
			if ( $typography_stored['color'] != "") { $val = $typography_stored['color']; }			
			$output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div></div></div>';
			$output .= '<input class="of-color of-typography of-typography-color" name="'. $value['id'] .'_color" id="'. $value['id'] .'_color" type="text" value="'. $val .'" />';

		break; 
        
        case "typography_description":
		
			$default = $value['std'];
			$typography_description_stored = get_option($value['id']);
			
			/* Font Size */
			$val = $default['size'];
			if ( $typography_description_stored['size'] != "") { $val = $typography_description_stored['size']; }
			$output .= '<select class="of-typography of-typography-size" name="'. $value['id'].'_size" id="'. $value['id'].'_size">';
				for ($i = 9; $i < 13; $i++){ 
					if($val == $i){ $active = 'selected="selected"'; } else { $active = ''; }
					$output .= '<option value="'. $i .'" ' . $active . '>'. $i .'px</option>'; }
			$output .= '</select>';

			/* Font Face */
			$val = $default['face'];
			if ( $typography_description_stored['face'] != "") 
				$val = $typography_description_stored['face']; 

			$font01 = ''; 
			$font02 = ''; 
			$font03 = ''; 
			$font04 = ''; 
			$font05 = ''; 
			$font06 = ''; 
			$font07 = ''; 
			$font08 = '';
			$font09 = '';

			if (strpos($val, 'Arial, sans-serif') !== false){ $font01 = 'selected="selected"'; }
			if (strpos($val, 'Verdana, Geneva') !== false){ $font02 = 'selected="selected"'; }
			if (strpos($val, 'Trebuchet') !== false){ $font03 = 'selected="selected"'; }
			if (strpos($val, 'Georgia') !== false){ $font04 = 'selected="selected"'; }
			if (strpos($val, 'Times New Roman') !== false){ $font05 = 'selected="selected"'; }
			if (strpos($val, 'Tahoma, Geneva') !== false){ $font06 = 'selected="selected"'; }
			if (strpos($val, 'Palatino') !== false){ $font07 = 'selected="selected"'; }
			if (strpos($val, 'Helvetica') !== false){ $font08 = 'selected="selected"'; }
			
			$output .= '<select class="of-typography of-typography-face" name="'. $value['id'].'_face" id="'. $value['id'].'_face">';
			$output .= '<option value="Arial, sans-serif" '. $font01 .'>Arial</option>';
			$output .= '<option value="Verdana, Geneva, sans-serif" '. $font02 .'>Verdana</option>';
			$output .= '<option value="&quot;Trebuchet MS&quot;, Tahoma, sans-serif"'. $font03 .'>Trebuchet</option>';
			$output .= '<option value="Georgia, serif" '. $font04 .'>Georgia</option>';
			$output .= '<option value="&quot;Times New Roman&quot;, serif"'. $font05 .'>Times New Roman</option>';
			$output .= '<option value="Tahoma, Geneva, Verdana, sans-serif"'. $font06 .'>Tahoma</option>';
			$output .= '<option value="Palatino, &quot;Palatino Linotype&quot;, serif"'. $font07 .'>Palatino</option>';
			$output .= '<option value="&quot;Helvetica Neue&quot;, Helvetica, sans-serif" '. $font08 .'>Helvetica*</option>';
			$output .= '</select>';
			
			/* Font Weight */
			$val = $default['style'];
			if ( $typography_description_stored['style'] != "") { $val = $typography_description_stored['style']; }
				$normal = ''; $italic = ''; $bold = ''; $bolditalic = '';
			if($val == 'normal'){ $normal = 'selected="selected"'; }
			if($val == 'italic'){ $italic = 'selected="selected"'; }
			if($val == 'bold'){ $bold = 'selected="selected"'; }
			if($val == 'bold italic'){ $bolditalic = 'selected="selected"'; }
			
			$output .= '<select class="of-typography of-typography-style" name="'. $value['id'].'_style" id="'. $value['id'].'_style">';
			$output .= '<option value="normal" '. $normal .'>Normal</option>';
			$output .= '<option value="italic" '. $italic .'>Italic</option>';
			$output .= '<option value="bold" '. $bold .'>Bold</option>';
			$output .= '<option value="bold italic" '. $bolditalic .'>Bold/Italic</option>';
			$output .= '</select>';
			
			/* Font Color */
			$val = $default['color'];
			if ( $typography_description_stored['color'] != "") { $val = $typography_description_stored['color']; }			
			$output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div></div></div>';
			$output .= '<input class="of-color of-typography of-typography-color" name="'. $value['id'] .'_color" id="'. $value['id'] .'_color" type="text" value="'. $val .'" />';

		break;   
		
		case "border":
		
			$default = $value['std'];
			$border_stored = get_option( $value['id'] );
			
			/* Border Width */
			$val = $default['width'];
			if ( $border_stored['width'] != "") { $val = $border_stored['width']; }
			$output .= '<select class="of-border of-border-width" name="'. $value['id'].'_width" id="'. $value['id'].'_width">';
				for ($i = 0; $i < 100; $i++){ 
					if($val == $i){ $active = 'selected="selected"'; } else { $active = ''; }
					$output .= '<option value="'. $i .'" ' . $active . '>'. $i .'px</option>'; }
			$output .= '</select>';
			
			/* Border Style */
			$val = $default['style'];
			if ( $border_stored['style'] != "") { $val = $border_stored['style']; }
				$solid = ''; $dashed = ''; $dotted = '';
			if($val == 'solid'){ $solid = 'selected="selected"'; }
			if($val == 'dashed'){ $dashed = 'selected="selected"'; }
			if($val == 'dotted'){ $dotted = 'selected="selected"'; }
			
			$output .= '<select class="of-border of-border-style" name="'. $value['id'].'_style" id="'. $value['id'].'_style">';
			$output .= '<option value="solid" '. $solid .'>Solid</option>';
			$output .= '<option value="dashed" '. $dashed .'>Dashed</option>';
			$output .= '<option value="dotted" '. $dotted .'>Dotted</option>';
			$output .= '</select>';
			
			/* Border Color */
			$val = $default['color'];
			if ( $border_stored['color'] != "") { $val = $border_stored['color']; }			
			$output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div></div></div>';
			$output .= '<input class="of-color of-border of-border-color" name="'. $value['id'] .'_color" id="'. $value['id'] .'_color" type="text" value="'. $val .'" />';

		break;   
        
        case "headings":
	
			$default = $value['std'];
			$heading_stored = get_option( $value['id'] );
			
            /* Heading Color */
			$val = $default['color'];
			if ( $heading_stored['color'] != "") { $val = $heading_stored['color']; }			
			$output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div></div></div>';
			$output .= '<input class="of-color of-border of-border-color" name="'. $value['id'] .'_color" id="'. $value['id'] .'_color" type="text" value="'. $val .'" />';

            /* Heading Font Type */
			$val = $default['fonttype'];
			if ( $heading_stored['fonttype'] != "") { $val = $heading_stored['fonttype']; }
			$f1 = ''; $f2 = ''; $f3 = ''; $f4 = ''; $f5 = ''; $f6 = ''; $f7 = ''; $f8 = ''; $f9 = ''; $f10 = ''; $f11 = ''; $f12 = ''; $f13 = '';
			if($val == 'PT Sans Narrow'){ $f13 = 'selected="selected"'; }
            if($val == 'ColaborateLight'){ $f1 = 'selected="selected"'; }
            if($val == 'Colaborate-Regular'){ $f2 = 'selected="selected"'; }
            if($val == 'Diavlo Book'){ $f3 = 'selected="selected"'; }
            if($val == 'Aller Light'){ $f4 = 'selected="selected"'; }
            if($val == 'Marketing Script'){ $f5 = 'selected="selected"'; }
            if($val == 'NeoRetroDraw'){ $f6 = 'selected="selected"'; }
            if($val == 'NeoRetroFill'){ $f7 = 'selected="selected"'; }
            if($val == 'Ubuntu-Title'){ $f8 = 'selected="selected"'; }
            if($val == 'UglyQua'){ $f9 = 'selected="selected"'; }
            if($val == 'Universal fruitcake'){ $f10 = 'selected="selected"'; }
            if($val == 'Yanone Kaffeesatz Light'){ $f11 = 'selected="selected"'; }
            if($val == 'Yanone Kaffeesatz Regular'){ $f12 = 'selected="selected"'; }

			
			$output .= '<select class="of-border of-border-style of-border-style-headings" name="'. $value['id'].'_fonttype" id="'. $value['id'].'_fonttype">';
			$output .= '<option value="PT&#32;Sans&#32;Narrow" '. $f13 .'>PT Sans Narrow</option>';
            $output .= '<option value="ColaborateLight" '. $f1 .'>Colaborate Light</option>';
            $output .= '<option value="Colaborate-Regular" '. $f2 .'>Colaborate Regular</option>';
            $output .= '<option value="Diavlo&#32;Book" '. $f3 .'>Diavlo Book</option>';
            $output .= '<option value="Aller&#32;Light" '. $f4 .'>Aller Light</option>';
            $output .= '<option value="Marketing&#32;Script" '. $f5 .'>Marketing Script</option>';
            $output .= '<option value="NeoRetroDraw" '. $f6 .'>Neo Retro Draw</option>';
            $output .= '<option value="NeoRetroFill" '. $f7 .'>Neo Retro Fill</option>';
            $output .= '<option value="Ubuntu-Title" '. $f8 .'>Ubuntu Title</option>';
            $output .= '<option value="UglyQua" '. $f9 .'>Ugly Qua</option>';
            $output .= '<option value="Universal&#32;fruitcake" '. $f10 .'>Universal Fruitcake</option>';
            $output .= '<option value="Yanone&#32;Kaffeesatz&#32;Light" '. $f11 .'>Yanone Kaffeesatz Light</option>';
            $output .= '<option value="Yanone&#32;Kaffeesatz&#32;Regular" '. $f12 .'>Yanone Kaffeesatz Regular</option>';
            
            $output .= '</select>';            
      
	    break;
        
        case "background":
	
			$default = $value['std'];
			$background_stored = get_option( $value['id'] );
			
            /* Background Color */
			$val = $default['color'];
			if ( $background_stored['color'] != "") { $val = $background_stored['color']; }			
			$output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div></div></div>';
			$output .= '<input class="of-color of-border of-border-color" name="'. $value['id'] .'_color" id="'. $value['id'] .'_color" type="text" value="'. $val .'" />';

            
			/* Background Repeate */
			$val = $default['repeate'];
			if ( $background_stored['repeate'] != "") { $val = $background_stored['repeate']; }
			$norepeat = ''; $repeat = ''; $repeatx = ''; $repeatx = '';

            if($val == 'no-repeat'){ $norepeat = 'selected="selected"'; }                    
			if($val == 'repeat'){ $repeat = 'selected="selected"'; }
			if($val == 'repeat-x'){ $repeatx = 'selected="selected"'; }
			if($val == 'repeat-y'){ $repeaty = 'selected="selected"'; }
			
			$output .= '<select class="of-border of-border-style" name="'. $value['id'].'_repeate" id="'. $value['id'].'_repeate">';

            $output .= '<option value="no-repeat" '. $norepeat .'>no-repeat</option>';
            $output .= '<option value="repeat" '. $repeat .'>repeat</option>';
			$output .= '<option value="repeat-x" '. $repeatx .'>repeat-x</option>';
			$output .= '<option value="repeat-y" '. $repeaty .'>repeat-y</option>';
			$output .= '</select>';
            
			/* Background Position */
			$val = $default['position'];
			if ( $background_stored['position'] != "") { $val = $background_stored['position']; }
				$left = ''; $right = ''; $top = ''; $bottom = ''; $center = ''; $inherit = '';
		
            if($val == 'left'){ $left = 'selected="selected"'; }
			if($val == 'right'){ $right = 'selected="selected"'; }
			if($val == 'top'){ $top = 'selected="selected"'; }
            if($val == 'bottom'){ $bottom = 'selected="selected"'; }
            if($val == 'center'){ $center = 'selected="selected"'; }
            if($val == 'inherit'){ $inherit = 'selected="selected"'; }
			
			$output .= '<select class="of-border of-border-style" name="'. $value['id'].'_position" id="'. $value['id'].'_position">';

            $output .= '<option value="left" '. $left .'>Left</option>';
			$output .= '<option value="right" '. $right .'>Right</option>';
			$output .= '<option value="top" '. $top .'>Top</option>';
            $output .= '<option value="bottom" '. $bottom .'>Bottom</option>';
            $output .= '<option value="center" '. $center .'>Center</option>';
            $output .= '<option value="inherit" '. $inherit .'>Inherit</option>';
			$output .= '</select>';

	    break;
		
		case "images":
			$i = 0;
			$select_value = get_option( $value['id']);
				   
			foreach ($value['options'] as $key => $option) 
			 { 
			 $i++;

				 $checked = '';
				 $selected = '';
				   if($select_value != '') {
						if ( $select_value == $key) { $checked = ' checked'; $selected = 'of-radio-img-selected'; } 
				    } else {
						if ($value['std'] == $key) { $checked = ' checked'; $selected = 'of-radio-img-selected'; }
						elseif ($i == 1  && !isset($select_value)) { $checked = ' checked'; $selected = 'of-radio-img-selected'; }
						elseif ($i == 1  && $value['std'] == '') { $checked = ' checked'; $selected = 'of-radio-img-selected'; }
						else { $checked = ''; }
					}	
				
				$output .= '<span>';
				$output .= '<input type="radio" id="of-radio-img-' . $value['id'] . $i . '" class="checkbox of-radio-img-radio" value="'.$key.'" name="'. $value['id'].'" '.$checked.' />';
				$output .= '<div class="of-radio-img-label">'. $key .'</div>';
				$output .= '<img src="'.$option.'" alt="" class="of-radio-img-img '. $selected .'" onClick="document.getElementById(\'of-radio-img-'. $value['id'] . $i.'\').checked = true;" />';
				$output .= '</span>';
				
			}
		
		break; 
		
		case "info":
			$default = $value['std'];
			$output .= $default;
		break;                                   
		
		case "heading":
			
			if($counter >= 2){
			   $output .= '</div>'."\n";
			}
			$jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']) );
			$jquery_click_hook = "of-option-" . $jquery_click_hook;
			$menu .= '<li><a style="background-image:url('.  $value['icon'] .')" title="'.  $value['name'] .'" href="#'.  $jquery_click_hook  .'">'.  $value['name'] .'</a></li>';
			$output .= '<div class="group" id="'. $jquery_click_hook  .'"><h2>'.$value['name'].'</h2>'."\n";
		break;                                  
		} 
		
		// if TYPE is an array, formatted into smaller inputs... ie smaller values
		if ( is_array($value['type'])) {
			foreach($value['type'] as $array){
			
					$id = $array['id']; 
					$std = $array['std'];
					$saved_std = get_option($id);
					if($saved_std != $std){$std = $saved_std;} 
					$meta = $array['meta'];
					
					if($array['type'] == 'text') { // Only text at this point
						 
						 $output .= '<input class="input-text-small of-input" name="'. $id .'" id="'. $id .'" type="text" value="'. $std .'" />';  
						 $output .= '<span class="meta-two">'.$meta.'</span>';
					}
				}
		}
		if ( $value['type'] != "heading" ) { 
			if ( $value['type'] != "checkbox" ) 
				{ 
				$output .= '<br/>';
				}
            
            $output .= '</div>';
            
             if ( $value['type'] == "line" ){} else {
                if(!isset($value['desc'])){ $explain_value = ''; } else{ $explain_value = $value['desc']; } 
    			$output .= '<div class="explain">'. $explain_value .'</div>'."\n";
			}
            
            $output .= '<div class="clear"> </div></div></div>'."\n";
			}
	 
    }
    $output .= '</div>';
    return array($output,$menu);

}



/*-----------------------------------------------------------------------------------*/
/* OptionsFramework Uploader - optionsframework_uploader_function */
/*-----------------------------------------------------------------------------------*/

function optionsframework_uploader_function($id,$std,$mod){

    //$uploader .= '<input type="file" id="attachement_'.$id.'" name="attachement_'.$id.'" class="upload_input"></input>';
    //$uploader .= '<span class="submit"><input name="save" type="submit" value="Upload" class="button upload_save" /></span>';
    
	$uploader = '';
    $upload = get_option($id);
	
	if($mod != 'min') { 
			$val = $std;
            if ( get_option( $id ) != "") { $val = get_option($id); }
            $uploader .= '<input class="of-input" name="'. $id .'" id="'. $id .'_upload" type="text" value="'. $val .'" />';
	}
	
	$uploader .= '<div class="upload_button_div"><span class="button image_upload_button" id="'.$id.'">Upload Image</span>';
	
	if(!empty($upload)) {$hide = '';} else { $hide = 'hide';}
	
	$uploader .= '<span class="button image_reset_button '. $hide.'" id="reset_'. $id .'" title="' . $id . '">Remove</span>';
	$uploader .='</div>' . "\n";
    $uploader .= '<div class="clear"></div>' . "\n";
	if(!empty($upload)){
    	$uploader .= '<a class="of-uploaded-image" href="'. $upload . '">';
    	$uploader .= '<img class="of-option-image" id="image_'.$id.'" src="'.$upload.'" alt="" />';
    	$uploader .= '</a>';
		}
	$uploader .= '<div class="clear"></div>' . "\n"; 


return $uploader;
}

?>
