<?php
// Set up Moderno information
$bavotasan_theme_data = get_theme_data(TEMPLATEPATH.'/style.css');
define('THEME_NAME', $bavotasan_theme_data['Name']);
define('THEME_AUTHOR', $bavotasan_theme_data['Author']);
define('THEME_HOMEPAGE', $bavotasan_theme_data['URI']);
define('THEME_VERSION', trim($bavotasan_theme_data['Version']));
define('THEME_URL', get_template_directory_uri());
define('THEME_FILE', "moderno");
define('THEME_CODE', 'mod');


// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain(THEME_FILE, TEMPLATEPATH . '/languages');

$locale = get_locale();
$locale_file = TEMPLATEPATH . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
	require_once( $locale_file );
	
$moderno_options = array (
	
	array(	"name" => __("Site Width", "moderno"),
			"desc" => __("Set the width of your site", "moderno"),
			"id" => "site_width",
			"default" => "980"),
			
	array(  "name" => __("First Sidebar Width", "moderno"),
			"desc" => __("Set width", "moderno"),
            "id" => "sidebar_width1",
			"default" => "300"),

	array(  "name" => __("Second Sidebar Width", "moderno"),
			"desc" => __("Set width", "moderno"),
            "id" => "sidebar_width2",
			"default" => "0"),
			
	array(  "name" => __("Sidebar Location", "moderno"),
			"desc" => __("Set location", "moderno"),
            "id" => "sidebar_location1",
			"default" => "2"),

	array(  "name" => __("Extended Footer Bar", "moderno"),
			"desc" => __("Display widgetized footer bar", "moderno"),
            "id" => "extended_footer",
 			"default" => "1"),

	array(  "name" => __("Front/Archive Page Text", "moderno"),
			"desc" => __("Display the excerpt or the content", "moderno"),
            "id" => "frontpage_exorcon",
			"default" => 1),
			
	array(  "name" => __("Excerpt Word Limit", "moderno"),
			"desc" => __("Set limit", "moderno"),
            "id" => "excerpt_limit",
			"default" => 55),		
	
	array(  "name" => __("Display Comment Count", "moderno"),
			"desc" => __("Do you want to display comment numbers?", "moderno"),
            "id" => "comment_count",
			"default" => 1),

	array(  "name" => __("More Link Text", "moderno"),
			"desc" => __("Set more link text", "moderno"),
            "id" => "more_link_text",
			"default" => "Read More &raquo;"),		
			
	array(  "name" => __("Header Logo", "moderno"),
			"desc" => __("Set the URL file path to your logo", "moderno"),
            "id" => "logo_header"),	
			
	array(  "name" => __("Logo or Blog Name Location", "moderno"),
			"desc" => __("Set your blog name/logo location", "moderno"),
            "id" => "logo_location",
			"default" => "fl"),	
			
	array(  "name" => __("Display Dates", "moderno"),
			"desc" => __("Display dates under your post titles", "moderno"),
            "id" => "dates",
			"default" => "on"),

	array(  "id" => "dates_cats",
			"default" => "on"),
	array(  "id" => "dates_posts",
			"default" => "on"),
			
	array(  "name" => __("Display Authors", "moderno"),
			"desc" => __("Display authors under your post titles", "moderno"),
			"default" => "on",
			"id" => "authors_front"),

	array(  "id" => "authors_cats",
			"default" => "on"),
	array(  "id" => "authors_posts",
			"default" => "on"),			

	array(  "name" => __("Site Description", "moderno"),
			"desc" => __("Add meta tag description (Excerpt used on single posts and pages)", "moderno"),
            "id" => "site_description"),

	array(  "name" => __("Keywords", "moderno"),
			"desc" => __("Add meta tag keywords, separate by comma (Tags are used on single posts)", "moderno"),
            "id" => "keywords"),
				
	array(  "name" => __("Google Analytics", "moderno"),
			"desc" => __("Add your Google Analytics code", "moderno"),
            "id" => "google_analytics"),
						
	array(  "name" => __("Header Ad", "moderno"),
			"desc" => __("Add header ad image/link or JavaScript (suggested size: 468 x 60)", "moderno"),
            "id" => "header_ad"),
			
	array(  "name" => __("Sidebar Ad", "moderno"),
			"desc" => __("Add sidebar ad image/link or JavaScript (suggested size: 125 x 125)", "moderno"),
            "id" => "sidebar_ad"),
			
	array(  "name" => __("Footer Ad", "moderno"),
			"desc" => __("Add footer ad image/link or JavaScript (suggested size: 728 x 90 or 468 x 60)", "moderno"),
            "id" => "footer_ad"),

	array(  "name" => __("Footer Text", "moderno"),
			"desc" => __("Add custom text to the footer", "moderno"),
            "id" => "footer_text"),
			
	array(  "name" => __("WordPress Link", "moderno"),
			"desc" => __("Display WordPress link in the footer", "moderno"),
            "id" => "footer_wordpress_link",
 			"default" => "1")						
);

$moderno_design_options = array(
   
	array(  "name" => __("Main Content Background", "moderno"),
            "id" => "main_content_bg_color",
            "default" => "F8F9F8"),			

	array(  "name" => __("Top Border", "moderno"),
            "id" => "top_border",
            "default" => "444444"),

	array(  "name" => __("Text", "moderno"),
            "id" => "text_color",
            "default" => "444444"),

	array(  "name" => __("Headers Text", "moderno"),
            "id" => "headers_text_color",
            "default" => "3E454B"),
			
	array(  "name" => __("Links", "moderno"),
            "id" => "link_color",
            "default" => "57A3d4"),
			
	array(  "name" => __("Link Hover", "moderno"),
            "id" => "link_hover_color",
            "default" => "444444"),
			
	array(  "name" => __("Nav Menu Links", "moderno"),
            "id" => "nav_menu_link_color",
            "default" => "3E454B"),									

	array(  "name" => __("Nav Font", "moderno"),
           "id" => "nav_font",
            "default" => "Arial, Helvetica, sans-serif"),
			
	array(  "id" => "nav_font_size",
            "default" => 12),

	array(  "name" => __("Nav Menu Border", "moderno"),
            "id" => "nav_menu_border_color",
            "default" => "D1D1D1"),

	array(  "name" => __("Nav Menu Border Hover", "moderno"),
            "id" => "nav_menu_border_hover_color",
            "default" => "3E454B"),

	array(  "name" => __("Side Widget Links", "moderno"),
            "id" => "side_widget_link_color",
            "default" => "444444"),
			
	array(  "name" => __("Side Widget Link Hover", "moderno"),
            "id" => "side_widget_link_hover_color",
            "default" => "444444"),
			
	array(  "name" => __("Main Font", "moderno"),
           "id" => "main_font",
            "default" => "Arial, Helvetica, sans-serif"),
			
	array(  "id" => "main_font_size",
            "default" => 14),
			
	array(  "name" => __("Blog Title Font", "moderno"),
           "id" => "title_font",
            "default" => 'Georgia, "Times New Roman", Times, serif'),
			
	array(  "id" => "title_font_size",
            "default" => 50),	
								
	array(  "name" => __("Index Post Title Font", "moderno"),
           "id" => "post_title_font",
            "default" => 'Georgia, "Times New Roman", Times, serif'),
			
	array(  "id" => "post_title_font_size",
            "default" => 30),	
	
	array(  "name" => __("Single Post Title Font", "moderno"),
           "id" => "post_title_single_font",
            "default" => 'Georgia, "Times New Roman", Times, serif'),
			
	array(  "id" => "post_title_single_font_size",
            "default" => 30),	
	
	array(  "name" => __("Sidebar Text Font", "moderno"),
           "id" => "sidebar_text_font",
            "default" => "Arial, Helvetica, sans-serif"),
			
	array(  "id" => "sidebar_text_font_size",
            "default" => 12),	
			
	array(  "name" => __("Sidebar Header Font", "moderno"),
           "id" => "sidebar_header_font",
            "default" => 'Georgia, "Times New Roman", Times, serif'),
			
	array(  "id" => "sidebar_header_font_size",
            "default" => 14)
			
);


// setting up the $values variable
$values = get_option(THEME_FILE);
$designs = get_option(THEME_FILE.'_design');
//delete_option(THEME_FILE);
//delete_option(THEME_FILE.'_design');

