$(document).ready(function(){

        $("#tabs").tabs();

	if (window.location.hash == "#1") $("#tabs").tabs('select', 0); // switch to tab 1
	if (window.location.hash == "#2") $("#tabs").tabs('select', 1); // switch to tab 2
	if (window.location.hash == "#3") $("#tabs").tabs('select', 2); // switch to tab 3
	if (window.location.hash == "#4") $("#tabs").tabs('select', 3); // switch to tab 4
	if (window.location.hash == "#5") $("#tabs").tabs('select', 4); // switch to tab 5
	if (window.location.hash == "#6") $("#tabs").tabs('select', 5); // switch to tab 6

	$('.tabs1init').live("click",function() { // bind click event to link
		$("#tabs").tabs('select', 0);
		return false;
	});

	$('.tabs2init').live("click",function() { // bind click event to link
		$("#tabs").tabs('select', 1);
		return false;
	});

	$('.tabs3init').live("click",function() { // bind click event to link
		$("#tabs").tabs('select', 2);
		return false;
	});

	$('.tabs4init').live("click",function() { // bind click event to link
		$("#tabs").tabs('select', 3);
		return false;
	});

	$('.tabs5init').live("click",function() { // bind click event to link
		$("#tabs").tabs('select', 4);
		return false;
	});

	$('.tabs6init').live("click",function() { // bind click event to link
		$("#tabs").tabs('select', 5);
		return false;
	});
	
	$("button").button();
	
	$(".nojs").hide();

        $("a[rel=pc_group]").fancybox({
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'titlePosition'     : 'over',
            'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
                return '<span id="fancybox-title-over">Bild ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
            }
        });

	$.getJSON("papers.php", function(json) {
	
		var items = '<div id="accordion">';
		var i = 0;
		$.each(json, function(key, val) {
			i = i+1;
			items = items + '<div class="accheader"><a href="#section'+i+'">' + GA_LANG[key] + '</a></div>';
			items = items + '<div><ul id="ajaxcontent">';
			$.each(val, function(year, content) {
                            if (year != 0) {
				items = items + '<li>' + year + '</li>';
                            }
				items = items + '<ul>';
				//year = year.replace(':','');
				$.each(content, function(key2, pub) {
					items = items + '<li>' + pub + '</li>';
				});
				items = items + '</ul>';
			});
			items = items + '</ul></div>';
		});
		
		items = items + '</div>';
		//alert(items);
		$( "#pubajax" ).html(items);
		$( "#accordion" ).accordion({ collapsible: true, active: false, autoHeight: false, header: 'div.accheader' });
		// $( "#accordion" ).accordion( "activate" , false );
	
	});
	
});
