<?php
	// get the theme options and shortcodes
	include "theme-options.php";
	include "shortcodes.php";
	
	// add in the needed scripts and styles
	if(!is_admin()) {
		function mnk_enqueue_scripts() {
			// google jquery
			wp_deregister_script( 'jquery' );
			wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
			wp_enqueue_script( 'jquery' );
			
			// google jquery ui
			wp_deregister_script( 'jquery-ui-core' );
			wp_register_script( 'jquery-ui-core', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js');
			wp_register_style('jquery-ui-core-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
			wp_enqueue_style('jquery-ui-core-css');
			wp_enqueue_script( 'jquery-ui-core' );
			
			// slimbox
			wp_register_style('mnk-slim-css', get_template_directory_uri() . '/slim/css/slimbox2.css');
			wp_register_script('mnk-slim-js', get_template_directory_uri() . '/slim/js/slimbox2.js');
			wp_enqueue_style('mnk-slim-css');
			wp_enqueue_script('mnk-slim-js');
			
			// theme specific scripts
			wp_register_script( 'mnk-jscript', get_template_directory_uri() . '/mnk-jscript.js' );
			wp_enqueue_script( 'mnk-jscript' );
		}
		
		add_action('wp_enqueue_scripts', 'mnk_enqueue_scripts');
	}
	
	// set up sidebar
	if ( function_exists('register_sidebar') ) {
		register_sidebar(array('name'=>'sidebar',
			'before_widget' => '<li class="pagewrap">',
			'after_widget' => '</li>',
			'before_title' => '<h2 class="widgettitle">',
			'after_title' => '</h2>',
		));
	}
	
	// change excerpt
	function mnk_excerpt_length($length){
		return 90;
	}
	add_filter('excerpt_length', 'mnk_excerpt_length');

	function mnk_excerpt_more($text) {
   		return str_replace('[...]', ' <a class="read-more" href="'.get_permalink().'">More &rarr;</a>', $text);
	}
	add_filter('excerpt_more', 'mnk_excerpt_more');
	
	// post thumbnails
	if ( function_exists( 'add_theme_support' ) ) {
		add_theme_support( 'post-thumbnails' );
		set_post_thumbnail_size( 250, 250, false );
	}

	// register menu
	if ( function_exists( 'register_nav_menu' ) ) {
		register_nav_menu( 'nav-menu', 'Main Navigation Menu' );
	}

	// support feed links
	add_theme_support( 'automatic-feed-links' );
	
	// header image ( logo )
	define('HEADER_TEXTCOLOR', '700000');
	define('NO_HEADER_TEXT', true );
	define('HEADER_IMAGE', '%s/images/default.png');
	define('HEADER_IMAGE_WIDTH', 150);
	define('HEADER_IMAGE_HEIGHT', 50);
	
	// gets included in the site header
	function mnk_header_style() {
		?><style type="text/css">
			#logo {
				background: url('<?php header_image(); ?>');
			}
		</style><?php
	}
	
	// gets included in the admin header
	function mnk_admin_header_style() {
    echo '<style type="text/css">
        #headimg {
            width: ' . HEADER_IMAGE_WIDTH . 'px;
            height: ' . HEADER_IMAGE_HEIGHT . 'px;
            background: no-repeat;
        }
    </style>';
	}
	
	add_custom_image_header('mnk_header_style', 'mnk_admin_header_style');
	
	// support custom background
	add_custom_background();
	
	// remove admin-bar
	add_filter( 'show_admin_bar', '__return_false' );

	// default content width
	if ( ! isset( $content_width ) ) $content_width = 550;
	
	// pagination
	function mnk_pagination($pages = '', $range = 2) {  
     	$showitems = ($range * 2)+1;  
		global $paged;
		if(empty($paged)) $paged = 1;
		if($pages == '') {
         	global $wp_query;
         	$pages = $wp_query->max_num_pages;
         	if(!$pages) {
             	$pages = 1;
         	}
     	}   
		if(1 != $pages) {
         	echo "<div class='pagination'>";
         	if($paged > 2 && $paged > $range+1 && $showitems < $pages) {
				echo "<a href='".htmlspecialchars(get_pagenum_link(1))."'><</a>";
			}
         	if($paged > 1 && $showitems < $pages) {
				echo "<a href='".htmlspecialchars(get_pagenum_link($paged - 1))."'><</a>";
			}
			for ($i=1; $i <= $pages; $i++) {
             	if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
                 	echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".htmlspecialchars(get_pagenum_link($i))."' class='inactive' >".$i."</a>";
             	}
         	}
			if ($paged < $pages && $showitems < $pages) {
				echo "<a href='".htmlspecialchars(get_pagenum_link($paged + 1))."'>></a>";
			}
         	if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) {
				echo "<a href='".htmlspecialchars(get_pagenum_link($pages))."'>>></a>";
     		}
			echo "</div>\n";
		}
	}
	
	// breadcrumbs
	function mnk_breadcrumbs() {
		if (!is_home()) {
			if (is_category() || is_single()) {
				echo '<h4>';
				the_category(' &raquo ');
				if (is_single()) {
					echo " &raquo ";
					the_title();
				}
				echo '</h4>';
			}
			elseif (is_page()) {
				echo '<h4>';
				the_title();
				echo '</h4>';
			}
            elseif (is_archive()) {
				if(is_month()) {
					echo '<h4>';
                    the_time('F, Y');
					echo '</h4>';
				}
				elseif(is_day()) {
					echo '<h4>';
					the_time('l, F jS, Y');
					echo '</h4>';
				}
				elseif(is_year()) {
					echo '<h4>';
					the_time('Y');
					echo '</h4>';
				}
            }
			elseif (is_search()) {
				echo '<h4>';
				the_search_query();
				echo '<h4>';
			}
		}
		else {
			echo "<h4>Home</h4>";
		}
	}
	
	// adds custom link color
	function mnk_link_color($color = '') {
		$r = 'body a { color:#' . $color . '; } ';
		$r .= '#bread h4 a, #bread h4 { color:#' . $color . '; } ';
		$r .= 'li.pagewrap a:hover { color:#' . $color . '; } ';
		$r .= 'h1.title { color:#' . $color . '; } ';
		$r .= '#nav ul li a { color:#' . $color . '; } ';
		$r .= '#nav ul li ul li a { color:#' . $color . '; } ';
		$r .= '.comment-body a { color:#' . $color . '; } ';
		return $r;
	}
?>