index = 1;


function update(offset)
{
	var $parent = $('#schools .images');
	var $items;
	var $item;
	var data = JSON.parse($parent.find('textarea').val());
	var count = data.length;
	var value;

	switch (offset) {
		case -1: index = (index == 1 ? count : index - 1); break;
		case 1: index = (index == count ? 1 : index + 1); break;
	}

	value = data[index - 1];

	$parent.append("<img src=\"" + value.url + "\" />");
	$item = $parent.find('img:last');
	$item.fadeTo(0, 0);
	$item.load(function() {
		$item.fadeTo(750, 1, function() {
			$items = $('#schools .images').find('img');
			if ($items.length > 1) $items.eq(0).remove();
		});

		$parent = $('#schools .description');
		$item = $parent.find('div:last');
		$item.fadeTo(750, 0);
		$parent.append("<div class=\"wysiwyg\">" + value.description + "</div>");
		$item = $parent.find('div:last');
		$item.fadeTo(0, 0);
		$item.fadeTo(750, 1, function() {
			$items = $parent.find('div');
			if ($items.length > 1) $items.eq(0).remove();									
		});
	});
}


$().ready(function() {
	$('#schools .control .button1, #schools .control .button2').click(function() {
		update(($(this).attr('class') == 'button1' ? -1 : 1));
	});
});
