/**
	Burned Media.
	JavaScript.
	Pat Collins <pat@burned.com>
*/

var defaultSectionIndex = 0;
var defaultProjectIndex = 0;

$(document).ready(function(){
	//
	// Page Sections.
	//
	$("a.section").click(function(){
		var id = $(this).parent().parent().get(0).id;
		if(id != getActiveSectionID()) {
			$("a.section").removeClass("active");
			$(this).addClass("active");
			$(".stretcher").hide().filter(function(){ return $(this).parent().parent().get(0).id==id; }).slideDown(300);
		}
		this.blur();
	});
	$("a.section").eq(defaultSectionIndex).addClass("active");
	$(".stretcher").hide().eq(defaultSectionIndex).show();
	
	
	//
	// Portfolio Pieces.
	//
	$("#well-done div.primary a").click(function(){
		var id = this.id.split('-switch')[0];
		if(id != getActivePortfolioID()) {
			$("#well-done div.primary a").removeClass("active");
			$(this).addClass("active");
			$("#well-done div.secondary").children().hide().filter('#'+id).slideDown(200);
		}
		this.blur();
	});
	$("#well-done div.primary a").eq(defaultProjectIndex).addClass("active");
	$("#well-done div.secondary").children().hide().eq(defaultProjectIndex).show();
	
	
	//
	// Parsing the location hash for Page Sections.
	//
	$("a.section").each(function(){
		var id = $(this).parent().parent().get(0).id;
		if(window.location.href.indexOf(id) > 0) {
			$("a.section").removeClass("active");
			$(this).addClass("active");
			$(".stretcher").hide().filter(function(){ return $(this).parent().parent().get(0).id==id; }).show();
		}
	});
	
});

function getActiveSectionID() {
	return $("a.section.active").parent().parent().get(0).id;
}

function getActivePortfolioID() {
	return $("#well-done div.primary a.active").get(0).id.split('-switch')[0];
}