<?PHP 
$webfonts = array ( array("name" => "Allan", "variant" => ""),
					array("name" => "Allerta", "variant" => ""),
					array("name" => "Allerta Stencil", "variant" => ""),
					array("name" => "Amaranth", "variant" => ""),
					array("name" => "Anonymous Pro", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Anton", "variant" => ""),
					array("name" => "Architects Daughter", "variant" => ""),
					array("name" => "Arimo", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Arvo", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Bentham", "variant" => ""),
					array("name" => "Bevan", "variant" => ""),
					array("name" => "Cabin", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Cabin Sketch", "variant" => ""),
					array("name" => "Calligraffitti", "variant" => ""),
					array("name" => "Candal", "variant" => ""),
					array("name" => "Cantarell", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Cardo", "variant" => ""),
					array("name" => "Cherry Cream", "variant" => ""),
					array("name" => "Chewy", "variant" => ""),
					array("name" => "Coda", "variant" => ""),
					array("name" => "Coming Soon", "variant" => ""),
					array("name" => "Copse", "variant" => ""),
					array("name" => "Corben", "variant" => ""),
					array("name" => "Cousine", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Covered By Your Grace", "variant" => ""),
					array("name" => "Crafty", "variant" => ""),
					array("name" => "Crimson Text", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Crushed", "variant" => ""),
					array("name" => "Cuprum", "variant" => ""),
					array("name" => "Dancing Script", "variant" => ""),
					array("name" => "Droid Sans", "variant" => "regular,bold"),
					array("name" => "Droid Sans Mono", "variant" => ""),
					array("name" => "Droid Serif", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "EB Garamond", "variant" => ""),
					array("name" => "Expletus Sans", "variant" => "400,500,600,700"),
					array("name" => "Fontdiner Swanky", "variant" => ""),
					array("name" => "Geo", "variant" => ""),
					array("name" => "Goudy Bookletter 1911", "variant" => ""),
					array("name" => "Gruppo", "variant" => ""),
					array("name" => "Homemade Apple", "variant" => ""),
					array("name" => "IM Fell DW Pica", "variant" => "regular,italic"),
					array("name" => "Inconsolata", "variant" => ""),
					array("name" => "Indie Flower", "variant" => ""),
					array("name" => "Irish Grover", "variant" => ""),
					array("name" => "Josefin Sans", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Josefin Slab", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Just Another Hand", "variant" => ""),
					array("name" => "Just Me Again Down Here", "variant" => ""),
					array("name" => "Kenia", "variant" => ""),
					array("name" => "Kranky", "variant" => ""),
					array("name" => "Kreon", "variant" => "300,400,700"),
					array("name" => "Kristi", "variant" => ""),
					array("name" => "Lato", "variant" => ""),
					array("name" => "League Script", "variant" => ""),
					array("name" => "Lekton", "variant" => "400,italic,700"),
					array("name" => "Lobster", "variant" => ""),
					array("name" => "Luckiest Guy ", "variant" => ""),
					array("name" => "Meddon", "variant" => ""),
					array("name" => "MedievalSharp", "variant" => ""),
					array("name" => "Merriweather", "variant" => ""),
					array("name" => "Molengo", "variant" => ""),
					array("name" => "Mountains of Christmas", "variant" => ""),
					array("name" => "Neucha", "variant" => ""),
					array("name" => "Neuton", "variant" => "regular,italic"),
					array("name" => "Nobile", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Nova Round", "variant" => ""),
					array("name" => "OFL Sorts Mill Goudy TT", "variant" => "regular,italic"),
					array("name" => "Old Standard TT", "variant" => "regular,italic,bold"),
					array("name" => "Orbitron", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Oswald", "variant" => ""),
					array("name" => "PT Sans", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "PT Serif", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Pacifico", "variant" => ""),
					array("name" => "Permanent Marker", "variant" => ""),
					array("name" => "Philosopher", "variant" => ""),
					array("name" => "Puritan", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Quattrocento", "variant" => ""),
					array("name" => "Radley", "variant" => ""),
					array("name" => "Raleway", "variant" => ""),
					array("name" => "Reenie Beanie", "variant" => ""),
					array("name" => "Rock Salt", "variant" => ""),
					array("name" => "Schoolbell", "variant" => ""),
					array("name" => "Six Caps", "variant" => ""),
					array("name" => "Slackey", "variant" => ""),
					array("name" => "Sniglet", "variant" => ""),
					array("name" => "Sunshiney", "variant" => ""),
					array("name" => "Syncopate", "variant" => ""),
					array("name" => "Tangerine", "variant" => "regular,bold"),
					array("name" => "Tinos", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Ubuntu", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Unkempt", "variant" => ""),
					array("name" => "VT323", "variant" => ""),
					array("name" => "Vibur", "variant" => ""),
					array("name" => "Vollkorn", "variant" => "regular,italic,bold,bolditalic"),
					array("name" => "Walter Turncoat", "variant" => ""),
					array("name" => "Yanone Kaffeesatz", "variant" => "regular,italic,bold,bolditalic")

		);

/*******************************
 WIDGETS AREAS
********************************/

function diary_widgets_init() {
register_sidebar(array(
	'name' => 'sidebar',
	'before_widget' => '<section class="sideBox">',
	'after_widget' => '</section>',
	'before_title' => '<h3>',
	'after_title' => '</h3>',
));
}

add_action( 'widgets_init', 'diary_widgets_init' );

/*******************************
 PAGINATION
********************************
 * Retrieve or display pagination code.
 *
 * The defaults for overwriting are:
 * 'page' - Default is null (int). The current page. This function will
 *      automatically determine the value.
 * 'pages' - Default is null (int). The total number of pages. This function will
 *      automatically determine the value.
 * 'range' - Default is 3 (int). The number of page links to show before and after
 *      the current page.
 * 'gap' - Default is 3 (int). The minimum number of pages before a gap is 
 *      replaced with ellipses (...).
 * 'anchor' - Default is 1 (int). The number of links to always show at begining
 *      and end of pagination
 * 'before' - Default is '<div class="emm-paginate">' (string). The html or text 
 *      to add before the pagination links.
 * 'after' - Default is '</div>' (string). The html or text to add after the
 *      pagination links.
 * 'title' - Default is '__('Pages:')' (string). The text to display before the
 *      pagination links.
 * 'next_page' - Default is '__('&raquo;')' (string). The text to use for the 
 *      next page link.
 * 'previous_page' - Default is '__('&laquo')' (string). The text to use for the 
 *      previous page link.
 * 'echo' - Default is 1 (int). To return the code instead of echo'ing, set this
 *      to 0 (zero).
 *
 * @author Eric Martin <eric@ericmmartin.com>
 * @copyright Copyright (c) 2009, Eric Martin
 * @version 1.0
 *
 * @param array|string $args Optional. Override default arguments.
 * @return string HTML content, if not displaying.
 */
 
function emm_paginate($args = null) {
	$defaults = array(
		'page' => null, 'pages' => null, 
		'range' => 3, 'gap' => 3, 'anchor' => 1,
		'before' => '<div class="emm-paginate">', 'after' => '</div>',
		'title' => __('Pages:'),
		'nextpage' => __('&raquo;'), 'previouspage' => __('&laquo'),
		'echo' => 1
	);

	$r = wp_parse_args($args, $defaults);
	extract($r, EXTR_SKIP);

	if (!$page && !$pages) {
		global $wp_query;

		$page = get_query_var('paged');
		$page = !empty($page) ? intval($page) : 1;

		$posts_per_page = intval(get_query_var('posts_per_page'));
		$pages = intval(ceil($wp_query->found_posts / $posts_per_page));
	}
	
	$output = "";
	if ($pages > 1) {	
		$output .= "$before<span class='emm-title'>$title</span>";
		$ellipsis = "<span class='emm-gap'>...</span>";

		if ($page > 1 && !empty($previouspage)) {
			$output .= "<a href='" . get_pagenum_link($page - 1) . "' class='emm-prev'>$previouspage</a>";
		}
		
		$min_links = $range * 2 + 1;
		$block_min = min($page - $range, $pages - $min_links);
		$block_high = max($page + $range, $min_links);
		$left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
		$right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;

		if ($left_gap && !$right_gap) {
			$output .= sprintf('%s%s%s', 
				emm_paginate_loop(1, $anchor), 
				$ellipsis, 
				emm_paginate_loop($block_min, $pages, $page)
			);
		}
		else if ($left_gap && $right_gap) {
			$output .= sprintf('%s%s%s%s%s', 
				emm_paginate_loop(1, $anchor), 
				$ellipsis, 
				emm_paginate_loop($block_min, $block_high, $page), 
				$ellipsis, 
				emm_paginate_loop(($pages - $anchor + 1), $pages)
			);
		}
		else if ($right_gap && !$left_gap) {
			$output .= sprintf('%s%s%s', 
				emm_paginate_loop(1, $block_high, $page),
				$ellipsis,
				emm_paginate_loop(($pages - $anchor + 1), $pages)
			);
		}
		else {
			$output .= emm_paginate_loop(1, $pages, $page);
		}

		if ($page < $pages && !empty($nextpage)) {
			$output .= "<a href='" . get_pagenum_link($page + 1) . "' class='emm-next'>$nextpage</a>";
		}

		$output .= $after;
	}

	if ($echo) {
		echo $output;
	}

	return $output;
}

/**
 * Helper function for pagination which builds the page links.
 *
 * @access private
 *
 * @author Eric Martin <eric@ericmmartin.com>
 * @copyright Copyright (c) 2009, Eric Martin
 * @version 1.0
 *
 * @param int $start The first link page.
 * @param int $max The last link page.
 * @return int $page Optional, default is 0. The current page.
 */
function emm_paginate_loop($start, $max, $page = 0) {
	$output = "";
	for ($i = $start; $i <= $max; $i++) {
		$output .= ($page === intval($i)) 
			? "<span class='emm-page emm-current'>$i</span>" 
			: "<a href='" . get_pagenum_link($i) . "' class='emm-page'>$i</a>";
	}
	return $output;
}

function post_is_in_descendant_category( $cats, $_post = null )
{
	foreach ( (array) $cats as $cat ) {
		// get_term_children() accepts integer ID only
		$descendants = get_term_children( (int) $cat, 'category');
		if ( $descendants && in_category( $descendants, $_post ) )
			return true;
	}
	return false;
}

/*******************************
 CUSTOM BACKGROUNDS
********************************/
add_custom_background();

/*******************************
 CUSTOM COMMENTS
********************************/

function mytheme_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class('clearfix'); ?> id="li-comment-<?php comment_ID() ?>">
	 <?php echo get_avatar($comment,$size='38'); ?>
     <div id="comment-<?php comment_ID(); ?>">
	  <div class="comment-meta commentmetadata">
	    <?php printf(__('<strong>%s</strong>'), get_comment_author_link()) ?><?php edit_comment_link(__('(Edit)'),'  ','') ?> <span><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?>
	  </span>
	  </div>
	  
      <div class="text">
		  <?php comment_text() ?>
	  </div>
	  
	  <?php if ($comment->comment_approved == '0') : ?>
         <em><?php _e('Your comment is awaiting moderation.') ?></em>
         <br />
      <?php endif; ?>

      <div class="reply">
         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
      </div>
     </div>
<?php }

/*******************************
 LATEST TWEETS WIDGET
********************************/


/**
 * Add function to widgets_init that'll load the widget */
 
add_action( 'widgets_init', 'latest_tweet_widget' );

function latest_tweet_widget() {
	register_widget( 'Latest_Tweets' );
}
class Latest_Tweets extends WP_Widget {

	/**
	 * Widget setup.
	 */
	function Latest_Tweets() {
		/* Widget settings. */
		$widget_ops = array( 'classname' => 'example', 'description' => __('Display a list of latest tweets', 'example') );

		/* Widget control settings. */
		$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'latest-tweets-widget' );

		/* Create the widget. */
		$this->WP_Widget( 'latest-tweets-widget', __('Latest Tweets', 'example'), $widget_ops, $control_ops );
	}

	/**
	 * How to display the widget on the screen.
	 */
	function widget( $args, $instance ) {
		extract( $args );

		/* Our variables from the widget settings. */
		$title = apply_filters('widget_title', $instance['title'] );
		$no_of_tweets = $instance['no_of_tweets'];
		$avatar = $instance['avatar'];

		/* Before widget (defined by themes). */
		echo $before_widget;

		if ( $title )
			echo '<h3 class="twitter">'. $title . $after_title;

		if ( $no_of_tweets )?>
				<div id="twitter">
					<script>
						$(function(){
							  $("#twitter").tweet({
							  	<?php if($avatar == 'yes'){?>
								avatar_size: 24,
								<?php }?>
								count: <?php echo $instance['no_of_tweets'];?>,
								username: "<?php echo get_option('diary_twitter_user');?>",
								loading_text: "<span style='color:#999;font-size:11px;'>...searching twitter...</span>",
								//refresh_interval: 10,
								template: "{avatar}{text} <br/>{time}"
							  });
							});
						</script>
					
				</div>
				<a href="http://twitter.com/<?php echo get_option('diary_twitter_user'); ?>" class="followTwitter">Follow me on Twitter! &raquo;</a>
				
	<?php 

		/* After widget (defined by themes). */
		echo $after_widget;
	}

	/**
	 * Update the widget settings.
	 */
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		/* Strip tags for title and name to remove HTML (important for text inputs). */
		$instance['title'] = strip_tags( $new_instance['title'] );
		$instance['no_of_tweets'] = strip_tags( $new_instance['no_of_tweets'] );
		$instance['avatar'] = strip_tags( $new_instance['avatar'] );

		return $instance;
	}

	/**
	 * Displays the widget settings controls on the widget panel.
	 * Make use of the get_field_id() and get_field_name() function
	 * when creating your form elements. This handles the confusing stuff.
	 */
	function form( $instance ) {

		/* Set up some default widget settings. */
		$defaults = array( 'title' => __('Latest Tweets', 'example'), 'no_of_tweets' => '3', 'avatar' => 'no' );
		$instance = wp_parse_args( (array) $instance, $defaults ); ?>

		<!-- Widget Title: Text Input -->
		<p>
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
		</p>

		<!-- No of Tweets: Text Input -->
		<p>
			<label for="<?php echo $this->get_field_id( 'no_of_tweets' ); ?>"><?php _e('No. of Tweets:', 'example'); ?></label>
			<input id="<?php echo $this->get_field_id( 'no_of_tweets' ); ?>" name="<?php echo $this->get_field_name( 'no_of_tweets' ); ?>" value="<?php echo $instance['no_of_tweets']; ?>" style="width:100%;" />
		</p>
		
		<!-- Avatar: Select -->
		<p>
			<label for="<?php echo $this->get_field_id( 'avatar' ); ?>"><?php _e('Display avatar?:', 'example'); ?></label>
			<select id="<?php echo $this->get_field_id( 'avatar' ); ?>" name="<?php echo $this->get_field_name( 'avatar' ); ?>">
				<option value="no" <?php if($instance['avatar'] == 'no'){?>selected="selected"<?php }?>>No</option>
				<option value="yes" <?php if($instance['avatar'] == 'yes'){?>selected="selected"<?php }?>>Yes</option>
			</select>
		</p>

	<?php
	}
}

/*******************************
  THEME OPTIONS PAGE
********************************/

function admin_register_head() {
	
	?>
	<script>
		var theme_admin_images="<?php bloginfo('template_directory'); ?>";
	</script>
	<?php
	webfonts_render();
    $url = get_bloginfo('template_directory') . '/css/admin.css';
    echo "<link rel='stylesheet' type='text/css' href='$url' />\n";
	$urlcolor = get_bloginfo('template_directory') . '/js/mColorPicker.js';
    echo "<script  type='text/javascript' src='$urlcolor' />\n";
	
 }
add_action('admin_head', 'admin_register_head');

add_action('admin_menu', 'diary_theme_page');
function diary_theme_page ()
{

	if ( count($_POST) > 0 && isset($_POST['diary_settings']) )
	{
		$options = array ('logo_title','contact_page','contact_email','contact_text','twitter_user','facebook_link','keywords','description','analytics','copyright','main_font','font_title','font_title_size','font_date','font_date_size','font_more','font_more_size','font_heading','font_heading_size','font_sideheading','font_sideheading_size','blog_title_color','blog_text_color','main_h_color','main_links_color','main_links_hover_color','post_title_color','post_title_hover_color','post_date_color','read_more_color','read_more_hover_color','sidebar_h_color','sidebar_links_color','footer_color','footer_links_color','footer_shadow_color');
		
		foreach ( $options as $opt )
		{
			delete_option ('diary_'.$opt, $_POST[$opt] );
			add_option ( 'diary_'.$opt, $_POST[$opt] );	
		}			
		 
	}
	add_menu_page(__('Diary/Notebook Options'), __('Diary/Notebook Options'), 'edit_themes', basename(__FILE__), 'diary_settings');
	add_submenu_page(__('Diary/Notebook Options'), __('Diary/Notebook Options'), 'edit_themes', basename(__FILE__), 'diary_settings');
}

function diary_settings()
{

global $webfonts;

?>
<div class="wrap">
	<h2>Diary/Notebook Options Panel</h2>
	<ul class="adminTabs">
		<li><a href="#generalsettings">General Settings</a></li>
		<li><a href="#fonts">Fonts</a></li>
		<li><a href="#colors">Colors</a></li>
		<li><a href="#sociallinks">Social Links</a></li>
		<li><a href="#contact">Contact Page</a></li>
		<li><a href="#footersettings">Footer</a></li>
		<li><a href="#seo">SEO</a></li>
	</ul>
	<form method="post" action="">
	<div class="tabs">
		<!-- General settings -->
		<div id="generalsettings" class="tab">
				<table class="form-table">
				<tr valign="top">
					<td>
						<strong>Background</strong>: You can set the background image and/or color from Appearance > Background
					</td>
				</tr>
				<tr valign="top">
					<td>
						<strong>Blog Logo/Title</strong>: The logo/title is the blog title set in Settings > General
					</td>
				</tr>
			</table>
			<p class="submit">
			<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
			<input type="hidden" name="diary_settings" value="save" style="display:none;" />
			</p>
		</div>
		<!-- Fonts -->
		<div id="fonts" class="tab">
				<h4>Blog Main Font</h4>
				<table class="form-table">
				<tr valign="top">
					<th scope="row">Font Family:</th>
					<td><select name="main_font" id="main_font">		
							<option value="Georgia, Times New Roman, Times, serif" <?php if(get_option('diary_main_font') == 'Georgia, Times New Roman, Times, serif'){?>selected="selected"<?php }?>>Georgia, Times New Roman, Times, serif</option>
							<option value="Arial, Helvetica, sans-serif" <?php if(get_option('diary_main_font') == 'Arial, Helvetica, sans-serif'){?>selected="selected"<?php }?>>Arial, Helvetica, sans-serif</option>
							<option value="Verdana, Arial, Helvetica, sans-serif" <?php if(get_option('diary_main_font') == 'Verdana, Arial, Helvetica, sans-serif'){?>selected="selected"<?php }?>>Verdana, Arial, Helvetica, sans-serif</option>
							<option value="Trebuchet MS, Arial, Helvetica, sans-serif" <?php if(get_option('diary_main_font') == 'Trebuchet MS, Arial, Helvetica, sans-serif'){?>selected="selected"<?php }?>>Trebuchet MS, Arial, Helvetica, sans-serif</option>
						</select>
					</td>
					</tr>
				</table>
				<h4>Blog Title/ Logo Font</h4>
				<em><small><strong>Note:</strong>The theme uses Google Web Fonts. When setting new fonts you can first see them in action at <a href="http://www.google.com/webfonts">http://www.google.com/webfonts</a></small></em>
				<table class="form-table">
				<tr valign="top">
					<th scope="row">Font Family:</th>
					<td>
						<select id="font_title" name="font_title">
							<option value="" selected="selected">Default</option>
							<?php foreach($webfonts as $webfont){?>
								<option value="<?php echo $webfont['name'];?>" <?php if(get_option('diary_font_title') == $webfont['name']){?>selected="selected"<?php }?>><?php echo $webfont['name'];?></option>
							<?php }?>
						</select> 
						<?php if(get_option('diary_font_title')):?>
						&nbsp;&nbsp;&nbsp;<span style="font-family:<?php echo get_option('diary_font_title')?>; font-size:26px;">Sample Text</span>
						<?php endif;?>
					</td>
				</tr>
				<tr valign="top">
					<th scope="row">Font Size:</th>
					<td>
						<input name="font_title_size" type="text" id="font_title_size" value="<?php echo get_option('diary_font_title_size'); ?>" class="regular-text" style="width:40px;"/> px<br />
						<em><small>Leave blank for default, 40px</small></em>
					</td>
				</tr>
				</table>
				<h4>Post Date Font</h4>
				<table class="form-table">
				<tr valign="top">
					<th scope="row">Font Family:</th>
					<td>
						<select id="font_date" name="font_date">
							<option value="" selected="selected">Default</option>
							<?php foreach($webfonts as $webfont){?>
								<option value="<?php echo $webfont['name'];?>" <?php if(get_option('diary_font_date') == $webfont['name']){?>selected="selected"<?php }?>><?php echo $webfont['name'];?></option>
							<?php }?>
						</select>
						<?php if(get_option('diary_font_date')):?>
						&nbsp;&nbsp;&nbsp;<span style="font-family:<?php echo get_option('diary_font_date')?>; font-size:26px;">Sample Text</span>
						<?php endif;?>
					</td>
				</tr>
				<tr valign="top">
					<th scope="row">Font Size:</th>
					<td>
						<input name="font_date_size" type="text" id="font_date_size" value="<?php echo get_option('diary_font_date_size'); ?>" class="regular-text" style="width:40px;"/> px<br />
						<em><small>Leave blank for default, 26px</small></em>
					</td>
				</tr>
				</table>
				<h4>Post Read More Font</h4>
				<table class="form-table">
				<tr valign="top">
					<th scope="row">Font Family:</th>
					<td>
						<select id="font_more" name="font_more">
							<option value="" selected="selected">Default</option>
							<?php foreach($webfonts as $webfont){?>
								<option value="<?php echo $webfont['name'];?>" <?php if(get_option('diary_font_more') == $webfont['name']){?>selected="selected"<?php }?>><?php echo $webfont['name'];?></option>
							<?php }?>
						</select>
						<?php if(get_option('diary_font_more')):?>
						&nbsp;&nbsp;&nbsp;<span style="font-family:<?php echo get_option('diary_font_more')?>; font-size:26px;">Sample Text</span>
						<?php endif;?>
					</td>
				</tr>
				<tr valign="top">
					<th scope="row">Font Size:</th>
					<td>
						<input name="font_more_size" type="text" id="font_more_size" value="<?php echo get_option('diary_font_more_size'); ?>" class="regular-text" style="width:40px;"/> px<br />
						<em><small>Leave blank for default, 26px</small></em>
					</td>
				</tr>

				</table>
				<h4>Post/Page Heading Font:</h4>
				<table class="form-table">
				<tr valign="top">
					<th scope="row">Font Family:</th>
					<td>
						<select id="font_heading" name="font_heading">
							<option value="" selected="selected">Default</option>
							<?php foreach($webfonts as $webfont){?>
								<option value="<?php echo $webfont['name'];?>" <?php if(get_option('diary_font_heading') == $webfont['name']){?>selected="selected"<?php }?>><?php echo $webfont['name'];?></option>
							<?php }?>
						</select>
						<?php if(get_option('diary_font_heading')):?>
						&nbsp;&nbsp;&nbsp;<span style="font-family:<?php echo get_option('diary_font_heading')?>; font-size:26px;">Sample Text</span>
						<?php endif;?>
					</td>
				</tr>
				<tr valign="top">
					<th scope="row">Font Size:</th>
					<td>
						<input name="font_heading_size" type="text" id="font_heading_size" value="<?php echo get_option('diary_font_heading_size'); ?>" class="regular-text" style="width:40px;"/> px<br />
						<em><small>Leave blank for default, 28px</small></em>
						
					</td>
				</tr>

				</table>
				<h4>Sidebar Headings (H3) Font:</h4>
			<table class="form-table">
				<tr valign="top">
					<th scope="row">Font Family:</th>
					<td>
						<select id="font_sideheading" name="font_sideheading">
							<option value="" selected="selected">Default</option>
							<?php foreach($webfonts as $webfont){?>
								<option value="<?php echo $webfont['name'];?>" <?php if(get_option('diary_font_sideheading') == $webfont['name']){?>selected="selected"<?php }?>><?php echo $webfont['name'];?></option>
							<?php }?>
						</select>
						<?php if(get_option('diary_font_sideheading')):?>
						&nbsp;&nbsp;&nbsp;<span style="font-family:<?php echo get_option('diary_font_sideheading')?>; font-size:26px;">Sample Text</span>
						<?php endif;?>
					</td>
				</tr>
				<tr valign="top">
					<th scope="row">Font Size:</th>
					<td>
						<input name="font_sideheading_size" type="text" id="font_sideheading_size" value="<?php echo get_option('diary_font_sideheading_size'); ?>" class="regular-text" style="width:40px;"/> px<br />
						<em><small>Leave blank for default, 16px</small></em>
					</td>
				</tr>

			</table>
			<p class="submit">
			<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
			<input type="hidden" name="diary_settings" value="save" style="display:none;" />
			</p>
		</div>
		<!-- Colors -->
		<div id="colors" class="tab">
		<h3>Colors Settings &nbsp;&nbsp;&nbsp;<em style="font-weight:normal; font-size:13px;">* Leave the fields blank to restore the defaults</em></h3>
		<h4>MAIN CONTENT</h4>
			<table class="form-table">
				<tr valign="top">
					<th scope="row"><label for="blog_title_color">Blog Title Color</label></th>
					<td>
						<input type="color" id="blog_title_color" name="blog_title_color" value="<?php echo get_option("diary_blog_title_color")?>" data-hex="true"/>		</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="blog_text_color">Blog Text Color</label></th>
					<td>
						<input type="color" id="blog_text_color" name="blog_text_color" value="<?php echo get_option("diary_blog_text_color")?>" data-hex="true"/>		</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="main_h_color">Main Headings Color (H2,H3...)</label></th>
					<td>
						<input type="color" id="main_h_color" name="main_h_color" value="<?php echo get_option("diary_main_h_color")?>" data-hex="true" />
					</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="main_links_color">Main Content Links Color</label></th>
					<td>
						<input type="color" id="main_links_color" name="main_links_color" value="<?php echo get_option("diary_main_links_color")?>" data-hex="true" />
					</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="main_links_hover_color">Main Content Links Hover Color</label></th>
					<td>
						<input type="color" id="main_links_hover_color" name="main_links_hover_color" value="<?php echo get_option("diary_main_links_hover_color")?>" data-hex="true" />
					</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="post_title_color">Post Title Color</label></th>
					<td>
						<input type="color" id="post_title_color" name="post_title_color" value="<?php echo get_option("diary_post_title_color")?>" data-hex="true" />
					</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="post_title_hover_color">Post Title Hover Color</label></th>
					<td>
						<input type="color" id="post_title_hover_color" name="post_title_hover_color" value="<?php echo get_option("diary_post_title_hover_color")?>" data-hex="true" />
					</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="post_date_color">Post Date Color</label></th>
					<td>
						<input type="color" id="post_date_color" name="post_date_color" value="<?php echo get_option("diary_post_date_color")?>" data-hex="true" />
					</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="read_more_color">Read More Link Color</label></th>
					<td>
						<input type="color" id="read_more_color" name="read_more_color" value="<?php echo get_option("diary_read_more_color")?>" data-hex="true" />
					</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="read_more_hover_color">Read More Link Hover Color</label></th>
					<td>
						<input type="color" id="read_more_hover_color" name="read_more_hover_color" value="<?php echo get_option("diary_read_more_hover_color")?>" data-hex="true" />
					</td>
				</tr>
			</table>
			<h4>SIDEBAR</h4>
			<table class="form-table">
				<tr valign="top">
					<th scope="row"><label for="sidebar_h_color">Sidebar Headings Color</label></th>
					<td>
						<input type="color" id="sidebar_h_color" name="sidebar_h_color" value="<?php echo get_option("diary_sidebar_h_color")?>" data-hex="true" />
					</td>
				</tr>
				
				<tr valign="top">
					<th scope="row"><label for="sidebar_links_color">Sidebar Links Color</label></th>
					<td>
						<input type="color" id="sidebar_links_color" name="sidebar_links_color" value="<?php echo get_option("diary_sidebar_links_color")?>" data-hex="true" />
					</td>
				</tr>
			</table>
			<p class="submit">
				<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
				<input type="hidden" name="diary_settings" value="save" style="display:none;" />
			</p>
			<h4>FOOTER</h4>
			<table class="form-table">
				<tr valign="top">
					<th scope="row"><label for="footer_color">Footer Text Color</label></th>
					<td>
						<input type="color" id="footer_color" name="footer_color" value="<?php echo get_option("diary_footer_color")?>" data-hex="true" />
					</td>
				</tr>
				
				<tr valign="top">
					<th scope="row"><label for="footer_links_color">Footer Links Color</label></th>
					<td>
						<input type="color" id="footer_links_color" name="footer_links_color" value="<?php echo get_option("diary_footer_links_color")?>" data-hex="true" />
					</td>
				</tr>
				<tr valign="top">
					<th scope="row"><label for="footer_shadow_color">Footer Text Shadow Color</label></th>
					<td>
						<input type="color" id="footer_shadow_color" name="footer_shadow_color" value="<?php echo get_option("diary_footer_shadow_color")?>" data-hex="true" />
					</td>
				</tr>
			</table>
			<p class="submit">
				<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
				<input type="hidden" name="diary_settings" value="save" style="display:none;" />
			</p>
		</div>
		<!-- Social Links -->
		<div id="sociallinks" class="tab">
			<table class="form-table">
			<tr valign="top">
				<th scope="row"><label for="twitter_user">Twitter Username</label></th>
				<td>
					<input name="twitter_user" type="text" id="twitter_user" value="<?php echo get_option('diary_twitter_user'); ?>" class="regular-text" />
				</td>
			</tr>
			<tr valign="top">
				<th scope="row"><label for="facebook_link">Facebook link</label></th>
				<td>
					<input name="facebook_link" type="text" id="facebook_link" value="<?php echo get_option('diary_facebook_link'); ?>" class="regular-text" />
				</td>
			</tr>
        </table>
		<p class="submit">
		<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
		<input type="hidden" name="diary_settings" value="save" style="display:none;" />
		</p>
		
		</div>
		<!-- Contact Page -->
		<div id="contact" class="tab">
			<table class="form-table">	
			<tr>
				<td colspan="2"></td>
			</tr>
			<tr valign="top">
				<th scope="row"><label for="contact_page">Contact Page</label></th>
				<td>
					<?php wp_dropdown_pages("name=contact_page&show_option_none=".__('- Select -')."&selected=" .get_option('diary_contact_page')); ?>
				</td>
			</tr>
			 <tr valign="top">
				<th scope="row"><label for="contact_text">Contact Page Text</label></th>
				<td>
					<textarea name="contact_text" id="contact_text" rows="7" cols="70" style="font-size:11px;"><?php echo stripslashes(get_option('diary_contact_text')); ?></textarea>
				</td>
			</tr>
			<tr valign="top">
				<th scope="row"><label for="contact_email">Email Address for Contact Form</label></th>
				<td>
					<input name="contact_email" type="text" id="contact_email" value="<?php echo get_option('diary_contact_email'); ?>" class="regular-text" />
				</td>
			</tr>
        </table>
		<p class="submit">
		<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
		<input type="hidden" name="diary_settings" value="save" style="display:none;" />
		</p>
		</div>
		<!-- Footer -->
		<div id="footersettings" class="tab">
			<table class="form-table">
			<tr>
				<th colspan="2"><strong>Copyright Info</strong></th>
			</tr>
			<tr>
				<th><label for="copyright">Copyright Text</label></th>
				<td>
					<textarea name="copyright" id="copyright" rows="4" cols="70" style="font-size:11px;"><?php echo stripslashes(get_option('diary_copyright')); ?></textarea><br />
					<em>You can use HTML for links etc.</em>
				</td>
			</tr>
		</table>
		<p class="submit">
		<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
		<input type="hidden" name="diary_settings" value="save" style="display:none;" />
		</p>
		</div>
		<div id="seo" class="tab">
			<table class="form-table">
        <tr>
			<th><label for="keywords">Meta Keywords</label></th>
			<td>
				<textarea name="keywords" id="keywords" rows="7" cols="70" style="font-size:11px;"><?php echo get_option('diary_keywords'); ?></textarea><br />
                <em>Keywords comma separated</em>
			</td>
		</tr>
        <tr>
			<th><label for="description">Meta Description</label></th>
			<td>
				<textarea name="description" id="description" rows="7" cols="70" style="font-size:11px;"><?php echo get_option('diary_description'); ?></textarea>
			</td>
		</tr>
		<tr>
			<th><label for="ads">Google Analytics code:</label></th>
			<td>
				<textarea name="analytics" id="analytics" rows="7" cols="70" style="font-size:11px;"><?php echo stripslashes(get_option('diary_analytics')); ?></textarea>
			</td>
		</tr>
	</table>
		<p class="submit">
		<input type="submit" name="Submit" class="button-primary" value="Save Changes" />
		<input type="hidden" name="diary_settings" value="save" style="display:none;" />
		</p>
		</div>
</div>

</form>
<script>
jQuery(document).ready(function(){
		 //if this is not the first tab, hide it
		 jQuery(".tab:not(:first)").hide();
		 
		 //to fix u know who
		 jQuery(".tab:first").show();
		 jQuery(".adminTabs a:first").addClass('active');
		 
		 //when we click one of the tabs
		 jQuery(".adminTabs a").click(function(){
		 
		 //get the ID of the element we need to show
		 stringref = jQuery(this).attr("href").split('#')[1];
		 //hide the tabs that doesn't match the ID
		 jQuery('.tab:not(#'+stringref+')').hide();
		 jQuery('.adminTabs a:not(#'+stringref+')').removeClass('active');
		 jQuery(this).addClass('active');
		 //fix
		 if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0") {
		 jQuery('.tab#' + stringref).show();
		 }
		 else
		 //display our tab fading it in
		 jQuery('.tab#' + stringref).fadeIn();
		 //stay with me
		 return false;
		 });
		 
		});
	</script>
</div>
<?php 
}

/*******************************
  WEB FONTS
********************************/
function webfonts_render() {
	global $webfonts;
	$fontsref='';
	$font_options = array(
						get_option('diary_font_title'),
						get_option('diary_font_date'),
						get_option('diary_font_more'),
						get_option('diary_font_heading'),
						get_option('diary_font_sideheading')
					);
	foreach($font_options as $font_option){
		if($font_option!=''){
			foreach($webfonts as $webfont){
						if($webfont['name'] == $font_option){ 
							$variant = $webfont['variant'];
								}	
					}
					if(!strstr($fontsref, $font_option)){
						if($variant){
							$fontsref .= $font_option.":".$variant."|";
							}else{
							$fontsref .= $font_option."|";
							}
					}
			}
			}
	$fontsref = str_replace(" ","+",$fontsref);	
	$output = '<link href="http://fonts.googleapis.com/css?family=' . $fontsref .'" rel="stylesheet" type="text/css" />'."\n\n";
	$output = str_replace('|"','"',$output);
	echo $output;
}

/*******************************
  CONTACT FORM 
********************************/

 function hexstr($hexstr) {
  $hexstr = str_replace(' ', '', $hexstr);
  $hexstr = str_replace('\x', '', $hexstr);
  $retstr = pack('H*', $hexstr);
  return $retstr;
}

function strhex($string) {
  $hexstr = unpack('H*', $string);
  return array_shift($hexstr);
}

?>