function get_index($array, $index) {
  return isset($array[$index]) ? $array[$index] : null;
}

// CALL THEME OPTIONS
function theme_option($var) {
	global $values;
	$val = get_index($values, $var);
	return $val;
}

// CALL DESIGN OPTIONS
function design_option($var) {
	global $designs;
	$val = get_index($designs, $var);
	return $val;
}

// Set all default options
if(!$values) {
	foreach ($moderno_options as $default) {
		if(isset($default['id']) && isset($default['default'])) {
			$setdefaultvalues1[ $default['id'] ] = $default['default'];
		}
	}
	update_option(THEME_FILE, $setdefaultvalues1);
}

if(!$designs) {
	foreach ($moderno_design_options as $default) {
		if(isset($default['id']) && isset($default['default'])) {
			$setdefaultvalues2[ $default['id'] ] = $default['default'];
		}
	}
	update_option(THEME_FILE.'_design', $setdefaultvalues2);
}

// Setting up the theme options CSS
if(theme_option('site_width')) {
	$moderno_loc = theme_option('sidebar_location1');
	$moderno_site = theme_option('site_width');
	$moderno_sidebar = theme_option('sidebar_width1');
	$moderno_secondsidebar = theme_option('sidebar_width2');
	if($moderno_sidebar!=0) $buffer1 = 80; else $buffer1 = 40;	
	if($moderno_loc==5) $buffer2 = 36; else $buffer2 = 0;
	if($moderno_secondsidebar!=0) {
		$moderno_content = $moderno_site - $moderno_sidebar - $moderno_secondsidebar - $buffer1 - $buffer2;
	} else {
		$moderno_content = $moderno_site - $moderno_sidebar - $buffer1;
	}
	$moderno_fullcontent = $moderno_site - 35;
} else {
	$moderno_site = 980;
	$moderno_sidebar = 300;
	$moderno_sidewidget = 264;
	$moderno_content = 600;
}

define("CONTENT_WIDTH", $moderno_content);
// Set the content width based on the theme's design and stylesheet.
if ( ! isset( $content_width ) )
	$content_width = CONTENT_WIDTH-55;

function pbt_header_css() {
	global $moderno_site, $moderno_sidebar, $moderno_secondsidebar, $moderno_content, $moderno_fullcontent, $moderno_loc;

	$sidewidget = $moderno_sidebar - 36;	
	$sidewidget2 = $moderno_secondsidebar - 36;	
	if($moderno_loc==2) {
		$mainfloat = " float: left;";
		$mainmargin = " margin: 0 0 0 30px;";
		$sidebarfloat = " float: right;";
		$sidebarbg = " background: url(".THEME_URL."/images/sidebarbg.png) no-repeat top left;";
	} elseif($moderno_loc==3) {
		$mainfloat = " float: right;";
		$mainmargin = " margin: 0 10px 0 0;";
		$sidebarfloat = " float: left;";
		$sidebarbg = " background: none;";
		$sidebarfloat2 = " float: left;";
		$sidebarbg2 = " background: url(".THEME_URL."/images/sidebarbg-r.png) no-repeat top right;";
	} elseif($moderno_loc==4) {
		$mainfloat = " float: left; clear: left;";
		$mainmargin = " margin: 0 10px 0 30px;";
		$sidebarfloat = " float: left;";
		$sidebarbg = "  background: url(".THEME_URL."/images/sidebarbg.png) no-repeat top left;";	
		$sidebarfloat2 = " float: right;";
		$sidebarbg2 = " background: none;";	
	} elseif($moderno_loc==5) {
		$mainfloat = " float: left;";
		$mainmargin = " margin: 0 10px 0 30px;";
		$sidebarfloat = " float: left;";
		$sidebarbg = "  background: url(".THEME_URL."/images/sidebarbg-r.png) no-repeat top right;";	
		$sidebarfloat2 = " float: right; padding-left: 36px;";
		$sidebarbg2 = " background: url(".THEME_URL."/images/sidebarbg.png) no-repeat top left;";	
	} else {
		$mainfloat = " float: right;";
		$mainmargin = " margin: 0 10px 0 0;";
		$sidebarfloat = " float: left;";
		$sidebarbg = " background: url(".THEME_URL."/images/sidebarbg-r.png) no-repeat top right;";
	}
?>
<style type="text/css">
#header { width: <?php echo $moderno_site; ?>px; }
#content { width: <?php echo $moderno_site; ?>px; border-top: 15px solid #<?php echo design_option('top_border'); ?> }
#postwrapper { width: <?php echo $moderno_content; ?>px;<?php echo $mainfloat; ?><?php echo $mainmargin; ?> }
.postimage .imgbg { width: <?php echo $moderno_content-20; ?>px; }
body.fullwidth #postwrapper, body.fullwidth #postwrapper .post { width: <?php echo $moderno_fullcontent-20; ?>px;<?php echo $mainfloat; ?> }
body.fullwidth .postimage .imgbg { width: <?php echo $moderno_fullcontent-10; ?>px; }
#navwrap { width: <?php echo $moderno_content-16; ?>px; }
.post { width: <?php echo $moderno_content-24; ?>px; }
.post .storycontent img { max-width: <?php echo $moderno_content-60; ?>px; height: auto; }
<?php if($moderno_sidebar!=0) { ?> 
#sidebar { width: <?php echo $moderno_sidebar; ?>px;<?php echo $sidebarfloat; echo $sidebarbg; ?> }
#sidebar .side-widget { width: <?php echo $sidewidget; ?>px; }
#sidebar .side-widget img { max-width: <?php echo $sidewidget; ?>px; height: auto; }
<?php } ?>
<?php if($moderno_secondsidebar!=0) { ?> 
#secondsidebar { width: <?php echo $moderno_secondsidebar; ?>px;<?php echo $sidebarfloat2; echo $sidebarbg2; ?> }
#secondsidebar .side-widget { width: <?php echo $sidewidget2; ?>px; }
#secondsidebar .side-widget img { max-width: <?php echo $sidewidget2; ?>px; height: auto; }	
<?php } ?>
#s { width: <?php echo $sidewidget - 45; ?>px; }
#footercontent { width: <?php echo $moderno_site-40; ?>px; }
<?php
// colors
$mainlineheight = round(design_option('main_font_size')*1.4);
echo '	body { color: #'.design_option('text_color').'; font-size: '.design_option('main_font_size').'px; line-height: '.$mainlineheight.'px; font-family: '.stripslashes(design_option('main_font')).'; }'."\n";
echo '	#wrapper { background-color: #'.design_option('main_content_bg_color').'; }'."\n";
echo '	#title h1 { font-size: '.design_option('title_font_size').'px; font-family: '.stripslashes(design_option('title_font')).';}'."\n";
echo '	h1, h1 a, h2, h2 a, h3, h3 a, h4, h4 a, h5, h5 a, h6, h6 a { color: #'.design_option('headers_text_color').'; }'."\n";
echo '	a, .side-widget .mytweets a, .side-widget .twitterlink, .bottom-widget .mytweets a, .meta .ind-comments { color: #'.design_option('link_color').'; }'."\n";
echo '	a:hover, .side-widget .mytweets a:hover, .bottom-widget .mytweets a:hover { color: #'.design_option('link_hover_color').'; }'."\n";
echo '	#main-navigation a { color: #'.design_option('nav_menu_link_color').'; }'."\n";
echo '	#main-navigation { font-size: '.design_option('nav_font_size').'px; font-family: '.design_option('nav_font').'; border-bottom: 2px solid #'.design_option('nav_menu_border_color').'; }'."\n";
echo '	#magic-line, #main-navigation ul ul { background: #'.design_option('nav_menu_border_hover_color').'; }'."\n";
echo '	#main-navigation ul ul li a { color: #'.design_option('nav_menu_border_color').'; }'."\n";
echo '	.side-widget, .bottom-widget { font-size: '.design_option('sidebar_text_font_size').'px; font-family: '.design_option('sidebar_text_font').'; }'."\n";
echo '	.side-widget a, .bottom-widget a { color: #'.design_option('side_widget_link_color').'; }'."\n";
echo '	.side-widget a:hover, .bottom-widget a:hover { color: #'.design_option('side_widget_link_hover_color').'; }'."\n";
echo '	.side-widget h3, .bottom-widget h3 { font-size: '.design_option('sidebar_header_font_size').'px; font-family: '.design_option('sidebar_header_font').'; }'."\n";
echo '	.post h2, .info h2 { font-size: '.design_option('post_title_font_size').'px; font-family: '.design_option('post_title_font').'; }'."\n";
echo '	.post h2.single { font-size: '.design_option('post_title_single_font_size').'px; font-family: '.design_option('post_title_single_font').'; }'."\n";
echo stripslashes(trim(get_option(THEME_FILE.'_custom_css')))."\n";
?>
</style>
<?php
}

