

jQuery(document).ready(function() {
	var location = window.location.href;
	var loc = location.indexOf('#');
	if (loc != -1) {
		var href = location.substring(0,loc);
		var hash = location.substring(loc + 1);
		console.info(href);
		if (hash == 'blog') console.info(hash);

	}
	
	jQuery("#list > li").each(function(i) {
		jQuery(this).addClass("heading-" + i + " item").attr("itemColor",jQuery(this).css("background-color"));
	});
	
	var listDom = jQuery("#list");
	var blogDom = jQuery("#blog").appendTo("<div id='tempBlog'>");
	jQuery("#list").accordion({
		autoHeight:false,
		header:".section-title",
		animated:"easeslide",
		alwaysOpen:false,
		active:-1
	}).bind("click.accordion", function(){
		runAccordionChange();
	});
	if(jQuery.browser.msie) jQuery("#list").accordion("activate",-1);

	function runAccordionChange() {
		jQuery(".showHide").hide();
		jQuery(".selected").children("a").removeClass("ui-state-hover").find(".showHide").show();
	}
	
	jQuery(".headerLinkBlog").click(function(){
		// jQuery(this).unbind();
		blogDom.appendTo("body");
		jQuery("#list, #blog, .headerBar").animate({left:"-=100%"}, 200, function(){listDom.appendTo("<div id='tempList'>");});
		// jQuery(".headerBar").animate({left:"-=100%"}, 300);
		
	});

	jQuery(".headerLinkProjects").click(function(){
		listDom.appendTo("body");
		jQuery("#list, #blog, .headerBar").animate({left:"+=100%"}, 200, function(){blogDom.appendTo("<div id='tempBlog'>");});
		// jQuery(".headerBar").animate({left:"+=100%"}, 300);
	});

	selectFilter("projectFilter", "blog", "news", "select projects", "{ unselect projects }");
	selectFilter("blogFilter", "news", "project", "select blog posts", "{ unselect blog posts }");
	selectFilter("newsFilter", "blog", "project", "select news", "{ unselect news }");

	function selectFilter(sel, nonA, nonB, string1, string2) {
		jQuery("#" + sel).click(function() {
			if(jQuery("#" + sel).html() == string1) {
				clearFilters();
				jQuery("#list").accordion("activate",-1);
				runAccordionChange();
				
				jQuery(".post-" + nonA + ", .post-" + nonB).addClass("filterOut");
//				jQuery("." + nonA + " > a > div, ." + nonB + " > a > div").addClass("smallFont");
				jQuery(".title-" + nonA + ", .title-" + nonB).addClass("smallFont");
//				jQuery(".smallFont").animate({fontSize:"24px"},700);
				jQuery(".typeBox-" + nonA + ", .typeBox-" + nonB).addClass("typeBoxInactive");
//				jQuery("." + nonA + " > a > p, ." + nonB + " > a > p").addClass("typeBoxInactive");
				
				jQuery("#" + sel).html(string2);
			}
			else {
				clearFilters();
			}
		});
	}
	function clearFilters() {
		jQuery(".filterOut").removeClass("filterOut");
//		jQuery(".smallFont").animate({fontSize:""},400);
		jQuery(".smallFont").removeClass("smallFont");
		jQuery(".typeBoxInactive").removeClass("typeBoxInactive");
		jQuery("#blogFilter").html("select blog posts");
		jQuery("#projectFilter").html("select projects");
		jQuery("#newsFilter").html("select news");
	}


	jQuery("#list > li > a").hover(function() {
		if(jQuery(this).parent().hasClass("selected")) jQuery(this).removeClass("ui-state-hover");
		else jQuery(this).find(".showHide").show();

	}, function() {
		if(!jQuery(this).parent().hasClass("selected")) jQuery(this).find(".showHide").hide();
	});
	
	
});


