$(document).ready(function(){ 
	$('a[href^="http://"]').attr("target", "_blank");
	
	$('#categories div.accordion h3').each(function(i, item) { $(this).addClass('head-' + i); });
	$('#categories div.accordion div').each(function(i, item) { $(this).addClass('content-' + i); });
	$("div.accordion").accordion({
			autoHeight: false,
			active: false,
    		collapsible: true,
			change: function(event, ui) {
				var x=$("h3.ui-state-active");
				if(x.length>0) $.scrollTo(x,500);
			}
	});
	//	YOY Code
	$("p").hide();
	$('#nav').hide();
	var doAnimate = function(target,index){
		if(target.is(':visible')) return;
		var current=$("#wrapper>div:visible");
		$("p")[(target.attr("id")=="home")?"hide":"show"]();
		$('#nav')[(target.attr("id")=="home")?"hide":"show"]();
		$('#sponsor')[(target.attr("id")!="home")?"hide":"show"]();
		current.animate({
			"marginLeft":-1000
		},500,function(){
				current.css("margin-left",0).hide().appendTo($("#wrapper"));
		});
		target.appendTo($("#wrapper")).css("marginLeft","1000px").show().animate({
			"marginLeft":0
		},500,function(){
			$("body")[(index==1||index==4||index==5||index==6)?"addClass":"removeClass"]("pattern");
		});

	};
	var bindMenu = function(i){
		var map=["about","categories","news","entries","theme","letter"];
		$(this).click(function(){
			$('#nav a').removeClass("active");
			$('#nav a:eq('+i+')').addClass("active");
			doAnimate($("#"+map[i]),i+1);
			return false;
		});
	};
	$("#home-nav a").each(bindMenu);
	$("#nav a").each(bindMenu);
	$("#footer p a, h1 a").click(function(){
		doAnimate($("#home"),0);
	});
	$('a.close-banner').click(function() { 
		$('#banner').slideUp();
	});
});