// Ajax save function
function save_theme_callback() {
	global $wpdb; // this is how you get access to the database

	$savevalues = array();
	
	$items = explode("&", $_POST['option']);
	foreach ($items as $value) {
		$key_value = explode("=",$value);
		$key = urldecode($key_value[0]);
		$value = urldecode($key_value[1]);
		$savevalues[ $key ] = $value; 
	}
	
	if(isset($savevalues['custom_css'])) {
		update_option(THEME_FILE.'_custom_css', $savevalues['custom_css']);
	} elseif(isset($savevalues['design'])) {
		update_option(THEME_FILE.'_design', $savevalues);
	} else {
		update_option(THEME_FILE, $savevalues);
	}
	die();
}
add_action('wp_ajax_save_theme_options', 'save_theme_callback');


// initialize the theme
add_action('admin_menu', 'mytheme_add_admin'); 

function mytheme_add_admin() {
	wp_register_script('colorpicker_js', THEME_URL.'/admin/js/colorpicker.js', array( 'jquery' ),'',true);
	wp_register_script('admin_effects_js', THEME_URL.'/admin/js/effects.js', array( 'jquery' , 'jquery-ui-core' , 'jquery-ui-tabs' ),'',true);
	
	add_menu_page(THEME_FILE, THEME_NAME, 'manage_options', THEME_FILE, 'pbt_options', THEME_URL.'/admin/images/icon.png');
	$themelayout = add_submenu_page(THEME_FILE, THEME_NAME." - Layout", __("Layout Options", "moderno"), 'manage_options', THEME_FILE, 'pbt_options');
	$themedesign = add_submenu_page(THEME_FILE, THEME_NAME." - Design", __("Design Options", "moderno"), 'manage_options', THEME_FILE.'-design', 'pbt_design');
	$themecss = add_submenu_page(THEME_FILE, THEME_NAME." - Custom CSS", __("Custom CSS", "moderno"), 'manage_options', THEME_FILE.'-CSS', 'pbt_css');
	add_action( "admin_print_scripts-$themelayout", 'pbt_admin_css' );
	add_action( "admin_print_scripts-$themedesign", 'pbt_admin_css' );
	add_action( "admin_print_scripts-$themecss", 'pbt_admin_css' );
}

// load the js and css on theme options page
function pbt_admin_css() {
	echo '<link rel="stylesheet" href="'.THEME_URL.'/admin/css/admin-style.css" />'."\n";
	wp_enqueue_script('colorpicker_js');
	wp_enqueue_script('admin_effects_js');
}

// Setting up the custom css page
function pbt_css() { 
?>
<div id="arturowrap" class="wrap">
    <h2><?php echo THEME_NAME." ".__("Custom CSS", "moderno"); ?></h2>
    <?php echo '<div id="message" class="updated fade" style="display: none;"><p><strong>'.THEME_NAME.' '.__("Custom CSS Saved", "moderno").'</strong></p></div>'."\n"; ?>
	<?php $custom_CSS = get_option(THEME_FILE.'_custom_css'); ?> 
    <form method="post" class="custom_css_form" action="" id="themeform">
    <?php if(function_exists('wp_nonce_field')) wp_nonce_field('bavotasan_nonce', 'bavotasan_nonce'); ?>
    <div id="poststuff" class="metabox-holder has-right-sidebar">
        <div id="side-info-column" class="inner-sidebar thinner">
            <a href="http://themes.bavotasan.com" target="_blank"><img src="<?php echo THEME_URL; ?>/admin/images/brand.png" class="bavota bavtop" alt="Themes by bavotasan.com" width="225" height="84"/></a>
            <a href="javascript:{}" id="savecss"></a><div class="ajaxsave"></div>
            <br class="clear" />
            <div class="postbox thinner" id="themeresources">
            	<div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span>Resources</span></h3>
                <div class="inside">
                    <ul>
                        <li><a href="http://themes.bavotasan.com/" title="Themes by bavotasan.com">Themes by bavotasan.com</a></li>
                        <li><a href="http://themes.bavotasan.com/support/" title="<?php _e('Support Forum', "moderno"); ?>"><?php _e('Support Forum', "moderno"); ?></a></li>
                        <li><a href="http://themes.bavotasan.com/affiliates/" title="<?php _e('Affiliates Program', "moderno"); ?>"><?php _e('Affiliates Program', "moderno"); ?></a></li>
                        <li><a href="http://bavotasan.com/" title="bavotasan.com">bavotasan.com</a></li>
                    </ul>
                 </div>
            </div>
        </div> <!-- end of #side-info-column -->
        <div id="post-body" class="has-sidebar">
            <div id="post-body-content" class="has-sidebar-content thinmain">
                <div id='normal-sortables' class='meta-box-sortables'>
                    <div id="wrapper" class="arturo">
                        <textarea name="custom_css" id="custom_css" class="css" cols="" rows="30" style="width: 100%;"><?php echo stripslashes(trim($custom_CSS)); ?></textarea>	
                    	<p><?php _e('Please add all your custom CSS here and avoid modifying core theme files, since that will make upgrading the theme problematic.', "moderno"); ?></p>
                        <p><?php printf(__('If you wish to modify %1$s, you should look into creating a child theme. There is more information at %2$s.', "moderno"), '<strong>'.THEME_NAME.'</strong>', '<a href="http://codex.wordpress.org/Child_Themes">http://codex.wordpress.org/Child_Themes</a>'); ?></p>
						<p><?php printf(__('If you are new to CSS, check out %s', "moderno"), '<a href="http://www.w3schools.com/css/">http://www.w3schools.com/css/</a>'); ?></p>
         	        </div> <!-- end of #wrapper -->
        		</div> <!-- end of #normal-sortables -->
        	</div> <!-- end of #post-body-content -->
        </div> <!-- end of #post-body -->
    </div> <!-- end of #poststuff -->
    </form>
</div> <!-- end of #wrap -->
<?php
}


