$().ready(function(){	
	
	//============================================================
	// 	FACEBOX INIT
	//============================================================
	//$('a[rel*=facebox]').facebox();
		
		
	//============================================================
	// 	HIDE/SHOW RIGHTRAIL
	//============================================================
	//pull rightrail image out if we don't have one
	if ( $("#Rightrail").length != 0 )
	{
		$("#InnerContentRight").css('background','url(/images/template/bg_container_right.jpg) no-repeat');
	}
	
	//============================================================
	// 	MOVE WHITE BAR BEHIND LINK DEPENDING ON SIZE
	//============================================================
	if ( $(".on").height() > 20 )
	{
		$(".on").css('backgroundPosition','0px 9px');
	}
	
	//============================================================
	// 	LEFTRAIL SHOW/HIDE MAIN MENU
	//============================================================
	if ( $("#default_menu_position").length > 0 )
	{
		default_menu_pos = $("#default_menu_position").html();
		if ( default_menu_pos == 'hide' )
		{
			$("#default_menu").hide();
		}
		else if ( default_menu_pos == 'above' )
		{
			$("#custom_menu").prepend($("#default_menu"));
		}
	}
	
	//remove menu if it is empty
	if ( $("#default_menu").find('ul').length == 0 )
	{
		$("#default_menu").hide();
	}
	
	//============================================================
	// 	SEE IF PAGE IS EMPTY
	//============================================================
	empty = 1;
	if ( $(".editor_content").length > 0 )
	{
		$(".editor_content").each(function(){
			if ( jQuery.trim($(this).html()) != '' )
			{
				empty = 0;
			}
		})
		
		if ( $(".editor_content:first").siblings().length > 0 )
		{
			empty = 0;
		}
	}
	else
	{
		empty = 0;
	}
	
	if ( empty == 1 )
	{
		$("#containerMiddleFull").html("<h2>"+$("#page_title_holder").html()+"</h2><ul>");
		$("#default_menu").find("a").each(function(){
			$("#containerMiddleFull").append("<li><a href='"+$(this).attr('href')+"'>"+$(this).html()+"</a><br>");
		})
		$("#containerMiddleFull").append("</ul>");
	}	
	
	//============================================================
	// 	TOP PAGE LINKS
	//============================================================
	$("#bookmarkPage").jFav();
	$("#printPage").click(function(){window.print()});
	$("#textLarger").click(function(){$(".editor_content p font,.editor_content p span, .editor_content p a").css('font-size','120%')})
	$("#textSmaller").click(function(){$(".editor_content p *").css('font-size','100%')})
	
	//============================================================
	// 	TABS
	//============================================================
	if ( $(".page_tab").length > 0 )
	{
		$("#page_tab_1").before("<div id='page_tabs_container'><ul id='page_tabs'></ul></div>");
		var tab_titles = new Array();
		$(".page_tab").each(function(){
			tab_id = $(this).attr('id').replace('page_tab_','');
			$("#page_tabs").append("<li id='section_link_"+tab_id+"' class='tab_container'><div class='tab_left_back'></div><div class='tab_rpt'><a href='javascript:;' class='tab_link' id='tab_link_"+tab_id+"'>"+$("#tab_title_"+tab_id).html()+"</a></div><div class='tab_right_back'></li>");
		})
		
		$('.page_tab').hide();
		
		$(".tab_link").click(function(){
			tab_id = $(this).attr('id').replace('tab_link_','');
			$(".page_tab").hide();
			$("#page_tab_"+tab_id).show();
			$(".tab_container").children().removeClass('active');
			$(this).parents('.tab_container').children().addClass('active');
		})
		
		if ( tab_to_click != '' )
		{
			$("#tab_link_"+tab_to_click).click();
		}
		else
		{
			$("#tab_link_1").click();
		}	
	}
	
	//============================================================
	// 	PARAGRAPH WITH SIDEBAR FILLING WITH EVENTS
	//============================================================
	if ( $(".manual_calendar").length > 0 )
	{
		if ($(".paragraph_with_sidebar_right").length > 0 )
		{
			var sidebar = $(".paragraph_with_sidebar_right .editor_content");
			var count = 0;
			$(".manual_calendar .event").each(function(){
				if ( count < 4 )
				{
					sidebar.append('<h3>'+$(this).find('.month').html()+' '+$(this).find('.date').html()+'</h3>');
					sidebar.append('<div style="line-height: 1.2em">'+$(this).find('.title').html()+'<div style="font-size: 80%; color: #999; padding: 3px 5px; margin-bottom: 10px">'+$(this).find('.time').html()+'<br>'+$(this).find('.place').html()+'</div></div>');
					count++;
				}
			})
			if(sidebar.html() != '' )
			{
				sidebar.prepend('<h3 style="color: #013E7F; margin-bottom: 10px">Events</h3>');
			}
		}
	}
	
	if ( $(".paragraph_with_sidebar_right .editor_content").html() == '' )
	{
		$(".paragraph_with_sidebar_right .editor_content").hide();
	}	
});

