$(document).ready(function() {
	$.ajaxSetup({ cache: false });
	$.getJSON('/popular.php', {'ca': '6', 'd': '3', 'cut': '75', 'suffix': '...'}, function(data) { fillPopular(data) });
	//$.getJSON('/papps/kongresskalender/json.php', {'days': '30', 'cut': '50', 'suffix': '...'}, function(data) { fillPopular(data) });
	$.getJSON('/papps/kongresskalender/json.php', {'days': '15', 'cut': '50', 'suffix': '...'}, function(data) { fillDates(data) });
});

$(document).ready(function() {
	$("#tabs-beliebt").hide();
	$('#tabs-termine-btn').click(function() {
		$("#tabs-termine").show();
		$("#tabs-beliebt").hide();
		$('#tabs-termine-btn').addClass('current');
		$('#tabs-beliebt-btn').removeClass('current');
		return false;
	});
	$('#tabs-beliebt-btn').click(function() {
		$("#tabs-termine").hide();
		$("#tabs-beliebt").show();
		$('#tabs-termine-btn').removeClass('current');
		$('#tabs-beliebt-btn').addClass('current');
		return false;
	});
});




var fillDates = function(data) {
	jQuery.each(data, function() {
		/*console.log(this.id);*/
		var newDate = $('#date-dummy').clone();
		var domId = 'dateId_'+this.id;
		newDate.appendTo('#dates-list').attr('id',domId);
	
		$('#'+domId+' .date').text(this.datum);
		$('#'+domId+' .place').text(this.ort);
		$('#'+domId+' .title').text(this.titel).attr('href', '/10aerzte/20fortbildung/10fortbildungskalender/index.html?detail='+this.id+'#anchor_'+this.id);
		
		newDate.show();
	});
	jQuery('#dates-list').jcarousel({
		vertical: true,
		scroll: 1,
		auto: 4,
		animation: 900,
		wrap: 'last',
		initCallback: mycarousel_initCallback
	});
};

var fillPopular = function(data) {
	jQuery.each(data, function() {
		/*console.log(this.id);*/
		var newPop = $('#popular-dummy').clone();
		var domId = 'popId_'+this.rank;
		newPop.appendTo('#popular-list').attr('id',domId);
	
		$('#'+domId+' .title').text(this.displaytitle).attr('href', this.url);
		$('#'+domId+' .title').attr('title', this.title);
		
		newPop.show();
	});
	/*
	jQuery('#popular-list').jcarousel({
		vertical: true,
		scroll: 1,
		auto: 4,
		animation: 900,
		wrap: 'circular',
		initCallback: mycarousel_initCallback
	});*/
};

function mycarousel_initCallback(carousel) {
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
	});
	
	carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
	});
	
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
			carousel.stopAuto();
	}, function() {
			carousel.startAuto();
	});
};