// Setting up the layout options page tabs
function pbt_options() { 
?>
<div id="arturowrap" class="wrap">
    <h2><?php echo THEME_NAME." ".__("Layout Options", "moderno"); ?></h2>
    <?php echo '<div id="message" class="updated fade" style="display: none;"><p><strong>'.THEME_NAME.' '.__("Options Saved", "moderno").'</strong></p></div>'."\n"; ?>
    <form method="post" action="" id="themeform" class="themesbybavotasan">
    <div id="poststuff" class="metabox-holder has-right-sidebar">
        <div id="side-info-column" class="inner-sidebar thinner">
            <a href="http://themes.bavotasan.com" target="_blank"><img src="<?php echo THEME_URL; ?>/admin/images/brand.png" class="bavota" alt="Themes by bavotasan.com" width="225" height="84" /></a>
            <a href="javascript:void(0)" id="savetheme"></a><div class="ajaxsave"></div>
            <br class="clear" />
            <div class="postbox thinner" id="themeresources">
            	<div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php _e("Resources", "moderno"); ?></span></h3>
                <div class="inside">
                    <ul>
                        <li><a href="http://themes.bavotasan.com" title="Themes by bavotasan.com">Themes by bavotasan.com</a></li>
                        <li><a href="http://support.bavotasan.com" title="<?php _e('Support Forum', "moderno"); ?>"><?php _e('Support Forum', "moderno"); ?></a></li>
                        <li><a href="http://themes.bavotasan.com/affiliates" title="<?php _e('Affiliates Program', "moderno"); ?>"><?php _e('Affiliates Program', "moderno"); ?></a></li>
                        <li><a href="http://bavotasan.com" title="bavotasan.com">bavotasan.com</a></li>
                    </ul>
 
                </div>
            </div>                    

        </div> <!-- end of #side-info-column -->
        <div id="post-body" class="has-sidebar">
            <div id="post-body-content" class="has-sidebar-content thinmain">
                <div id='normal-sortables' class='meta-box-sortables'>
                    <div id="wrapper" class="arturo">
                        <div id="tabbed">
                        <ul class="tabs">
						<?php
                        $menuPages = array(
							__('Info', "moderno") =>'pbt_info', 
							__('Main', "moderno") =>'pbt_layout_options', 
							__('Header &amp; Footer', "moderno") =>'pbt_header_options', 
							__('Sidebars', "moderno") =>'pbt_sidebars_options', 
							__('Ad Space', "moderno") =>'pbt_ad_space_options', 
							__('SEO', "moderno") =>'pbt_seo_options'
						);
                        $x = 1;
                        foreach($menuPages as $menuPage => $pagefunction) {
                            echo '<li><a href="#tabbed-'.$x.'">'.$menuPage.'</a></li>';
                            $x++;
                        }
                        ?>
                        </ul>
                        <?php
                        $x = 1;
                        foreach($menuPages as $menuPage => $pagefunction) {
                            echo '<div class="tab-content" id="tabbed-'.$x.'">';
                            if($x>1) echo '<p class="openclose"><a href="#" class="openall">'.__("Open All", "moderno").' [+]</a><a href="#" class="closeall">'.__("Close All", "moderno").' [-]</a></p>';
                            $pagefunction();
                            echo '</div>';
                            $x++;
                        }	
                        ?>
                        </div>
                    </div> <!-- end of #wrapper -->
        		</div> <!-- end of #normal-sortables -->
        	</div> <!-- end of #post-body-content -->
        </div> <!-- end of #post-body -->
    </div> <!-- end of #poststuff -->
    </form>
</div> <!-- end of #wrap -->
<?php
}

// Setting up the design options page tabs
function pbt_design() { 
?>
<div id="arturowrap" class="wrap">
    <h2><?php echo THEME_NAME." ".__("Design Options", "moderno"); ?></h2>
    <?php echo '<div id="message" class="updated fade" style="display: none;"><p><strong>'.THEME_NAME.' '.__("Options Saved", "moderno").'</strong></p></div>'."\n"; ?>
    <form method="post" action="" id="themeform" class="themesbybavotasan">
    <input type="hidden" name="design" value="true" />
    <div id="poststuff" class="metabox-holder has-right-sidebar">
        <div id="side-info-column" class="inner-sidebar thinner">
            <a href="http://themes.bavotasan.com" target="_blank"><img src="<?php echo THEME_URL; ?>/admin/images/brand.png" class="bavota" alt="Themes by bavotasan.com" width="225" height="84" /></a>
            <a href="javascript:{}" id="savetheme"></a><div class="ajaxsave"></div>
            <br class="clear" />
            <div class="postbox thinner" id="themeresources">
            	<div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php _e("Resources", "moderno"); ?></span></h3>
                <div class="inside">
                    <ul>
                        <li><a href="http://themes.bavotasan.com" title="Themes by bavotasan.com">Themes by bavotasan.com</a></li>
                        <li><a href="http://support.bavotasan.com" title="<?php _e('Support Forum', "moderno"); ?>"><?php _e('Support Forum', "moderno"); ?></a></li>
                        <li><a href="http://themes.bavotasan.com/affiliates" title="<?php _e('Affiliates Program', "moderno"); ?>"><?php _e('Affiliates Program', "moderno"); ?></a></li>
                        <li><a href="http://bavotasan.com" title="bavotasan.com">bavotasan.com</a></li>
                    </ul>
 
                </div>
            </div>          
			<br class="clear" />
            <div class="postbox thinner" id="themefontsamples">
            	<div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php _e("@font-face Samples", "moderno"); ?></span></h3>
                <div class="inside">
                    <ul>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/adler.jpg">Adler</a></li>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/chantelli.jpg">Chantelli</a></li>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/chunkfive.jpg">Chunkfive</a></li>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/existence.jpg">Existence</a></li>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/galatia.jpg">Galatia</a></li>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/garogier.jpg">Garogier</a></li>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/jott.jpg">Jott FLF</a></li>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/laffayette.jpg">Laffayette</a></li>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/quicksand.jpg">Quicksand</a></li>
                        <li><a href="javascript:void(0)" class="screenshot" rel="<?php echo THEME_URL; ?>/admin/css/fonts/riesling.jpg">Riesling</a></li>
                    </ul>
 
                </div>
            </div>                        

        </div> <!-- end of #side-info-column -->
        <div id="post-body" class="has-sidebar">
            <div id="post-body-content" class="has-sidebar-content thinmain">
                <div id='normal-sortables' class='meta-box-sortables'>
                    <div id="wrapper" class="arturo">
                        <div id="tabbed">
                        <ul class="tabs">
						<?php
                        $menuPages = array(
							__('Main', "moderno") =>'pbt_design_main', 
							__('Menus', "moderno")=>'pbt_design_menus', 
							__('Sidebars', "moderno") =>'pbt_design_sidebars', 
						);
                        $x = 1;
                        foreach($menuPages as $menuPage => $pagefunction) {
                            echo '<li><a href="#tabbed-'.$x.'">'.$menuPage.'</a></li>';
                            $x++;
                        }
                        ?>
                        </ul>
                        <?php
                        $x = 1;
                        foreach($menuPages as $menuPage => $pagefunction) {
                            echo '<div class="tab-content" id="tabbed-'.$x.'">';
                            echo '<p class="openclose"><a href="#" class="openall">'.__("Open All", "moderno").' [+]</a><a href="#" class="closeall">'.__("Close All", "moderno").' [-]</a></p>';
                            $pagefunction();
                            echo '</div>';
                            $x++;
                        }	
                        ?>
                         </div>
                   </div> <!-- end of #wrapper -->
        		</div> <!-- end of #normal-sortables -->
        	</div> <!-- end of #post-body-content -->
        </div> <!-- end of #post-body -->
    </div> <!-- end of #poststuff -->
    </form>
</div> <!-- end of #wrap -->
<?php
}

////////////////////////
//
// Default input boxes
//
///////////////////////

// OPEN POSTBOX DIV
function openDiv($valueName, $valueDesc = null) {
?>
<div class="postbox">
    <div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php echo $valueName; ?></span><small><?php if(isset($valueDesc)) echo " - ".$valueDesc; ?></small></h3>
    <div class="inside">
<?php
}

// CLOSE POSTBOX DIV
function closeDiv() {
?>
		<br class="clear" />
	</div>
</div>
<?php
}


// TEXTAREA
function textAreaBox($rows = 4, $valueName, $valueDesc, $valueID) {
	openDiv($valueName, $valueDesc);
?>
    <textarea name="<?php echo $valueID; ?>" cols="60" rows="<?php echo $rows; ?>"><?php echo stripslashes(theme_option($valueID)); ?></textarea>
<?php
	closeDiv();
}

// INPUT TEXT
function textBox($size = 50, $valueName, $valueDesc, $valueID, $label = null, $maxlength = null, $align = null, $color = null) {
	openDiv($valueName, $valueDesc);
?>
    <input type="text" name="<?php echo $valueID; ?>" size="<?php echo $size; ?>"<?php if(isset($maxlength)) echo ' maxlength="'.$maxlength.'"'; ?><?php if(isset($align)) echo ' class="'.$align.'"'; ?> value="<?php echo theme_option($valueID); ?>" /><?php if(isset($label)) echo '<label style="margin: 9px 0 0 5px;">'.$label.'</label>'; if(isset($color)) echo '<div class="colorpicked" style="background-color:#'.theme_option($valueID).';">&nbsp;</div>'; ?>
<?php
	closeDiv();
}

// RADIO BUTTON
function radioBox($numof = 2, $valueName, $valueDesc, $valueID, $labels = null) {
	if(!isset($labels)) $labels = array( __('Yes', "moderno"), __('No', "moderno") );
	openDiv($valueName, $valueDesc);
	$i = 0;
    for($x=1;$x<=$numof;$x++) {
		echo '<input  name="'.$valueID.'" type="radio" value="'.$x.'"';
		if(theme_option($valueID) == $x) { echo " checked=\"checked\""; }
        echo ' />&nbsp;<label>'.$labels[$i].'</label>&nbsp;&nbsp;';
    	$i++;
    }
	closeDiv();
}

