jQuery(function($) {

	var $tabs = $('#tabs');

	if ($tabs.length != null) {

		var $h2 = $tabs.find('h2');
		$tabs.prepend('<ul id="tab_menu"></ul>');
		var $tab_menu = $tabs.find('#tab_menu');

		if ($h2.length != null) {

			var $tabs_w = $tabs.width()*1;
			var $w = $tabs_w/$h2.length-10;

			$h2.each(function(i){
				var $this = $(this);
				var $text = $(this).text();
				var curr = i;
				var $selected = curr < 1 ? ' class="selected"' : '';

				$tab_menu
					.append('<li' + $selected + '>'+
						 	'<a href="#'+curr+'" id="tab_menu_item_'+curr+'" '+
						 	'style="width:'+$w+'px">' +
						 	$text +
						 	'</a></li>');

				$tab_menu
					.find('#tab_menu_item_'+curr)
					.click(function(){

						$tab_menu
							.find('li.selected')
							.removeClass('selected');

						$(this)
							.parent('li')
							.addClass('selected');

						$tabs
							.find('.text')
							.hide();

						$h2.eq(curr)
							.nextAll()
							.each(function(){
								var $this = $(this);
								$this.show();
								if ($this.next().is('h2')) return true;
							});

				});

				$h2.eq(0)
					.nextAll()
					.each(function(){
						var $this = $(this);
						$this.show();
						if ($this.next().is('h2')) return true;
					});
			});
		}
		$tabs
			.find('#cur_project_item')
			.parent('li')
			.remove();
	}

	$('h1.card').next().each(function(i){
		 $(this).css('margin-left','-159px');
	})

	$('#lang_toggle').click(function(){
		$('.lang_nav').toggle();

		if(!$('.lang_nav').is(':hidden')){
			window.setTimeout("$('.lang_nav').toggle()", 5000);
		}
		return false;
	});

});