// Get content from URL and display it in element, specified by ID
function loadurl(id, url, onsuccess) {
	stopvideo();
	new Ajax.Request(url, {
		method: 'get',
		onCreate: function() {
			$(id).update('<img src="img/ajax.gif" alt="" width=50 height=50>');
		},
		onSuccess: function(transport) {
			$(id).update(transport.responseText);
			if (onsuccess != undefined) eval(onsuccess);
		},
		onFailure: function(transport) {
			var errtext = 'Cannot load URL (code=' + transport.status + '): ' + url;
			$(id).update('<span style="color:red;">' + errtext + '</span>');
		}
	});
}

// Click on directory link
// obj - link object
// cat_id - selected category id
function click_dir(obj, cat_id) {
	loadurl('cards', 'print_cards.php?cat_id='+cat_id, 'play_first_card();');
}

// Stop playing current preview
function stopvideo() {
	$('preview').update('');
}

// Play first card on the page
function play_first_card() {
	div = $$('.nf_thumb').first();
	if (div != undefined) {
		card_id = div.down().innerHTML;
		loadurl('preview', 'print_preview.php?id='+card_id);
	}
}
