$(document).ready( function(){
	$('html').removeClass('js');
	$(".click-menu").next().hide();
	$(".tabbed-content .hide-if-js").hide();
	
	$(".click-menu").each( function(){
		list = $(this).next();
		list.css("padding-bottom" ,  0 );
		list.css("height" ,  (16 * list.find('li').length) +10 );
	});
	$(".click-menu").click( function(){
		
		state = $(this).next().css("display");
		
		if( state == "block" ){
			$(this).next().hide();
			return false;
		}
		else{
			$(".click-menu").next().each( function(){
				if( $(this).css("display") == "block" ){
					$(this).hide();
				};
			});
			if( $(this).parent().find('ul').length ){
				$(this).next().show();
				return false;
			}
		}
	});
	
	var counter = 1;
	$(".tabbed-content .tab").each( function(){
		
		// Add a class to move the header text off page
		// Add a specific class to display the proper tab graphic
		temp = $(this).find(".header");
		temp.addClass("css-sprite");
		temp.addClass("tab"+counter);
		temp.addClass("tab_"+$(".tabbed-content .tab").length+'_'+counter);		

		counter++;
	});
	
	var counter = 1;
	$(".tabbed-content .tab").each( function(){
		
		//Add the navigation elements for each tab
		//uses the text contained in the .header
		temp = $(this);
		switch( counter ){
			case 1:
				temp.append("<ul class='navigation s'><li><strong>"+$(".tabbed-content .tab .tab1").text()+"</strong></li><li><a class='change2' href='#'>"+$(".tabbed-content .tab .tab2").text()+"</a></li><li><a class='change3' href='#'>"+$(".tabbed-content .tab .tab3").text()+"</a></li></ul>");
				break;
			case 2:
				temp.append("<ul class='navigation s'><li><a class='change1' href='#'>"+$(".tabbed-content .tab .tab1").text()+"</a></li><li><strong>"+$(".tabbed-content .tab .tab2").text()+"</strong></li><li><a class='change3' href='#'>"+$(".tabbed-content .tab .tab3").text()+"</a></li></ul>");
				break;
			case 3:
				temp.append("<ul class='navigation s'><li><a class='change1' href='#'>"+$(".tabbed-content .tab .tab1").text()+"</li><li><a class='change2' href='#'>"+$(".tabbed-content .tab .tab2").text()+"</a></li><li><strong>"+$(".tabbed-content .tab .tab3").text()+"</strong></li></ul>");
				break;
		}
		counter++;
	});

	$(".tabbed-content .navigation a").click( function(){
		switch( $(this).attr("class") ){
			case "change1":
				$("#tab-id2").hide();
				$("#tab-id3").hide();
				$("#tab-id1").show();
				break;
			case "change2":
				$("#tab-id1").hide();
				$("#tab-id3").hide();
				$("#tab-id2").show();
				break;
			case "change3":
				$("#tab-id1").hide();
				$("#tab-id2").hide();
				$("#tab-id3").show();
				break;	
		}
		return false;
	});

});