// COLOR BOX
function colorsBox($size = 50, $valueName, $valueID, $label = null, $maxlength = null, $align = null, $color = false) {
	openDiv($valueName);
?>
    <input type="text" name="<?php echo $valueID; ?>" size="<?php echo $size; ?>"<?php if(isset($maxlength)) echo ' maxlength="'.$maxlength.'"'; ?><?php if(isset($align)) echo ' class="'.$align.'"'; ?> value="<?php echo design_option($valueID); ?>" /><?php if(isset($label)) echo '<label style="margin: 9px 0 0 5px;">'.$label.'</label>'; if(isset($color)) echo '<div class="colorpicked" id="'.$valueID.'" style="background-color:#'.design_option($valueID).';">&nbsp;</div>'; ?>
<?php
	closeDiv();
}

// FONTS BOX
function fontsBox($valueName, $valueID) {
	$sizeID = $valueID."_size";
	openDiv($valueName);
?>
    <table border="0" cellpadding="0" cellspacing="0" class="optionstable">
    <tr><td class="left">
    <select name="<?php echo $valueID; ?>">
        <?php 
        $fonts = array(
            "arial, helvetica, sans-serif" => "Arial",
            "'courier new', courier, monospace" => "Courier New",
            "georgia, times, serif" => "Georgia",
            "'lucida console', monaco, monospace" => "Lucida Console",
            "'lucida sans unicode', 'lucida grande', sans-serif" => "Lucida Sans Unicode",
            "tahoma, geneva, sans-serif" => "Tahoma",
            "'times new roman', times, serif" => "Times New Roman",
            "'trebuchet ms', helvetica, sans-serif" => "Trebuchet MS",
            "verdana, geneva, sans-serif" => "Verdana",
            "'AdlerRegular', arial, sans-serif" => "Adler *",							
            "'ChantelliAntiquaRegular', georgia, serif" => "Chantelli Antique *",
            "'ChunkFiveRegular', courier, monospace" => "Chunk Five *",
            "'ExistenceLightRegular', arial, sans-serif" => "Existence *",
            "'GalatiaSILRegular', times, serif" => "Galatia *",
            "'GarogierRegular', georgia, serif" => "Garogier *",
            "'JottFLFRegular', georgia, serif" => "Jott FLF *",							
            "'LaffayetteComicProRegular', 'Comic Sans MS', arial, sans-serif" => "Laffayette *",							
            "'QuicksandLight', arial, sans-serif" => "Quicksand *",
            "'RieslingRegular', times, serif" => "Riesling *"							
        );
        foreach($fonts as $font => $name) {
            echo '<option value="'.$font.'"';
            if(stripslashes(design_option($valueID)) == $font) echo ' selected="selected"';
            echo '>'.$name.'</option>'."\n";
        
        }
        ?>			
    </select>
    </td><td>&nbsp;<label class="label">Size:</label> <input type="text" size="2" maxlength="2" class="center" name="<?php echo $sizeID; ?>" value="<?php echo design_option($sizeID); ?>" /><label class="label">px</label></td>
    </tr></table>
<?php
	closeDiv();
}

#####################
##  the info page  ##
#####################

function pbt_info() { 
?>
    <img src="<?php echo THEME_URL; ?>/screenshot.png" alt="<?php echo THEME_NAME; ?>" class="theme" width="200" height="150" />
    <?php
    echo '<p><ul><li><strong>'.__('Version', "moderno").':</strong> '.THEME_VERSION.'</li><li><strong>'.__('Author', "moderno").':</strong> <a href="http://bavotasan.com/">'.THEME_AUTHOR.'</a></li><li><strong>'.__('Built by', "moderno").':</strong> <a href="http://themes.bavotasan.com/">Themes by bavotasan.com</a></li><li><strong>'.__('Theme home page', "moderno").':</strong> <a href="'.THEME_HOMEPAGE.'">'.THEME_NAME.'</a></li></ul></p>'; 
    echo '<p>';
	printf(__("Thank you for downloading %s. Hope you enjoy using it!</p>", "moderno"), '<strong>'.THEME_NAME.'</strong>');
	echo '</p><p>';
	_e("There are tons of layout possibilities available with this theme, as well as a bunch of cool features that will surely help you get your site looking and working it's best.", "moderno");
	echo '</p>';
     printf(__('<p>If an update to <strong>%s</strong> is available, you can download it by logging into your account on the <a href="http://themes.bavotasan.com/themers">Themers Only</a> page.</p>', "moderno"), THEME_NAME);
    echo '<p>'.__('Here are some guides to get your started:</p>', "moderno").'</p>'; 
    echo '<p><a href="http://themes.bavotasan.com/support/discussion/17/how-to-customize-a-theme/">'.__('How to Customize a Theme', "moderno").'</a><br />';
    echo '<a href="http://themes.bavotasan.com/support/discussion/19/how-to-set-the-post-thumbnail-featured-image/">'.__('How to Set the Post Thumbnail/Featured Image', "moderno").'</a><br />';	
    echo '<a href="http://themes.bavotasan.com/support/discussion/18/how-to-add-a-logo-to-the-header/">'.__('How to Add a Logo to the Header', "moderno").'</a><br />';	
    echo '<a href="http://themes.bavotasan.com/manual/">'.__('Instruction Manual', "moderno").'</a></p>';	
	echo '<p>'.__('If you have any questions, comments, or if you encounter a bug, please visit our <a href="http://themes.bavotasan.com/support/">Support Forum</a> and let us know.', "moderno").'</p>';	$contents = wp_remote_fopen('http://themes.bavotasan.com/?themeversion=wpt-'.THEME_CODE);
	if(version_compare($contents, THEME_VERSION, '>')) {
		echo '<p class="newversion">';
		printf(__('Version %1$s of %2$s is available for download on the %3$s page.', "moderno"), $contents, '<strong>'.THEME_NAME.'</strong>', '<a href="http://themes.bavotasan.com/themers/" target="_blank">Themers Only</a>');
		echo '</p>';
	}
}

###############################
##  the layout options page  ##
###############################

function pbt_layout_options() {
	global $moderno_options;

	foreach ($moderno_options as $value) { 
		switch ( get_index($value,'id') ) {
	
			case "site_width":
				textBox(4, $value['name'], $value['desc'], $value['id'], 'px', 4, 'center');			
			break;
				
			case "dates":
				openDiv($value['name'], $value['desc']);
			?>
                <input name="dates_front" type="checkbox" <?php if(theme_option("dates_front") == "on") { echo " checked=\"checked\""; } ?> />&nbsp;<label><?php _e("Front Page", "moderno"); ?></label>&nbsp;&nbsp;
                <input name="dates_cats" type="checkbox" <?php if(theme_option("dates_cats") == "on") { echo " checked=\"checked\""; } ?> />&nbsp;<label><?php _e("Categories, Archives, Search Pages", "moderno"); ?></label>&nbsp;&nbsp;
                <input name="dates_posts" type="checkbox" <?php if(theme_option("dates_posts") == "on") { echo " checked=\"checked\""; } ?> />&nbsp;<label><?php _e("Single Posts", "moderno"); ?></label>
			<?php 
				closeDiv();
			break;
	
			case "authors_front":
				openDiv($value['name'], $value['desc']);
			?>
				<input name="authors_front" type="checkbox" <?php if(theme_option("authors_front") == "on") { echo " checked=\"checked\""; } ?> />&nbsp;<label><?php _e("Front Page", "moderno"); ?></label>&nbsp;&nbsp;
				<input name="authors_cats" type="checkbox" <?php if(theme_option("authors_cats") == "on") { echo " checked=\"checked\""; } ?> />&nbsp;<label><?php _e("Categories, Archives, Search Pages", "moderno"); ?></label>&nbsp;&nbsp;
				<input name="authors_posts" type="checkbox" <?php if(theme_option("authors_posts") == "on") { echo " checked=\"checked\""; } ?> />&nbsp;<label><?php _e("Single Posts", "moderno"); ?></label>
			<?php 
				closeDiv();
			break;
			
			case "frontpage_exorcon":
				radioBox(2, $value['name'], $value['desc'], $value['id'], array(__('Excerpt', "moderno"), __('Content', "moderno")));
			break;	
			
			case "excerpt_limit":
				textBox(4, $value['name'], $value['desc'], $value['id'], 'words', 4, 'center');			
			break;
			
			case "comment_count":
				radioBox(2, $value['name'], $value['desc'], $value['id']);
			break;	

			case "more_link_text":
				textBox(50, $value['name'], $value['desc'], $value['id']);			
			break;
		} 
	}
}

