
 	function list_all_blogs() {
	
											$.post('/page_includes/link_page.php', { 
												ID							: 'page_select', 
												LinkToID				: '12', 
												LinkOnPageID		: 0, 
												LinkText				: 'List All', 
												TreeCategoryID	: 0, 
												ItemClicked			: 'List All Button', 
												Referer					:	Referer
												}, function(data){
												
									where_to = $.trim(data)
									where_to_split = where_to.split('|')
					
									
									var where_to_go = where_to_split[0].replace('<div style="display:none">', '');
									document.location = where_to_go
							});
	}
	
	
function clean_blog() {
	 $('p').each(function() {
	 	if (($(this).html() == '&nbsp;') || ($(this).html() == '')) {
			$(this).remove()
		}
	 })
	 
	 
}
function prev_blog() {
		
	whats_loaded = parseInt($('body').data('BlogLoad'))
	max_loaded = parseInt($('body').data('BlogLoadMax'))

	$('#NextBlogButton').removeClass('dim').find('.button_text').removeClass('dim')
	$('#NextBlogButton').removeClass('dim').find('.arrow_right').removeClass('dim')

	if (whats_loaded != max_loaded) {
		$('#PrevBlogButton').removeClass('dim').find('.button_text').removeClass('dim')
		$('#PrevBlogButton').removeClass('dim').find('.arrow_right').removeClass('dim')
	} else {
		$('#PrevBlogButton').addClass('dim').find('.button_text').addClass('dim')
		$('#PrevBlogButton').addClass('dim').find('.arrow_right').addClass('dim')
	}
	
	load_next_blog = whats_loaded + 1


	if (load_next_blog != max_loaded) {
		get_blog(load_next_blog)
		$('body').data('BlogLoad', load_next_blog)

	} else {
		get_blog(load_next_blog)
		$('body').data('BlogLoad', load_next_blog)

	}

}
function next_blog() {
	whats_loaded = parseInt($('body').data('BlogLoad'))
	max_loaded = parseInt($('body').data('BlogLoadMax'))

	if (whats_loaded != 0) {
		$('#NextBlogButton').removeClass('dim').find('.button_text').removeClass('dim')
		$('#NextBlogButton').removeClass('dim').find('.arrow_right').removeClass('dim')

		load_next_blog = whats_loaded - 1

			get_blog(load_next_blog)
			$('body').data('BlogLoad', load_next_blog)
	
	} else {

		$('#NextBlogButton').addClass('dim').find('.button_text').addClass('dim')
		$('#NextBlogButton').addClass('dim').find('.arrow_right').addClass('dim')
	}
	if (load_next_blog == 0) {
		$('#NextBlogButton').addClass('dim').find('.button_text').addClass('dim')
		$('#NextBlogButton').addClass('dim').find('.arrow_right').addClass('dim')
	}
	if (whats_loaded != max_loaded) {
		$('#PrevBlogButton').removeClass('dim').find('.button_text').removeClass('dim')
		$('#PrevBlogButton').removeClass('dim').find('.arrow_right').removeClass('dim')
	} else {
		$('#PrevBlogButton').addClass('dim').find('.button_text').addClass('dim')
		$('#PrevBlogButton').addClass('dim').find('.arrow_right').addClass('dim')
	}
}

			function load_specific_page_function() {

					$('body').data('BlogLoad', 0)

						// ADDITIONAL  MODULE OPTIONS
						$("[id^='ModuleBoxContent_'], [id^='RightContainer']").each(function() {
							this_content_location = $(this).attr('content_location')
							this_id = $(this).attr('id')
							
							content_location_div_load = $(this).attr('load_from')
							if (this_content_location != '') {
								if (content_location_div_load == '') {
									build_load = 'Modules/'+this_content_location
								} else {
									build_load = 'ModuleInserts/'+this_content_location+' #'+content_location_div_load
								}
								$(this).load(build_load, function() {
									$(this).show()
									after_each_mod_load()

								})	
							}
						}) 
							 
						$('.left_box_footer').each(function() {
							this_content_location = $(this).attr('content_location')
							this_id = $(this).attr('id')

							content_location_div_load = $(this).attr('load_from')
							if ((this_content_location != '') && (this_content_location != undefined) ) {
								if (content_location_div_load == '') {
									build_load = 'Modules/'+this_content_location
								} else {
									build_load = 'Modules/'+this_content_location+' '+content_location_div_load
								}
								$(this).load(build_load, function() {
											$('#LeftContainer_2').find('.make_button').make_my_button();
											$('#NextBlogButton').addClass('dim').find('.button_text').addClass('dim')
											$('#NextBlogButton').addClass('dim').find('.arrow_right').addClass('dim')
								})	
							}
						}) 

						after_mod_load_global() // GLOBAL - ADDS MODULE BUTTON TO TOP AND FONTS
						check_mod_load() // GLOBAL - CALLS after_mod_load() ON page_functions_tree.js		- SETS COLUMNS BASED ON USER SETTINGS
						
			
					 	get_first_blog(1)

			}
			
	function get_blog(which_blog_counter) {
			this_blog = blog_array[which_blog_counter];
			blog_location_split = this_blog.split('|');
			this_comment_count = blog_location_split[1];
			blog_location = blog_location_split[0];
			build_load = 'ModuleInserts/blogs/'+blog_location+'.html #HomePage'

			$('#BlogContent').load(build_load, function() {
		
				$(this).find('#ItemExtras').hide()
				format_blog_for_page($(this))
				
											if (this_comment_count != 0) {
												$('#ViewComments').html('view all comments ('+comment_count+')').attr('file_location', blog_location)
											} else {
												$('#ViewComments').html('no comments to view').attr('file_location', blog_location).removeClass('left_box_link')
											}
			})	

	}

