/**
 *  Wordpress blog specific js for Finelight HTML site
 *  @author rgollapudi
 */
$(document).ready(function(){
	
	$('a.post_readmore').live('click', function(){  
        // first hide all other read more blog posts that might be open
        $('div.wp-post-fullentry').slideUp().empty().siblings('div.wp-post-entry').slideDown();
        $('a.post_close').removeClass('post_close').text('read more').addClass('post_readmore');
        var post_id = $(this).attr('post_id');
        var sibling_post_entry= $(this).siblings('div.wp-post-entry');
        var sibling_post_fullentry= $(this).siblings('div.wp-post-fullentry');
//        console.log('sending ajax request for the post with id: '+ post_id);
        $.get('/blog/ajax-wp-content/', {'request': 'post', 'post_id': post_id}, function(data) {
            sibling_post_entry.hide();
            if($.browser.msie && $.browser.version == '6.0'){
                sibling_post_fullentry.html(data).slideDown('slow').updateSidebar();
            }
            else{
                sibling_post_fullentry.html(data).slideDown('slow').log('done');
            }
        });
        $(this).text('close').addClass('post_close').removeClass('post_readmore');
        return false;
    });

    $('a.post_close').live('click', function() {
        var sibling_post_entry= $(this).siblings('div.wp-post-entry');
        var sibling_post_fullentry= $(this).siblings('div.wp-post-fullentry');
        sibling_post_fullentry.slideUp().empty();
        sibling_post_entry.slideDown('slow');
        $(this).removeClass('post_close').text('read more').addClass('post_readmore');
        return false;
    });

    /**
     *	Ajax get more posts
     */
    $('.getposts').click(function() {
        var offset = $('#content div.post').length;
            $.get('/blog/wp-get-posts/?offset=' + offset, function(data){
                if (data) {
                    $('div.navigation').before(data);
                }
                else {
                    $('div.navigation').html('No more posts left');
                    offset = 0;
                    //	console.log('no more posts left');
                }
            });
        return false;
    });
});