###############################
##  the header options page  ##
###############################

function pbt_header_options() {
    global $moderno_options;

	foreach ($moderno_options as $value) { 
		switch ( get_index($value,'id') ) {
	
			case "logo_header":
				openDiv($value['name'], $value['desc']);
			?>
				<input type="text" size="50" name="<?php echo $value['id']; ?>" value="<?php echo theme_option($value['id']); ?>" />
				<?php 
				echo '<div class="headerlogo"></div>';
				closeDiv();
			break;
			
			case "logo_location":
				openDiv($value['name'], $value['desc']);
			?>
				<table>
					<tr>
						<td style="padding-right: 15px;">
							<img src="<?php echo THEME_URL; ?>/admin/images/logoleft.png" alt="" />
						</td>
						<td style="padding-right: 15px;">
							<img src="<?php echo THEME_URL; ?>/admin/images/logoright.png" alt="" />
						</td>
						<td style="padding-right: 15px;">
							<img src="<?php echo THEME_URL; ?>/admin/images/logomiddle.png" alt="" />
						</td>
					</tr>
					<tr>
						<td align="center" style="padding-right: 15px;">
							<input  name="<?php echo $value['id']; ?>" type="radio" value="fl"<?php if(theme_option($value['id']) == "fl") { echo " checked=\"checked\""; } ?> />
						</td>
						<td align="center" style="padding-right: 15px;">
							<input  name="<?php echo $value['id']; ?>" type="radio" value="fr"<?php if(theme_option($value['id']) == "fr") { echo " checked=\"checked\""; } ?> />
						</td>
						<td align="center" style="padding-right: 15px;">
							<input  name="<?php echo $value['id']; ?>" type="radio" value="aligncenter"<?php if(theme_option($value['id']) == "aligncenter") { echo " checked=\"checked\""; } ?> />
						</td>
					</tr>
				</table>
			<?php 
				closeDiv();
			break;			

			case "footer_wordpress_link":
				radioBox(2, $value['name'], $value['desc'], $value['id']);
			break;	

			case "footer_text":
				textAreaBox(4, $value['name'], $value['desc'], $value['id']);
			break;						
		}
	}	
}


#################################
##  the sidebars options page  ##
#################################

function pbt_sidebars_options() {
	global $moderno_options;

	foreach ($moderno_options as $value) { 
		switch ( get_index($value,'id') ) {
				
			case "sidebar_width1":
				textBox(4, $value['name'], $value['desc'], $value['id'], 'px', 4, 'center');			
			break;
			   
			case "sidebar_width2":
				textBox(4, $value['name'], $value['desc'], $value['id'], 'px', 4, 'center');			
			break;			   
			   
			case "sidebar_location1":
				openDiv($value['name'], $value['desc']);
			?>
				<div id="oneSidebar">
					<table>
						<tr>
							<td style="padding-right: 15px;">
								<img src="<?php echo THEME_URL; ?>/admin/images/oneleft.png" alt="One Left" />
							</td>
							<td style="padding-right: 15px;">
								<img src="<?php echo THEME_URL; ?>/admin/images/oneright.png" alt="One Right" />
							</td>
						</tr>
						<tr>
							<td align="center" style="padding-right: 15px;">
								<input  name="<?php echo $value['id']; ?>" type="radio" value="1"<?php if(theme_option($value['id']) == "1") { echo " checked=\"checked\""; } ?> />
							</td>
							<td align="center" style="padding-right: 15px;">
								<input  name="<?php echo $value['id']; ?>" type="radio" value="2"<?php if(theme_option($value['id']) == "2") { echo " checked=\"checked\""; } ?> />
							</td>
						</tr>
					</table>
				</div>
				<div id="twoSidebar">
					<table>
						<tr>
							<td style="padding-right: 15px;">
								<img src="<?php echo THEME_URL; ?>/admin/images/twoleft.png" alt="" />
							</td>
							<td style="padding-right: 15px;">
								<img src="<?php echo THEME_URL; ?>/admin/images/tworight.png" alt="" />
							</td>
							<td style="padding-right: 15px;">
								<img src="<?php echo THEME_URL; ?>/admin/images/twoseparate.png" alt="" />
							</td>
						</tr>
						<tr>
							<td align="center" style="padding-right: 15px;">
								<input  name="<?php echo $value['id']; ?>" type="radio" value="3"<?php if(theme_option($value['id']) == "3") { echo ' checked="checked"'; } ?> />
							</td>
							<td align="center" style="padding-right: 15px;">
								<input  name="<?php echo $value['id']; ?>" type="radio" value="4"<?php if(theme_option($value['id']) == "4") { echo ' checked="checked"'; } ?> />
							</td>
							<td align="center" style="padding-right: 15px;">
								<input  name="<?php echo $value['id']; ?>" type="radio" value="5"<?php if(theme_option($value['id']) == "5") { echo ' checked="checked"'; } ?> />
							</td>
						</tr>
					</table>
				</div>
				<p class="locerror"></p>
			<?php 
				closeDiv();
			break;			

			case "extended_footer":
				radioBox(2, $value['name'], $value['desc'], $value['id']);
			break;	
		} 
	}
}

###################################
##  the colors main page  ##
###################################

function pbt_design_main() {
    global $moderno_design_options, $designs;

	foreach ($moderno_design_options as $value) { 
		switch ( get_index($value,'id') ) {
	
			case "main_content_bg_color":
				echo '<table border="0" cellpadding="0" cellspacing="0" class="sidebyside"><tr><td class="left">';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td>';
			break;
				
			case "top_border":
				echo '<td>';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td></tr>';
			break;
					
			case "text_color":
				echo '<tr><td class="left">';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td>';
			break;	
			
			case "headers_text_color":
				echo '<td>';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td></tr>';
			break;

			case "link_color":
				echo '<tr><td class="left">';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td>';
			break;	
			
			case "link_hover_color":
				echo '<td>';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td></tr>';
			break;
			
			case "main_font":
				echo '<tr><td class="left">';
				fontsBox($value['name'], $value['id']);
				echo '</td>';
			break;
			
			case "title_font":
				echo '<td>';
				fontsBox($value['name'], $value['id']);
				echo '</td></tr>';
			break;
			
			case "post_title_font":
				echo '<tr><td class="left">';
				fontsBox($value['name'], $value['id']);
				echo '</td>';
			break;
			
			case "post_title_single_font":
				echo '<td>';
				fontsBox($value['name'], $value['id']);
				echo '</td></tr></table>';
			break;				
		}
	}
}

###################################
##  the colors menus page  ##
###################################

function pbt_design_menus() {
    global $moderno_design_options, $designs;

	foreach ($moderno_design_options as $value) { 
		switch ( get_index($value,'id') ) {
			
			case "nav_menu_link_color":
				echo '<table border="0" cellpadding="0" cellspacing="0" class="sidebyside"><tr><td class="left">';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td>';
			break;
			
			case "nav_font":
				echo '<td>';
				fontsBox($value['name'], $value['id']);
				echo '</td></tr>';
			break;				
			
			case "nav_menu_border_color":
				echo '<tr><td class="left">';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td>';
			break;			
			
			case "nav_menu_border_hover_color":
				echo '<td>';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td></tr></table>';
			break;	
		}
	}
}

###################################
##  the colors sidebar page  ##
###################################