function get_first_blog(which_blog_counter) {
		a = $('#LeftContainer').width()
		$('#LeftContainer_2').width(a)
		$.getJSON("page_includes/blog_by_first.php", {'id' : which_blog_counter},  function(data) { 
								data_counter = 1
								this_blog_id = data.id
								file_location = data.file_location
								MaxHomePageHeight = data.MaxHomePageHeight
								
								comment_count = data.comment_count
	
														
									build_load = 'ModuleInserts/blogs/'+file_location+'.html #ModuleBoxTitle'
									$('#BlogTitle').find('.left_box_title').load(build_load, function() {
		

									})	
									build_load = 'ModuleInserts/blogs/'+file_location+'.html #HomePage'
									$('#BlogContent').load(build_load, function() {
										$(this).css({'padding':'0'}).parent().css({'margin':'0', 'padding':'0px 0px 0px'})
										$(this).find('#ItemExtras').hide()
										format_blog_for_page($(this))
									})	
						 
			}); // end json
						 
						 	
			$.get("page_includes/blog_list_all.php", function(data) { 
				blog_array = $.trim(data).split(',');
				$('body').data('BlogLoadMax', blog_array.length)
				//$('body').data('BlogLoadMax', data_counter)
	
		 
		 });

			
}		

function format_blog_for_page(this_blog) {

											// LOAD CONTENT
											$('#HiddenContent').remove()
											$('#BlogHeaderContent').remove()
											$('.full_item_insert').empty()
											$('#BlogHeader').empty()
											
											if (this_blog.find('.blog_toc_content').html() == 'null') {
												toc_box_w = $('#LeftContainer').width() - 96
												this_blog.find('.blog_toc_content').prev().remove()
												this_blog.find('.blog_toc_content').next().remove()
												this_blog.find('.blog_toc_content').remove()
											} 
											if (this_blog.find('.blog_toc_content').length > 0) {
												toc_box_w = this_blog.find('.blog_toc_content').width()
												this_blog.find('.slice_small_top, .slice_small_bot').width(toc_box_w)
												toc_box_w = toc_box_w - 24
												this_blog.find('.blog_toc_content').width(toc_box_w)
											} else {
												toc_box_w = $('#LeftContainer').width() - 96
												this_blog.find('.blog_toc_content').remove()
											}
											this_blog.find('.item_title_full_container').css({'padding':'10px'})
											$('.column_split').find('.table_of_content_header').remove()
											$('.column_split').find('.anchor_link').remove()
											this_blog.find('.column_layout').find('.table_of_content_anchors').remove()

											// FIX THE ANCHOR LINKS TO BE BROWN
											$('a').filter("[name!='']").css({'color':'#3B170C'}).addClass('anchor_inline')
											this_blog.find('.full_item_insert').hide()
											
							
											if ($(document).width() > 1200) {
												
												if (this_blog.find('#Column1').length != 0) {
													each_col_w = parseInt((toc_box_w - 50) / 2)
													this_blog.find('#Column1').width(each_col_w).attr('id', 'NewColumn1').css({'margin':'0 0 0 35px'})
													this_blog.find('#Column2').width(each_col_w).attr('id', 'NewColumn2').css({'margin':'0 0 0 35px'})
												} else {
													each_col_w = parseInt((toc_box_w - 0))
													this_blog.find('.column_split').width(each_col_w).css({'margin':'0 0 0 35px'})
												}

												a = $('.column_split').closest('.left_module').width() - 16
												$('.column_split').width(a)
												
											} else {
												if (this_blog.find('#Column1').length != 0) {
													each_col_w = parseInt((toc_box_w - 0))
													this_blog.find('#Column1').width(each_col_w).attr('id', 'NewColumn1').css({'margin':'0 0 0 35px'})
													this_blog.find('#Column2').width(each_col_w).attr('id', 'NewColumn2').css({'margin':'0  0 0 35px'})
												} else {
													each_col_w = (toc_box_w - 0) + 60
													this_blog.find('.column_split').width(each_col_w).css({'margin':'0 0 0 35px'})
												}
											}
	
											new_header_height = $('#BlogHeaderContent').height()
											

											blog_scroll_height = MaxHomePageHeight;
											$('#LeftContainer_2').attr('new_header_height', new_header_height).attr('blog_scroll_height',blog_scroll_height)
											blog_header_bg_height = $('.blog_header_bg').height()
											blog_scroll_height = blog_scroll_height - blog_header_bg_height ;
									
											blog_height = $('.column_split').height()

											if (blog_height > blog_scroll_height) {
												$('.column_split').height(blog_scroll_height)
												$('.column_split').scrollbar();
											}
											$('#LeftContainer_2').find('#Column2').css({'margin-right':'0px'})
											$('#LeftContainer_2').find('#BlogContent').css({'margin-bottom':'5px'})

											$('.permalink_word').next().html('PermaLink').show();
											$('.permalink_word').hide().prev().css({'margin-left':' 0'}).parent().css({'margin':'10px 0 0 0'})
	

											// CLICK FUNCTION - FOR: CLICKING ON ANCHOR LINKS ON TOP OF BLOG
											$(".anchor_link").bind("click", function(event) {
													event.preventDefault()
													event.stopImmediatePropagation(); 
													var this_href = $(this).attr('href');
													
													this_href = this_href.replace('#', "");
													this_link = $("[name='"+this_href+"']") ;
													this_link_o = this_link.offset()
													this_pane_o = $('#BlogContent').find('.pane').offset()
													scroll_amount = this_pane_o.top - this_link_o.top
												 	// alert(this_link_o.top + ' -  ' + this_pane_o.top)
												
												$('#BlogContent').find('.pane').css({'top':scroll_amount+'px'})
											//	$('#BlogContent').find('.pane').scrollTo(  { top:800, left:700},  800 );
											}); 
											if (comment_count != 0) {
												$('#ViewComments').html('view all comments ('+comment_count+')').attr('file_location', file_location)
											} else {
												$('#ViewComments').html('no comments to view').attr('file_location', file_location).removeClass('left_box_link')
											}

	align_footer_check()
											
											
}
	
	
	
	
	
	
// CLICK FUNCTION - FOR: VIEWING COMMENT  
$("[id='ViewComments']").live("click", function(event) {
		this_file_location = $(this).attr('file_location')
		document.location = 'blogs.php?BlogLocation='+this_file_location+'.php&ScrollToComment=1'
}); 
	
$("[id='ViewRSS']").live("click", function(event) {
		window.open('http://permablog.fpdcacd.org/rss.php')
		document.location = 'blogs.php?BlogLocation='+this_file_location+'.php'
}); 

	
$(".blog_title").live("mouseover mouseout", function(event) {
  if ( event.type == "mouseover" ) {
    $(this).addClass('hover')
  } else {
    $(this).removeClass('hover')
  }
});
$(".blog_title").live("click", function(event) {
	if ($(this).parent().parent().attr('file_location') != undefined) {
		this_file_location = $(this).parent().parent().attr('file_location')
		document.location = 'blogs.php?BlogLocation='+this_file_location+'.php'
	}
}); 
