<?php

global  $theme_version,
	        $next_page,
	        $next_page_txt,
        $js_status;



//  get functions
require( dirname(__FILE__) . '/gn.php' );
require( dirname(__FILE__) . '/gn_print_option_page.php' );

// Prepare for localization
load_theme_textdomain ('german_newspaper');

add_action('init', gn_init_method);
//  load CSS for theme option page
//	add_action('admin_init','gn_load_css');
//  second way to load a css file for the admin area
//	wp_admin_css( 'name', true );
add_action('admin_head', 'gn_load_css');
// check for new comments feature of wp 2.7
add_filter( 'comments_template', 'legacy_comments' );
// add a microid to all the comments
add_filter('comment_class','comment_add_microid');


	add_option( 'gn_left_img', get_template_directory_uri() . '/news-images/cuyabeno.jpg' );
	add_option( 'gn_right_img', get_template_directory_uri() . '/news-images/waterfall3.jpg' );
	add_option( 'gn_left_img_atxt', '' );
	add_option( 'gn_right_img_atxt', '' );
	add_option( 'gn_left_img_lnk', '' );
	add_option( 'gn_right_img_lnk', '' );
	add_option( 'gn_header_img', '/images/earth_2.gif' );
	add_option( 'gn_show_header', 'off' );
	add_option( 'gn_img_background', '#000' );
	add_option( 'gn_next_page', 'off' );
	add_option( 'gn_next_page_txt', 'Read more about ...' );
	add_option( 'gn_page_exclude', '' );
	add_option( 'gn_body_color', '#333' );
	add_option( 'gn_body_background', 'silver' );
	add_option( 'gn_wrapper_background', 'white' );
	add_option( 'gn_seo_meta_tags', 'off' );
	add_option( 'gn_seo_meta_author', '' );
	add_option( 'gn_seo_meta_desc', '' );
	add_option( 'gn_seo_meta_keyw', '' );
	add_option( 'gn_geourl_meta_tags', 'off' );
	add_option( 'gn_geourl_loc', '' );
	add_option( 'gn_geourl_title', '' );
	add_option( 'gn_screen_width', 'off' );
	add_option( 'gn_tab_feature_b1', 'off' );
	add_option( 'gn_tab_feature_b2', 'off' );
	add_option( 'gn_tab_count_b1', '3' );
	add_option( 'gn_tab_count_b2', '3' );
	
  add_action( 'admin_menu', 'gn_add_theme_option_page' );

	check_tab_feature();
	
	check_screen_width();


////////////////////////////////////////////////////////////////////////////////
// register theme option page
////////////////////////////////////////////////////////////////////////////////
function gn_add_theme_option_page()
{
	add_theme_page(__('German Newspaper Options'), __('German Newspaper Options'), 'edit_themes', basename(__FILE__), 'gn_theme_option_page');
}

function gn_theme_option_page()
{
	global 	$tab_feature_b1,
	        $tab_feature_b2,
	        $seo_meta_tags,
	        $geourl_meta_tags,
	        $geourl_loc,
	        $geourl_title,
	        $next_page,
	        $next_page_txt,
	        $theme_version,
	        $screen_width,
	        $tab_count_b1,
	        $tab_count_b2,
	        $tab_b1_titles,
 	        $tab_b2_titles;


	if ( isset( $_POST['info_update'] ) )
	{
		//  call update function
		update_gn_options();
	}

	gn_print_option_page();
}


////////////////////////////////////////////////////////////////////////////////
// get theme version from stylesheet file
////////////////////////////////////////////////////////////////////////////////
function gn_get_theme_version()
{
	global $theme_version;

 	$themes = get_themes( );
	$current_theme = get_current_theme( );
	$current_theme = $themes[$current_theme];
	$theme_version = $current_theme['Version'];

	return $theme_version;
}

// check for new comments feature of wp 2.7
function legacy_comments( $file ) 
{
	if ( !function_exists('wp_list_comments') )
		$file = TEMPLATEPATH . '/legacy.comments.php';
	return $file;
}

// add a microid to all the comments
function comment_add_microid($classes) {
	$c_email=get_comment_author_email();
	$c_url=get_comment_author_url();
	if (!empty($c_email) && !empty($c_url)) {
		$microid = 'microid-mailto+http:sha1:' . sha1(sha1('mailto:'.$c_email).sha1($c_url));
		$classes[] = $microid;
	}
	return $classes;
}




////////////////////////////////////////////////////////////////////////////////
// theme init function
////////////////////////////////////////////////////////////////////////////////
function gn_init_method() 
{
  $theme_dir   = get_bloginfo('template_directory');
	$str_pos     = strrpos(WP_CONTENT_URL, '/');
	$dir_content = substr( WP_CONTENT_URL, $str_pos);
	$str_pos     = strpos( $theme_dir, '/themes/');
	$dir_str     = substr( $theme_dir, $str_pos + 8);
	$file_dir    = $dir_content . '/themes/' . $dir_str;

  wp_enqueue_script('js_check', $file_dir . '/js/js_check.js');
  wp_enqueue_script('jquery');

//  get theme version to print in the header html code
//  and on the Theme Option Page
$theme_version = gn_get_theme_version();

//  register sidebars
if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'name' => 'Left_Menu',
		'id' => 'Left_Menu',
		'before_widget' => '<li>',
		'after_widget' => '</li>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));

if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'name' => 'Right_Menu',
		'id' => 'Right_Menu',
		'before_widget' => '<li>',
		'after_widget' => '</li>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));

}


?>