// Loads up the various functions we are going to use
$(document).ready(function(){
	jsEnabled();
	lastLi();
	navLi();
	imgLeft();
	imgRight();
	tabsLinks();
	headerCollapse();
	tabsPages();
	allBlogs();
});

// Adds a class to the body so I can style differently depending on whether Javascript is enabled.
function jsEnabled() {
	$("body").addClass("jsenabled");	
}
function lastLi() {
	$("ul li:last-child").addClass("lastLi");	
}
function navLi() {
	$("#nav li span").wrap("<span><span><span></span></span></span>");
}
function imgLeft() {
	$("img[align=left]").addClass("imgLeft");	
}
function imgRight() {
	$("img[align=right]").addClass("imgRight");	
}
function tabsLinks() {
	$("#sidebarTabs").prepend('<div id="tabsList"></div>');
	$("#sidebarTabs h2").each(function(i){
		$(this).remove();
		$(this).appendTo("#tabsList");
	});	
	$("#sidebarTabs h2").css({cursor:"pointer"});
}
function allBlogs() {
	$("#allBlogs>li").addClass('allBlogsClosed');
	
//	$("#allBlogs>li h3 a.blogUrl").each(function(i){
//		var str = $(this).text()
//		$(this).parent().append('<em></em>').html(str);
//  });

	$("#allBlogs>li h3 a.blogUrl").each(function(i){
		$(this).clone(true).insertAfter(this);
		$("#allBlogs>li h3 a.blogUrl + a.blogUrl").addClass('fakeUrl');
		$("#allBlogs>li h3 a.fakeUrl").removeClass('blogUrl');
	});

	
	$("#allBlogs .allBlogsClosed a.fakeUrl").click(function(){
    $("#allBlogs>li").removeClass('allBlogsOpen');
    $("#allBlogs>li").addClass('allBlogsClosed');
		$(this).parent().parent().removeClass('allBlogsClosed');
		$(this).parent().parent().addClass('allBlogsOpen');
		return false;
	});	
}


function headerCollapse() {
	$("#blogHeader").append('<a class="headerCollapse" href="#"><span>&nbsp;</span><em>&nbsp;</em></a>');	
	$(".headerCollapse span").click(function(){
		$("#blogHeader").animate({
			height: "223px"
		}, 500 );
		$("#blogHeaderOverlay").animate({
			width: "100%"
		}, 500 );
		$(".blogText #sidebar").animate({
			top: "0"
		}, 500 );
		$(".ccInfo").css({display: "block"});
		$(".headerCollapse span").css({display: "none"});
		$(".headerCollapse em").css({display: "block"});
	});
	$(".headerCollapse em").click(function(){
		$("#blogHeader").animate({
			height: "129px"
		}, 500 );
		$("#blogHeaderOverlay").animate({
			width: "1100px"
		}, 500 );
		$(".blogText #sidebar").animate({
			top: "20px"
		}, 500 );
		$(".ccInfo").css({display: "none"});
		$(".headerCollapse span").css({display: "block"});
		$(".headerCollapse em").css({display: "none"});
	});
}


function tabsPages(){
	$("#sidebarTabs h2").append('<div class="inner"></div>');
	$("#sidebarTabs h2:first-child").addClass('activeTab');
	$("#sidebarTabs>ul").append('<div class="inner"></div>');
	$("#sidebarTabs>ul>li").css({display: "none"});
	$("#sidebarTabs>ul>li:first-child").css({display: "block"});
	
	$("#tabsList h2:first-child").click(function(){
		$("#sidebarTabs h2").removeClass('activeTab');
		$(this).addClass('activeTab');
		$("#sidebarTabs>ul>li").css({display: "none"});
		$("#sidebarTabs>ul>li:first-child").css({display: "block"});
	})
	$("#tabsList h2:first-child + h2").click(function(){
		$("#sidebarTabs h2").removeClass('activeTab');
		$(this).addClass('activeTab');
		$("#sidebarTabs>ul>li").css({display: "none"});
		$("#sidebarTabs>ul>li:first-child + li").css({display: "block"});
	})
	$("#tabsList h2:first-child + h2 + h2").click(function(){
		$("#sidebarTabs h2").removeClass('activeTab');
		$(this).addClass('activeTab');
		$("#sidebarTabs>ul>li").css({display: "none"});
		$("#sidebarTabs>ul>li:first-child + li + li").css({display: "block"});
	})
	$("#tabsList h2:first-child + h2 + h2 + h2").click(function(){
		$("#sidebarTabs h2").removeClass('activeTab');
		$(this).addClass('activeTab');
		$("#sidebarTabs>ul>li").css({display: "none"});
		$("#sidebarTabs>ul>li:first-child + li + li + li").css({display: "block"});
	})
	$("#tabsList h2:first-child + h2 + h2 + h2 + h2").click(function(){
		$("#sidebarTabs h2").removeClass('activeTab');
		$(this).addClass('activeTab');
		$("#sidebarTabs>ul>li").css({display: "none"});
		$("#sidebarTabs>ul>li:first-child + li + li + li + li").css({display: "block"});
	})
}


