
/*
$('.flipopen').ready(function(){
	$('.flipopen').html('<a href="javascript:;" class="open_arrow mir">Ausklappen</a><a href="javascript:;" class="close_arrow mir">Einklappen</a>');
});
*/

function enhanceVAItems()
{
	$('.va-item').each(function(){
		var va_div = $(this);
		var va_id = va_div.attr('id').split('_')[1];
		va_div.find('.flipopen').html('<a href="javascript:;" class="open_arrow mir">Ausklappen</a><a href="javascript:;" class="close_arrow mir">Einklappen</a>');
		va_div.find('.links').hide();
		va_div.find('.open_arrow').click(function(){
			va_div.data('copy_short', va_div.find('.copy').html());
			va_div.data('height_short', va_div.find('.copy').height());
			va_div.find('.copy').load('/veranstaltung/' + va_id + '/js/detail/', function(){
				var height_long = va_div.height()+'px';
				$(this).css({'height': va_div.data('height_short')+'px'});
				$(this).animate(
					{height: height_long},
					{
						duration: 200,
						specialEasing: {height: 'easeOutQuart'},
						complete: function() {
							$(this).css({'height':'auto'});
							va_div.find('.links').show();
							
						}
					}
				);
			});
			$(this).hide().siblings().show();
			va_div.addClass('open');
			try{ET_Event.click('VAList%20ausklappen', va_id);}catch(err){}
			return false;
		});
		va_div.find('.close_arrow').click(function(){
			va_div.find('.copy').animate(
				{height: va_div.data('height_short')+'px'},
				{
					duration: 200,
					specialEasing: {height: 'easeOutQuart'},
					complete: function() {
						$(this).css({'height': 'auto'});
					}
			}).html(va_div.data('copy_short'));
			va_div.find('.links').hide();
			$(this).hide().siblings().show();
			va_div.removeClass('open');
			return false;
		}).hide();
		va_div.click(function(){ window.location.href = '/veranstaltung/' + va_id + '/'; });
		va_div.removeClass('va-item');
	});
}

$(document).ready(function(){
	if($('.paginatorcontainer').length > 0 && $('.va-item').length > 0){
		var loadingVA = false;
		$('.paginatorcontainer').hide();
		$(window).scroll(function(){
			if($(window).scrollTop() >= $(document).height() - $(window).height() - 450 && !loadingVA){
				loadingVA = true;
				var lastItem = $('li.item:last');
				var postvar = {valist: lastItem.attr('id').split('_')[1]};
				if(lastItem.parent().parent().hasClass('cl_small'))
					postvar.small = '1';
				$.post(window.location.href, postvar, function(data, textStatus){
					lastItem.parent().append(data);
					enhanceVAItems();
					if(textStatus == 'success')
						loadingVA = false;
				});
			}
			if($(window).scrollTop() > 500){
				$('.backtotop').fadeIn("slow");
			}else{
				$('.backtotop').fadeOut("slow");
			}
		});
	}
	enhanceVAItems();
	$('.backtotop').click(function(){
		$.scrollTo(0, 800, 'easeOutExpo');
	})
});
