<?php

// Using hooks is absolutely the smartest, most bulletproof way to implement things like plugins,
// custom design elements, and ads. You can add your hook calls below, and they should take the 
// following form:
// add_action('thesis_hook_name', 'function_name');
// The function you name above will run at the location of the specified hook. The example
// hook below demonstrates how you can insert Thesis' default recent posts widget above
// the content in Sidebar 1:
// add_action('thesis_hook_before_sidebar_1', 'thesis_widget_recent_posts');

// Delete this line, including the dashes to the left, and add your hooks in its place.

/**
 * function custom_bookmark_links() - outputs an HTML list of bookmarking links
 * NOTE: This only works when called from inside the WordPress loop!
 * SECOND NOTE: This is really just a sample function to show you how to use custom functions!
 *
 * @since 1.0
 * @global object $post
*/

function custom_bookmark_links() {
	global $post;
?>
<ul class="bookmark_links">
	<li><a rel="nofollow" href="http://delicious.com/save?url=<?php urlencode(the_permalink()); ?>&amp;title=<?php urlencode(the_title()); ?>" onclick="window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=<?php urlencode(the_permalink()); ?>&amp;title=<?php urlencode(the_title()); ?>', 'delicious', 'toolbar=no,width=550,height=550'); return false;" title="Bookmark this post on del.icio.us">Bookmark this article on Delicious</a></li>
</ul>
<?php
}


//  ===========================================================================
//		MOVING NAVIGATION INTO HEADER. INSERTING LOGO AND LINKING TO HOME PAGE

remove_action('thesis_hook_before_header', 'thesis_nav_menu');

function insert_hslogo() {
?>
<div id="hs-logo">
	<a href="<?php bloginfo('url'); ?>" target="_self" id="hs_logo"><img src="<?php echo THESIS_CUSTOM_FOLDER; ?>/images/hs_logo.png" alt="Logo for Heard and Smith" border="0"></a>
</div>

<?php thesis_nav_menu(); ?>

<?php
}

add_action('thesis_hook_after_title', 'insert_hslogo');

//  ===========================================================================
//		CREATING A WIDGETIZED MULTIMEDIA BOX

register_sidebar(array('name' => 'Multimedia Box', 'before_widget' => '<li class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3>', 'after_title' => '</h3>'));

function multimedia_box_widgets() {
	echo '<ul class="sidebar_list">';
	dynamic_sidebar('Multimedia Box');
	echo '</ul>';
}
add_action('thesis_hook_multimedia_box', 'multimedia_box_widgets');


//  ===========================================================================
//		CUSTOM FOOTER WIDGET CONTAINERS
//		Make some widgets for the footer

/* Top Row */

