<?php

	include (TEMPLATEPATH . '/options/deluxe_metabox.php');
	include_once( TEMPLATEPATH."/options/deluxe_dynamic_vars.php");
	include_once( TEMPLATEPATH."/options/deluxe_shortcodes.php");
	include_once( TEMPLATEPATH."/options/deluxe_pagenavi.php");

	$right_sidebars = array('Right Widget 1 (All of Pages)', 'Right Widget 2 (All of Pages)', 'Right Widget 3 (All of Pages)', 'Right Widget 4 (All of Pages)', 'Right Widget 5 (All of Pages)', 'Blog Widget 1');
	
	foreach($right_sidebars as $rsidebar) {
		register_sidebar(array('name'=> $rsidebar, 'description' => 'Custom Widgets', 'before_widget' => '<div class="textwidget"><div class="page_navigation_advert">', 'after_widget' => '</div></div>', 'before_title' => '<div class="page_navigation_title"><h3>', 'after_title' => '</h3></div>'));
	}
	
	if (function_exists('register_nav_menus')){
		register_nav_menus( array(
			'primary' => __( 'Primary Navigation', 'twentyten' ),
		) );
	}
	
	if (function_exists('add_custom_background')){
		add_custom_background();
	}
	
	
	function twentyten_page_menu_args( $args ) {
		if (get_option('disable_home_page', 1) == '1'){
			$args['show_home'] = true;
		}else{
			$args['show_home'] = false;
		}
		
		$args['container'] = false;
		return $args;
	}
	
	function remove_menu_title( $args ) {
		$args = preg_replace('/title=\"(.*?)\"/','',$args);
		return $args;
	}
	
	function change_menu_home( $args ) {
		$home_name = get_option('home_page_name', 'Home');
		$args = str_replace('Home', $home_name, $args);
		return $args;
	}

	add_filter( 'wp_page_menu', 'remove_menu_title' );
	add_filter( 'wp_page_menu', 'change_menu_home' );
	
	add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
	
	add_filter('wp_list_pages','removes_titles');
	function removes_titles($content) {
		$content = preg_replace('/title=\"(.*?)\"/','',$content);
		return $content;
	}
	
	function list_categories($name, $value)
	{
		echo "<select name=$name>";
		echo "<option value=\"\">Select Category</option>";
	
		$categories = get_categories("title_li=&orderby=name");
		foreach ($categories as $category)
		{
			$selected = ($value == $category->term_id) ? "selected=\"selected\"" : "";
			echo "<option $selected value='". $category->term_id ."'>". $category->name ."</option>";
		}
		echo "</select>";
	}

	function list_pages($name, $value)
	{
		echo "<select name=$name>";
		echo "<option value=\"\">Select Category</option>";
	
		$pages = get_pages(); 

		foreach ($pages as $page)
		{
			$selected = ($value == $page->ID) ? "selected=\"selected\"" : "";
			echo "<option $selected value='". $page->ID ."'>". $page->post_title ."</option>";
		}
		echo "</select>";
	}

	function list_onoff($name, $value)
	{
	
		echo "<select name='$name'>";
		$items = array('on', 'off');
		foreach ($items as $item)
		{
			$selected = ($value == $item) ? "selected=\"selected\"" : "";
			echo "<option $selected value='". $item ."'>". $item ."</option>";
		}
		echo "</select>";
	}
	
	
	if(get_option("disable_wpautop", "off") == "on"){
		remove_filter('the_content', 'wpautop');
		remove_filter('the_content', 'wptexturize');
	}

	
	add_filter('widget_text', 'do_shortcode');

	function create_page($this_page) {

		if( !$this_page->post_parent ) {
			
			
			$pagelist = '<li class="current_page_item"><a href="'.  get_page_link($this_page->ID) .'"><span>' . $this_page->post_title . '</span></a>';
			$children = wp_list_pages('sort_column=menu_order&sort_order=ASC&link_before=<span>&link_after=</span>&title_li=&child_of='.$this_page->ID.'&echo=0');
			if( $children ) $pagelist .= '<ul class="children">' . $children . '</ul>';
			$pagelist .= '</li>';
		}
		elseif( $this_page->ancestors ) {

			$ancestor = end($this_page->ancestors);
			$pagelist = wp_list_pages('sort_column=menu_order&sort_order=ASC&link_before=<span>&link_after=</span>&title_li=&include='.$ancestor.'&echo=0');
			$pagelist = str_replace('</li>', '', $pagelist);
			$pagelist .= '<ul class="children">' . wp_list_pages('sort_column=menu_order&sort_order=ASC&link_before=<span>&link_after=</span>&title_li=&child_of='.$ancestor.'&echo=0') .'</ul></li>';
		}
		return $pagelist;
		
	}

	
	add_action('admin_menu', 'wpress_create_menu');
	
	function wpress_create_menu() {
		
		add_menu_page('The Deluxe Settings', 'The Deluxe', 'administrator', "tdeluxe", 'deluxe_settings');
		add_submenu_page('tdeluxe', 'Deluxe Settings ', 'Deluxe Settings', 'administrator', 'tdeluxe', 'deluxe_settings');
		add_submenu_page('tdeluxe', 'Deluxe Slider', 'Deluxe Slider', 'administrator', 'deluxe_slider', 'deluxe_slider');
		add_submenu_page('tdeluxe', 'Deluxe Home', 'Deluxe Home', 'administrator', 'deluxe_home', 'deluxe_home');
		add_submenu_page('tdeluxe', 'Deluxe Footer', 'Deluxe Footer', 'administrator', 'deluxe_footer', 'deluxe_footer');
		add_submenu_page('tdeluxe', 'Deluxe Contact', 'Deluxe Contact', 'administrator', 'deluxe_contact', 'deluxe_contact');
		add_submenu_page('tdeluxe', 'Deluxe Moreover', 'Deluxe Moreover', 'administrator', 'deluxe_moreover', 'deluxe_moreover');
		
	}
	
	function my_admin_scripts(){
		wp_enqueue_script('media-upload');
		wp_enqueue_script('jquery-ui-sortable');
		wp_enqueue_script('thickbox');
		wp_enqueue_script('mini', get_bloginfo('template_url').'/js/mini.js');
	}
	
	function my_admin_styles(){
		wp_enqueue_style('thickbox');
		wp_enqueue_style('global');
		wp_enqueue_style('wp-admin');
	}
	
	add_action('admin_print_styles', 'my_admin_styles');
	add_action('admin_print_scripts', 'my_admin_scripts');
	
	function deluxe_slider(){
		include_once( TEMPLATEPATH."/options/deluxe_slider.php");
	}
	
	function deluxe_home(){
		include_once( TEMPLATEPATH."/options/deluxe_home.php");
	}

	function deluxe_footer(){
		include_once( TEMPLATEPATH."/options/deluxe_footer.php");
	}
	
	function deluxe_moreover(){
		include_once( TEMPLATEPATH."/options/deluxe_moreover.php");
	}
	
	function deluxe_contact(){
		include_once( TEMPLATEPATH."/options/deluxe_contact.php");
	}
	
	function deluxe_settings(){
		include_once( TEMPLATEPATH."/options/deluxe_settings.php");
	}
	
	function custom_comments($comment, $args, $depth) {
		$GLOBALS['comment'] = $comment;
        $GLOBALS['comment_depth'] = $depth;
	?>
        <li>
			<div class="portfolio_box">
				<div class="portfolio_image">
					<div class="inside_border">
						<div class="portfolio_box_anime">
							<?php $avatar_email = get_comment_author_email(); echo get_avatar( $avatar_email, 80 ); ?>
						</div>
					</div>
				</div>
			
				<div class="comment_box">
					<div class="comment_border">
						<div class="comment_container">
							<strong style="font-size:15px;"><?php echo get_comment_author_link(); ?></strong>
							<span style="font-size:10px;">(<?php echo get_comment_date(); ?>)</span><br/>
							<?php comment_text() ?>
							<?php if ($comment->comment_approved == '0') _e("\t\t\t\t\t<span class='unapproved' style='font-size:11px; color:#adadad;'><i>".get_option('cf_awaiting', 'Your comment is awaiting moderation.')."</i></span>\n", 'your-theme') ?>
						</div>
					</div>
				</div>
			</div>
<?php } ?>