' . "\n" . '
' . "\n";
			}
		}
		// Set default value to $val
		if ( isset( $value['std'] ) ) {
			$val = $value['std'];
		}
		// If the option is already saved, ovveride $val
		if ( ( $value['type'] != 'heading' ) && ( $value['type'] != 'info') ) {
			if ( isset( $settings[($value['id'])]) ) {
				$val = $settings[($value['id'])];
				// Striping slashes of non-array options
				if ( !is_array($val) ) {
					$val = stripslashes( $val );
				}
			}
		}
		// If there is a description save it for labels
		$explain_value = '';
		if ( isset( $value['desc'] ) ) {
			$explain_value = $value['desc'];
		}
		switch ( $value['type'] ) {
		// Basic text input
		case 'text':
			$output .= '
';
			break;
		// Password input
		case 'password':
			$output .= '
';
			break;
		// Textarea
		case 'textarea':
			$rows = '8';
			if ( isset( $value['settings']['rows'] ) ) {
				$custom_rows = $value['settings']['rows'];
				if ( is_numeric( $custom_rows ) ) {
					$rows = $custom_rows;
				}
			}
			$val = stripslashes( $val );
			$output .= '
';
			break;
		// Select Box
		case 'select':
			$output .= '
';
			break;
		// Radio Box
		case "radio":
			$name = $option_name .'['. $value['id'] .']';
			foreach ($value['options'] as $key => $option) {
				$id = $option_name . '-' . $value['id'] .'-'. $key;
				$output .= '
';
			}
			break;
		// Image Selectors
		case "images":
			$name = $option_name .'['. $value['id'] .']';
			foreach ( $value['options'] as $key => $option ) {
				$selected = '';
				if ( $val != '' && ($val == $key) ) {
					$selected = ' of-radio-img-selected';
				}
				$output .= '
';
				$output .= '
' . esc_html( $key ) . '
';
				$output .= '
 . ')
';
			}
			break;
			
		// colorradio Selectors
			case "colorradio":
				$name = $option_name .'['. $value['id'] .']';
				foreach ( $value['options'] as $key=>$key ) {
					$selected = '';
					$checked = '';
					if ( $val != '' ) {
						if ( $val == $key ) {
							$selected = ' of-radio-img-selected';
							$checked = ' checked="checked"';
						}
					}
					$output .= '
';
					$output .= '
' . esc_html( $key ) . '
';
					$output .= '
';
					// $output .= '
 . ')
';
				}
				break;	
		// Checkbox
		case "checkbox":
			$output .= '
';
			$output .= '
';
			break;
		// Multicheck
		case "multicheck":
			foreach ($value['options'] as $key => $option) {
				$checked = '';
				$label = $option;
				$option = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($key));
				$id = $option_name . '-' . $value['id'] . '-'. $option;
				$name = $option_name . '[' . $value['id'] . '][' . $option .']';
				if ( isset($val[$option]) ) {
					$checked = checked($val[$option], 1, false);
				}
				$output .= '
';
			}
			break;
		// Color picker
		case "color":
			$default_color = '';
			if ( isset($value['std']) ) {
				if ( $val !=  $value['std'] )
					$default_color = ' data-default-color="' .$value['std'] . '" ';
			}
			$output .= '
';
			break;
		// Uploader
		case "upload":
			$output .= optionsframework_uploader( $value['id'], $val, null );
			break;
		// Typography
		case 'typography':
			unset( $font_size, $font_style, $font_face, $font_color );
			$typography_defaults = array(
				'size' => '',
				'face' => '',
				'style' => '',
				'color' => ''
			);
			$typography_stored = wp_parse_args( $val, $typography_defaults );
			$typography_options = array(
				'sizes' => of_recognized_font_sizes(),
				'faces' => of_recognized_font_faces(),
				'styles' => of_recognized_font_styles(),
				'color' => true
			);
			if ( isset( $value['options'] ) ) {
				$typography_options = wp_parse_args( $value['options'], $typography_options );
			}
			// Font Size
			if ( $typography_options['sizes'] ) {
				$font_size = '
';
			}
			// Font Face
			if ( $typography_options['faces'] ) {
				$font_face = '
';
			}
			// Font Styles
			if ( $typography_options['styles'] ) {
				$font_style = '
';
			}
			// Font Color
			if ( $typography_options['color'] ) {
				$default_color = '';
				if ( isset( $value['std']['color'] ) ) {
					if ( $val !=  $value['std']['color'] )
						$default_color = ' data-default-color="' .$value['std']['color'] . '" ';
				}
				$font_color = '
';
			}
			// Allow modification/injection of typography fields
			$typography_fields = compact( 'font_size', 'font_face', 'font_style', 'font_color' );
			$typography_fields = apply_filters( 'of_typography_fields', $typography_fields, $typography_stored, $option_name, $value );
			$output .= implode( '', $typography_fields );
			break;
		// Background
		case 'background':
			$background = $val;
			// Background Color
			$default_color = '';
			if ( isset( $value['std']['color'] ) ) {
				if ( $val !=  $value['std']['color'] )
					$default_color = ' data-default-color="' .$value['std']['color'] . '" ';
			}
			$output .= '
';
			// Background Image
			if (!isset($background['image'])) {
				$background['image'] = '';
			}
			$output .= optionsframework_uploader( $value['id'], $background['image'], null, esc_attr( $option_name . '[' . $value['id'] . '][image]' ) );
			$class = 'of-background-properties';
			if ( '' == $background['image'] ) {
				$class .= ' hide';
			}
			$output .= '
';
			// Background Repeat
			$output .= '';
			// Background Position
			$output .= '';
			// Background Attachment
			$output .= '';
			$output .= '
';
			break;
		// Editor
		case 'editor':
			$output .= '
' . wp_kses( $explain_value, $allowedtags ) . '
'."\n";
			echo $output;
			$textarea_name = esc_attr( $option_name . '[' . $value['id'] . ']' );
			$default_editor_settings = array(
				'textarea_name' => $textarea_name,
				'media_buttons' => false,
				'tinymce' => array( 'plugins' => 'wordpress' )
			);
			$editor_settings = array();
			if ( isset( $value['settings'] ) ) {
				$editor_settings = $value['settings'];
			}
			$editor_settings = array_merge( $default_editor_settings, $editor_settings );
			wp_editor( $val, $value['id'], $editor_settings );
			$output = '';
			break;
		// Info
		case "info":
			$id = '';
			$class = 'section';
			if ( isset( $value['id'] ) ) {
				$id = 'id="' . esc_attr( $value['id'] ) . '" ';
			}
			if ( isset( $value['type'] ) ) {
				$class .= ' section-' . $value['type'];
			}
			if ( isset( $value['class'] ) ) {
				$class .= ' ' . $value['class'];
			}
			$output .= '
' . "\n";
			if ( isset($value['name']) ) {
				$output .= '
' . esc_html( $value['name'] ) . '
' . "\n";
			}
			if ( $value['desc'] ) {
				$output .= apply_filters('of_sanitize_info', $value['desc'] ) . "\n";
			}
			$output .= '' . "\n";
			break;
		// Heading for Navigation
		case "heading":
			$counter++;
			if ($counter >= 2) {
				$output .= '
'."\n";
			}
			$class = '';
			$class = ! empty( $value['id'] ) ? $value['id'] : $value['name'];
			$class = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($class) );
			$output .= '
';
			if ( ( $value['type'] != "checkbox" ) && ( $value['type'] != "editor" ) ) {
				$output .= '
' . wp_kses( $explain_value, $allowedtags ) . '