function pbt_design_sidebars() {
    global $moderno_design_options, $designs;

	foreach ($moderno_design_options as $value) { 
		switch ( get_index($value,'id') ) {
			
			case "side_widget_link_color":
				echo '<table border="0" cellpadding="0" cellspacing="0" class="sidebyside"><tr><td class="left">';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td>';
			break;	
			
			case "side_widget_link_hover_color":
				echo '<td>';
				colorsBox(6, $value['name'], $value['id'], '', 6, 'center picker', true);
				echo '</td></tr>';
			break;																			

			case "sidebar_text_font":
				echo '<tr><td class="left">';
				fontsBox($value['name'], $value['id']);
				echo '</td>';
			break;

			case "sidebar_header_font":
				echo '<td>';
				fontsBox($value['name'], $value['id']);
				echo '</td></tr></table>';
			break;	
		}
	}
}

#################################
##  the ad space options page  ##
#################################

function pbt_ad_space_options() {
    global $moderno_options;

	foreach ($moderno_options as $value) { 
		switch ( get_index($value,'id') ) {
	
			case "header_ad":
				textAreaBox(4, $value['name'], $value['desc'], $value['id']);
			break;
	
			case "sidebar_ad":
				textAreaBox(4, $value['name'], $value['desc'], $value['id']);
			break;
	
			case "footer_ad":
				textAreaBox(4, $value['name'], $value['desc'], $value['id']);
			break;
		}
	}
}

############################
##  the seo options page  ##
############################

function pbt_seo_options() {
    global $moderno_options;

	foreach ($moderno_options as $value) { 
		switch ( get_index($value,'id') ) {
	
			case "site_description":
				textAreaBox(4, $value['name'], $value['desc'], $value['id']);
			break;
	
			case "keywords":
				textAreaBox(4, $value['name'], $value['desc'], $value['id']);
			break;
	
			case "google_analytics":
				textAreaBox(6, $value['name'], $value['desc'], $value['id']);
			break;
		}
	}
}

function pbt_widgets_init() {
	wp_register_script('effects_js', THEME_URL.'/js/effects.js', array( 'jquery' , 'jquery-ui-core' , 'jquery-ui-tabs' ),'',true);
	
	// include the widgets
	include(TEMPLATEPATH.'/widgets/widget_sideads.php');
	include(TEMPLATEPATH.'/widgets/widget_login.php'); 
	include(TEMPLATEPATH.'/widgets/widget_contributors.php'); 
	include(TEMPLATEPATH.'/widgets/widget_twitter.php'); 

	// Initiating the sidebars
	if (function_exists("register_sidebar")) {
		register_sidebar(array(
			'name' => __('Sidebar One', "moderno"),
			'description' => __( "The first sidebar", "moderno" ),
			'before_widget' => '<div id="%1$s" class="side-widget %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h3>',
			'after_title' => '</h3>',
		));
		
		if (theme_option('sidebar_width2')!=0) {
			register_sidebar(array(
				'name' => __('Sidebar Two', "moderno"),
				'description' => __( "The second sidebar", "moderno" ),
				'before_widget' => '<div id="%1$s" class="side-widget %2$s">',
				'after_widget' => '</div>',
				'before_title' => '<h3>',
				'after_title' => '</h3>',
			));
		}
		if(theme_option('extended_footer')!=2) {
			register_sidebar(array(
				'name' => __('Extended Footer', "moderno"),
				'description' => __( "The extended footer", "moderno" ),
				'before_widget' => '<div id="%1$s" class="bottom-widget %2$s">',
				'after_widget' => '</div>',
				'before_title' => '<h3>',
				'after_title' => '</h3>',
			));
		}
	}
}
add_action( 'init', 'pbt_widgets_init' );

// Tags for keywords
function csv_tags() {
    $posttags = get_the_tags();
	$csv_tags = '';
    if($posttags) {
		foreach((array)$posttags as $tag) {
			$csv_tags .= $tag->name . ',';
		}
	}
    echo '<meta name="keywords" content="'.$csv_tags.theme_option('keywords').'" />';
}

//excerpt word length
function new_excerpt_length($length) {
	return theme_option('excerpt_limit');
}
add_filter('excerpt_length', 'new_excerpt_length');

// Theme contents
function theme_content($readmore) {
	$content = get_the_content($readmore);
	$content = preg_replace("/<img[^>]+\>/i", "", $content); 
	$content = preg_replace('/\[.+\]/','', $content);
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]>', ']]&gt;', $content);
	echo $content;
}

// Meta description
function metaDesc() {
	$content = apply_filters('the_content_rss', strip_tags(get_the_content()));
	$content = preg_replace('/\[.+\]/','', $content);
	$chars = array("", "\n", "\r", "chr(13)",  "\t", "\0", "\x0B");
	$content = htmlentities(str_replace($chars, " ", $content));
	if(empty($content)) {
		$content = htmlentities(theme_option('site_description'));
	}
	if (strlen($content) < 155) {
		echo $content;
	} else {
		$desc = substr($content,0,155);
		echo $desc."...";
	}
}

// image grabber function
function resize($w,$h,$class='alignleft',$showlink=true) {
	global $more, $post;
	$title = the_title_attribute('echo=0');
	if($showlink) {
		$link = "<a href='".get_permalink()."' title='$title'>";
		$linkend = "</a>";
	} else {
		$link ="";
		$linkend="";
	}
	$more = 1;
	$content = get_the_content();
	$pattern = '/<img[^>]+src[\\s=\'"]';
	$pattern .= '+([^"\'>\\s]+)/is';
	$more = 0;
	if(preg_match($pattern,$content,$match)) {
		$theImage =  "$link<img src=\"$match[1]\" class=\"$class\" alt=\"$title\" width=\"$w\" height=\"$h\" />$linkend\n\n";
		return $theImage;
	}
}