/* Top Row - Left */
register_sidebars(1,
    array(
        'name' => 'Top Row - Left',
        'before_widget' => '<li class="widget %2$s" id="%1$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);

/* Top Row - Left Center */
register_sidebars(1,
    array(
        'name' => 'Top Row - Left Center',
        'before_widget' => '<li class="widget %2$s" id="%1$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);

/* Top Row - Right Center */
register_sidebars(1,
    array(
        'name' => 'Top Row - Right Center',
        'before_widget' => '<li class="widget %2$s" id="%1$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);

/* Top Row - Right */
register_sidebars(1,
    array(
        'name' => 'Top Row - Right',
        'before_widget' => '<li class="widget %2$s" id="%1$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);

//  ===========================================================================
/*		Bottom Row */

/* Bottom Row - Left */
register_sidebars(1,
    array(
        'name' => 'Bottom Row - Left',
        'before_widget' => '<li class="widget %2$s" id="%1$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);

/* Bottom Row - Center */
register_sidebars(1,
    array(
        'name' => 'Bottom Row - Center',
        'before_widget' => '<li class="widget %2$s" id="%1$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);


/* Bottom Row - Right */
register_sidebars(1,
    array(
        'name' => 'Bottom Row - Right',
        'before_widget' => '<li class="widget %2$s" id="%1$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);

//  ===========================================================================
//		ADDITIONAL FOOTER FUNCTIONS
//		These are to allow widgets to control each space in the footer. They go from 1-4 from left to right

/* Footer 1 Function */
function footer_1() { ?>

<div id="footer_1" class="sidebar">
<ul class="sidebar_list">
<?php thesis_default_widget(4); ?>
</ul>
</div>

<?php }

/* Footer 2 Function */
function footer_2() { ?>

<div id="footer_2" class="sidebar">
<ul class="sidebar_list">
<?php thesis_default_widget(5); ?>
</ul>
</div>

<?php }

/* Footer 3 Function */
function footer_3() { ?>

<div id="footer_3" class="sidebar">
<ul class="sidebar_list">
<?php thesis_default_widget(6); ?>
</ul>
</div>

<?php }

/* Footer 4 Function */
function footer_4() { ?>

<div id="footer_4" class="sidebar">
<ul class="sidebar_list">
<?php thesis_default_widget(7); ?>
</ul>
</div>

<?php }

/* Footer 5 Function */
function footer_5() { ?>

<div id="footer_5" class="sidebar">
<ul class="sidebar_list">
<?php thesis_default_widget(8); ?>
</ul>
</div>

<?php }

/* Footer 6 Function */
function footer_6() { ?>

<div id="footer_6" class="sidebar">
<ul class="sidebar_list">
<?php thesis_default_widget(9); ?>
</ul>
</div>

<?php }

/* Footer 7 Function */
function footer_7() { ?>

<div id="footer_7" class="sidebar">
<ul class="sidebar_list">
<?php thesis_default_widget(10); ?>
</ul>
</div>

<?php }


//		Remove current footer

remove_action('thesis_hook_footer', 'thesis_attribution');

//		Setup new footer function

function add_custom_footer () { ?>

<div id="footer_main">
<div id="footer_top_row">
<div id="footer_top_left">
<?php footer_1(); ?>
</div>
<div id="footer_top_left_center">
<?php footer_2(); ?>
</div>
<div id="footer_top_right_center">
<?php footer_3(); ?>
</div>
<div id="footer_top_right">
<?php footer_4(); ?>
</div>
</div>
<div id="footer_bottom_row">
<div id="footer_bottom_left">
<?php footer_5(); ?>
</div>
<div id="footer_bottom_center">
<?php footer_6(); ?>
</div>
<div id="footer_bottom_right">
<?php footer_7(); ?>
</div>
</div>
</div>

<div id="footer_sub">
	<div id="footer-left">
		<p>&#169; <?php echo date("Y"); ?> <a href="http://howtogetsocialsecuritydisability.com/" title="Link to Living with a Disability's About Us Page">Living with a Disability</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://howtogetsocialsecuritydisability.com/">Privacy Policy Regarding Medical and Legal Advice</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="http://howtogetsocialsecuritydisability.com/">New Link</a></p>
	</div>
	<div id="footer-right">
		<p><a href="http://www.berchman.com" title="Link to Berchman.com">Coding by Berchman.com</a></p> 
	</div>
</div>

<?php }

//		Insert new footer

add_action('thesis_hook_footer', 'add_custom_footer');


// **************************************************************************
// SOCIAL ICONS BEFORE POSTS

function social_icons(){
  if(is_single()){
$twitter='disabilitymag';
	global $post;
?>
			<div class="social">
			
				<div class="social_button dg">
                	<a class="DiggThisButton"><img src="http://digg.com/img/diggThisCompact.png" height="18" width="120" alt="DiggThis" /></a>
                </div>
 
                <div class="social_button tm">
				<script type="text/javascript">	tweetmeme_source = '<?php echo $twitter; ?>';	tweetmeme_style = 'compact';	</script>				
				<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>
                </div>
 
                <div class="social_button fb">
                <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a>
                </div>
 
                <div class="social_button su">
<!-- Google Buzz -->
						<a title="Post on Google Buzz" class="google-buzz-button" href="http://www.google.com/buzz/post" data-button-style="small-button"></a>
						<script type="text/javascript" src="http://www.google.com/buzz/api/button.js"></script>

<!-- Hiding StumbleUpon button
                <a href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" id="stumbleupon" target="_blank"><img src="http://cdn.stumble-upon.com/images/badgeStumble.png" alt="submit to Stumble Upon"/>
                </a>
 -->

                </div>
                <div class="social_button em">
              <a href="mailto:?subject=Sharing: <?php the_title(); ?>&body=I wanted to share this with you. Thought you might enjoy it:%0A%0A<?php the_permalink(); ?>" title="Email This" target="_blank">Email This</a>
              </div>
			</div> 
			<div class="clear"></div>
			<?php 
 
			function digg_footer(){ 
				echo '<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>';
				echo '<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>';
					} 
			add_action('wp_footer','digg_footer');
   }
}
add_action('thesis_hook_before_post','social_icons');

//  ===========================================================================
//		CUSTOM HOME PAGE
//

function home_page_custom() {
if (is_home() || is_front_page())  {
?>

<div id="content">
<div class="post_box">
<!-- Smooth Slider -->

<?php if ( function_exists( 'get_smooth_slider' ) ) { get_smooth_slider(); } ?>


 

<!-- CUSTOM TEASER DISPLAY -->

<div id='teasers_wrapper'>

<?php
    $teaser_count = 1;

    $recent = new WP_Query('category_name=intro-posts&showposts=4');
    while($recent->have_posts()) : $recent->the_post();

        if (($teaser_count % 2) == 1) {
                $top = ($post_count == 1) ? ' top' : '';
                $open_box = "\t\t\t<div class=\"teasers_box$top\">\n\n";
                $close_box = '';
                $right = false;
        }
        else {
                $open_box = '';
                $close_box = "\t\t\t</div>\n\n";
                $right = true;
        }

        if ($open_box != '') {
                echo $open_box;
                thesis_hook_before_teasers_box($post_count);
        }

        thesis_teaser('teaser', false, $right);

        if ($close_box != '') {
                echo $close_box;
                thesis_hook_after_teasers_box($post_count);
        }

        $teaser_count++;

    endwhile;
    wp_reset_query();
?>	
</div>


<!-- Most Popular Posts -->

<div id="most_popular_posts">
<h3>Most Popular Posts</h3>
<?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=monthly&order_by=views&excerpt_format=0&excerpt_length=200&pattern_form='{title} {image}  {excerpt}'&wpp_start='<ul>'&wpp_end='</ul>'&pages=0&limit=8"); ?>
</div>


</div>
</div>
<div id="sidebars">
<?php thesis_build_sidebars(); ?>
</div>		

<?php } }

//  ..........................................................................
//		HOME PAGE IMPLEMENT

remove_action('thesis_hook_custom_template', 'thesis_custom_template_sample');
add_action('thesis_hook_custom_template', 'home_page_custom');


//  ===========================================================================
//		CUSTOM BLOG PAGE
//  ===========================================================================

function blog_custom() {
if (is_page('blog'))  {
?>
<div id="content">
<div id="sidebars-blog">
<?php thesis_build_sidebars(); ?>
</div>		

<?php thesis_loop_posts(); ?>
	

<!-- Most Popular Posts -->

<div id="most_popular_posts">
<h3>Most Popular Posts</h3>
<?php if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("range=monthly&order_by=views&excerpt_format=0&excerpt_length=200&thumbnail_width=30&pattern_form='{title} {image}  {summary}'&wpp_start='<ul>'&wpp_end='</ul>'&pages=0&limit=8"); ?>
</div>


</div>
</div>

<?php } }

//  ..........................................................................
//		CUSTOM BLOG PAGE IMPLEMENT

add_action('thesis_hook_custom_template', 'blog_custom');




/* 
function category_page_custom() {
if (is_category('intro-posts') ) {?>
	<div class="format_text entry-content">
	<p></p><h3>Upcomming lessons</h3></p><ul>

	<?php
	$my_query = new WP_Query('category_name=intro-posts&showposts=5');
	if ($my_query->have_posts()) {
		while ($my_query->have_posts()) : $my_query->the_post();
			$do_not_duplicate = $post->ID; ?>
			<li><?php the_title(); ?> (online on <?php the_time('d.m.Y'); ?>)</li>
		<?php endwhile;
	} ?> </ul></div> <?php 
} 

}
add_action('thesis_hook_archive_info', 'category_page_custom');
*/

//  ===========================================================================
//		CUSTOM CATEGORY PAGE
//

function category_page_custom() {
if (!is_category(3) || is_tag()){
?>

<div id="content">
<div class="post_box">

<!-- Special Category Row -->

<div id="special_category_listing">		
<ul id="special_category">
<p>Categories: <?php the_category(' '); ?></p>

<?php query_posts("showposts=15"); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
	<li>
		<a href="<?php the_permalink(); ?>" class="the_title"><?php the_title(); ?></a><br /><?php the_excerpt(); ?>
	</li>
<?php endwhile; ?>

<?php else : ?>			
	<li>There are presently no <em>posts</em> available in <?php the_category(); ?>.</li>			
<?php endif; ?>
</ul>
</div>
	


<!-- Most Recent Posts in category -->

<div id="most_recent_posts_category">
<h3>Most Recent Posts in <?php the_category(); ?></h3>

<?php if (function_exists('recent_comments')) recent_comments(); ?>
	<?php popular_posts(); ?>
</div>

</div>
</div>

<div id="sidebars">
<?php thesis_build_sidebars(); ?>
</div>		

<?php } }

//  ===========================================================================
//		CATEGORY PAGE IMPLEMENT

// remove_action('thesis_hook_archive_info', 'thesis_default_archive_info');
// add_action('thesis_hook_archive_info', 'category_page_custom');



function my_archives_template() {
?>
	<h3 class="top"><?php _e('By Month:', 'thesis'); ?></h3>
		<ul>
			<?php wp_get_archives('type=monthly&show_post_count=1'); ?>
		</ul>
	<h3><?php _e('By Category:', 'thesis'); ?></h3>
		
		<p>Hey Yo!</p>
		<ul>
			<?php wp_list_categories('title_li=0&show_count=1'); ?>
		</ul>
<?php
}

remove_action('thesis_hook_archives_template', 'thesis_archives_template');
add_action('thesis_hook_archives_template', 'my_archives_template');



//  ===========================================================================
//		CUSTOM AFTER THE POST BOX

function post_article_call() { 
if (is_single( )) { 

remove_action('thesis_hook_after_content', 'thesis_prev_next_posts');

?>
<div class="after_post_box">
	
<?php 

$random_widget = rand(11,14);
thesis_default_widget($random_widget);

?>
	
</div>

<div id="related_posts">
<?php related_posts(); ?>
</div>

<?php thesis_prev_next_posts(); ?>

<?php }}
add_action('thesis_hook_after_post', 'post_article_call');








//		=========================================================================
//		ATPB = AFTER THE POST BOX

//	ATPB - 01
register_sidebars(1,
    array(
        'name' => 'After the Post - 01',
        'before_widget' => '<div id="after_the_post_box">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);

//	ATPB - 02
register_sidebars(1,
    array(
        'name' => 'After the Post - 02',
        'before_widget' => '<div id="after_the_post_box">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);

//	ATPB - 03
register_sidebars(1,
    array(
        'name' => 'After the Post - 03',
        'before_widget' => '<div id="after_the_post_box">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);

//	ATPB - 04
register_sidebars(1,
    array(
        'name' => 'After the Post - 04',
        'before_widget' => '<div id="after_the_post_box">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    )
);



//	***************************************************************************
// This group of functions replaces the category archive page in Thesis
//	***************************************************************************
//	***************************************************************************
//	Replaces the category template with the custom template and tells 
//	Thesis to use it
//	***************************************************************************

add_action('template_redirect','ttwcat_category_archive_template_redirect');

function ttwcat_category_archive_template_redirect(){
    if (is_category()) {
        global $wp_query;
        add_post_meta($wp_query->post->ID,'_wp_page_template','custom_template.php',TRUE);
        $wp_query->is_page = true;
    }
}


//	***************************************************************************
//	Hooks the new category archive template to the thesis custom template hook
//	***************************************************************************

add_action('thesis_hook_before_html', 'ttwcat_category_archive');

function ttwcat_category_archive(){

    if (is_category()) {
        include_once TEMPLATEPATH . '/custom/custom_archive_template.php';
        add_action('thesis_hook_custom_template','ttwcat_custom_archive_template');
        }
}