/**
 * support scripts for KVS v5
 *
 * @author Sander van Vliet
 * @version 0.1
 *
 **/
var currentDt = 1;

function addNextPhoto(id, callback) {
	$.ajax({
		url: '/wp-admin/admin-ajax.php',
		type: 'get',
		data: { action: 'getrandomimage', streamid: id },
		success: function(output) {
			var obj = jQuery.parseJSON(output);
			var pt = $('<a href="' + obj.url + '"><img src="' + obj.thumb + '" /></a>');
			$('#' + id).append(pt);
			eval(callback + '("' + id + '")');
		}
	});
}
function getNextDonateur(id, callback)
{
	$.ajax({
		url: '/wp-admin/admin-ajax.php',
		type: 'get',
		data: { action: 'getnextdonateur', current: currentDt },
		success: function(output) {
			var obj = jQuery.parseJSON(output);
			currentDt = obj.current;
			$('#' + id).find('img').filter(':first').attr('src', obj.thumb);
			eval(callback + '()');
		}
	});
}
function scrollPhotostream(id)
{
	addNextPhoto(id, 'startscroll');
}
function scrollDonateurs(id)
{
	getNextDonateur(id, 'startnexttimer');
}
function startscroll(id)
{
	var elems = $("#" + id).find("a");
	var first = elems.filter(':first');
	var offset = first.width();
	elems.each(function(index) {
		$(this).animate(
		{
			left: '-' + offset +  'px'
		},
		2000,
		'easeInOutSine',
		function() {
			if(first != null)
			{
				first.remove();
				first = null;
			}
			$(this).css('left', '+=' + (offset + 2));
		});
	});
	$(document).oneTime(5000, "pts", function() { if(!holdStreamScroll) { scrollPhotostream(id); } });
}
function startnexttimer(id)
{
	$(document).oneTime(1500, "dts", function() { scrollDonateurs('sponsors'); });
}