// Comments
function mytheme_comment($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment; ?>
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
	<div id="comment-<?php comment_ID(); ?>">
        <div class="comment-avatar">
        	<?php echo get_avatar($comment,$size='48'); ?>
        </div>     
        <div class="comment-author">
        	<?php echo get_comment_author_link()." ";
        	printf(__('on %1$s at %2$s', "moderno"), get_comment_date(),get_comment_time()); 
			edit_comment_link(__('(Edit)', "moderno"),'  ','');
			?>
        </div>
        <div class="comment-text">
	        <?php if ($comment->comment_approved == '0') { _e('<em>Your comment is awaiting moderation.</em>', "moderno"); } ?>
        	<?php comment_text() ?>
        </div>
        <?php if($args['max_depth']!=$depth && comments_open() && $comment->comment_type!="pingback") { ?>
        <div class="reply">
        	<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
        </div>
        <?php } ?>
	</div>
<?php
}
### Function: Page Navigation: Boxed Style Paging
function pagination($before = '', $after = '') {
	global $wpdb, $wp_query;
	$pagenavi_options = array();
	$pagenavi_options['pages_text'] = __('Page %CURRENT_PAGE% of %TOTAL_PAGES%',"moderno");
	$pagenavi_options['current_text'] = '%PAGE_NUMBER%';
	$pagenavi_options['page_text'] = '%PAGE_NUMBER%';
	$pagenavi_options['first_text'] = __('First Page',"moderno");
	$pagenavi_options['last_text'] = __('Last Page',"moderno");
	$pagenavi_options['next_text'] = '&raquo;';
	$pagenavi_options['prev_text'] = '&laquo;';
	$pagenavi_options['dotright_text'] = '...';
	$pagenavi_options['dotleft_text'] = '...';
	$pagenavi_options['num_pages'] = 5;
	$pagenavi_options['always_show'] = 0;
	$pagenavi_options['num_larger_page_numbers'] = 0;
	$pagenavi_options['larger_page_numbers_multiple'] = 5;
	if (!is_single()) {
		$request = $wp_query->request;
		$posts_per_page = intval(get_query_var('posts_per_page'));
		$paged = intval(get_query_var('paged'));
		$numposts = $wp_query->found_posts;
		$max_page = $wp_query->max_num_pages;
		if(empty($paged) || $paged == 0) {
			$paged = 1;
		}
		$pages_to_show = intval($pagenavi_options['num_pages']);
		$larger_page_to_show = intval($pagenavi_options['num_larger_page_numbers']);
		$larger_page_multiple = intval($pagenavi_options['larger_page_numbers_multiple']);
		$pages_to_show_minus_1 = $pages_to_show - 1;
		$half_page_start = floor($pages_to_show_minus_1/2);
		$half_page_end = ceil($pages_to_show_minus_1/2);
		$start_page = $paged - $half_page_start;
		if($start_page <= 0) {
			$start_page = 1;
		}
		$end_page = $paged + $half_page_end;
		if(($end_page - $start_page) != $pages_to_show_minus_1) {
			$end_page = $start_page + $pages_to_show_minus_1;
		}
		if($end_page > $max_page) {
			$start_page = $max_page - $pages_to_show_minus_1;
			$end_page = $max_page;
		}
		if($start_page <= 0) {
			$start_page = 1;
		}
		$larger_per_page = $larger_page_to_show*$larger_page_multiple;
		$larger_start_page_start = (n_round($start_page, 10) + $larger_page_multiple) - $larger_per_page;
		$larger_start_page_end = n_round($start_page, 10) + $larger_page_multiple;
		$larger_end_page_start = n_round($end_page, 10) + $larger_page_multiple;
		$larger_end_page_end = n_round($end_page, 10) + ($larger_per_page);
		if($larger_start_page_end - $larger_page_multiple == $start_page) {
			$larger_start_page_start = $larger_start_page_start - $larger_page_multiple;
			$larger_start_page_end = $larger_start_page_end - $larger_page_multiple;
		}
		if($larger_start_page_start <= 0) {
			$larger_start_page_start = $larger_page_multiple;
		}
		if($larger_start_page_end > $max_page) {
			$larger_start_page_end = $max_page;
		}
		if($larger_end_page_end > $max_page) {
			$larger_end_page_end = $max_page;
		}
		if($max_page > 1 || intval($pagenavi_options['always_show']) == 1) {
			$pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $pagenavi_options['pages_text']);
			$pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);
			echo $before.'<div class="pagination">'."\n";
			if(!empty($pages_text)) {
				echo '<span class="pages">'.$pages_text.'</span>';
			}
			previous_posts_link($pagenavi_options['prev_text']);
			if ($start_page >= 2 && $pages_to_show < $max_page) {
				$first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['first_text']);
				echo '<a href="'.esc_url(get_pagenum_link()).'" class="first" title="'.$first_page_text.'">1</a>';
				if(!empty($pagenavi_options['dotleft_text'])) {
					echo '<span class="extend">'.$pagenavi_options['dotleft_text'].'</span>';
				}
			}
			if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page) {
				for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple) {
					$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
					echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
				}
			}
			for($i = $start_page; $i  <= $end_page; $i++) {						
				if($i == $paged) {
					$current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['current_text']);
					echo '<span class="current">'.$current_page_text.'</span>';
				} else {
					$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
					echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
				}
			}
			if ($end_page < $max_page) {
				if(!empty($pagenavi_options['dotright_text'])) {
					echo '<span class="extend">'.$pagenavi_options['dotright_text'].'</span>';
				}
				$last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['last_text']);
				echo '<a href="'.esc_url(get_pagenum_link($max_page)).'" class="last" title="'.$last_page_text.'">'.$max_page.'</a>';
			}
			next_posts_link($pagenavi_options['next_text'], $max_page);
			if($larger_page_to_show > 0 && $larger_end_page_start < $max_page) {
				for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple) {
					$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
					echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
				}
					}

			echo '</div>'.$after."\n";
		}
	}
}

### Function: Round To The Nearest Value
function n_round($num, $tonearest) {
   return floor($num/$tonearest)*$tonearest;
}

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

// Functions to add meta boxes to the post edit page
function pbt_layout_option() {
	global $post;
	$layout = get_post_meta($post->ID, 'pbt_single_layout', true);
	$single_sidebar_width = get_post_meta($post->ID, 'pbt_single_sidebar_width', true);
	echo '<table border="0" cellpadding="0" cellspacing="5">';
	echo '<tr><td><input name="pbt_single_layout" type="radio" value="1"'; if($layout == 1 || !$layout) echo ' checked="checked"'; echo ' /></td><td>'.__('Default', "moderno").'</td></tr>';
	echo '<tr><td><input name="pbt_single_layout" type="radio" value="2"'; if($layout == 2) echo ' checked="checked"'; echo ' /></td><td>'.__('Full width', "moderno").'</td></tr>';
	echo '</table>';
}

function pbt_create_meta_box() {
	if ( function_exists('add_meta_box') ) {
		add_meta_box( 'pbt-layout-options', __('Layout', "moderno"), 'pbt_layout_option', 'post', 'side', 'low' );
		add_meta_box( 'pbt-layout-options', __('Layout', "moderno"), 'pbt_layout_option', 'page', 'side', 'low' );
	}
}

function pbt_save_postdata( $post_id ) {
	global $post, $new_meta_boxes;
	
	if($_POST['pbt_single_layout']) update_post_meta($post_id, 'pbt_single_layout', $_POST['pbt_single_layout']);
}

add_action('admin_menu', 'pbt_create_meta_box');
add_action('save_post', 'pbt_save_postdata');

/* ADDING NEW THUMBNAIL STUFF */
if ( !function_exists('pbt_AddThumbColumn') && function_exists('add_theme_support') ) {
 
	// for post and page
	add_theme_support('post-thumbnails');
 
	function pbt_AddThumbColumn($cols) {
 
		$cols['thumbnail'] = __('Thumbnail', "moderno");
 
		return $cols;
	}
 
	function pbt_AddThumbValue($column_name, $post_id) {
 
			$width = (int) 35;
			$height = (int) 35;
 
			if ( 'thumbnail' == $column_name ) {
				// thumbnail of WP 2.9
				$thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
				// image from gallery
				$attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
				if ($thumbnail_id)
					$thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
				elseif ($attachments) {
					foreach ( $attachments as $attachment_id => $attachment ) {
						$thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
					}
				}
					if ( isset($thumb) && $thumb ) {
						echo $thumb;
					} else {
						echo __('None', "moderno");
					}
			}
	}
 
	// for posts
	add_filter( 'manage_posts_columns', 'pbt_AddThumbColumn' );
	add_action( 'manage_posts_custom_column', 'pbt_AddThumbValue', 10, 2 );
 
	// for pages
	add_filter( 'manage_pages_columns', 'pbt_AddThumbColumn' );
	add_action( 'manage_pages_custom_column', 'pbt_AddThumbValue', 10, 2 );

	add_image_size( 'main-thumb', (CONTENT_WIDTH-60), 210, true ); // Main thumbnail size
}

// This theme allows users to set a custom background
if(function_exists('add_custom_background')) add_custom_background();

// This theme uses wp_nav_menu()
if(function_exists('register_nav_menu')) {
	add_theme_support( 'nav-menus' );
	register_nav_menu('main', 'Main Navigation Menu');
}

add_theme_support( 'automatic-feed-links' );

function menu_default() {
	echo '<p class="warning clear">Create your navigation menu <a href="'.admin_url('nav-menus.php').'">here</a>.</p>';
}

add_filter('body_class','fullWidth');

function fullWidth($classes = '') {
	global $post;
	$full = get_post_meta($post->ID, 'pbt_single_layout', true);
	if($full==2 && is_singular()) $classes[] = 'fullwidth';
	return $classes;
}

function add_menu_admin_bar() {
    global $wp_admin_bar, $wpdb;

    if ( !is_super_admin() || !is_admin_bar_showing() )
        return;

    /* Add the main siteadmin menu item */
    $wp_admin_bar->add_menu( array( 'id' => 'theme_options', 'title' => THEME_NAME, 'href' => admin_url('admin.php')."?page=".THEME_FILE ) );
    $wp_admin_bar->add_menu( array( 'parent' => 'theme_options', 'title' => __( 'Layout Options', 'moderno' ), 'href' => admin_url('admin.php')."?page=".THEME_FILE ) );
    $wp_admin_bar->add_menu( array( 'parent' => 'theme_options', 'title' => __( 'Design Options', 'moderno' ), 'href' => admin_url('admin.php')."?page=".THEME_FILE."-design" ) );
    $wp_admin_bar->add_menu( array( 'parent' => 'theme_options', 'title' => __( 'Custom CSS', 'moderno' ), 'href' => admin_url('admin.php')."?page=".THEME_FILE."-CSS" ) );
}
add_action( 'admin_bar_menu', 'add_menu_admin_bar', 1000 );
?>