$(document).ready(function() {
	$('.event-row').each(function(i) {
		var toggle = $('.more_less_toggle', this);
		toggle.show();
		var big_info = $('.details-box', this);
		var address = $('.venue-address', this);
		var event_desc = $('.event-description', this);
		var little_info = $('.small_info_details', this);
		var thumb = $('.venue_thumb', this);
		var expand_label  = $('.expand_label', this);
		var venue_box = $('.venue-box', this);
		$(toggle).click(function() {
			if ($(toggle).html() == '-') {
				collapse(toggle, big_info, little_info, address, event_desc, thumb, venue_box, expand_label);
			} else {
				expand(toggle, big_info, little_info, address, event_desc, thumb, venue_box, expand_label);
			}
			return false;
		});
	});
	$('#list_view_change li').each(function(i) {
		$('a', this).click(function() {
			$(this).parent('li').siblings().children('a').removeClass('active');
			var action = $(this).attr('id');
			if (action == 'collapse') {
				collapse_all();
			} else if (action == 'expand') {
				expand_all();
			} else if (action == 'grid_view') {
				make_grid();
			}
			$(this).addClass('active');
			return false;
		});
	});
	//$('#list_view_change #expand').click();
});


function expand(toggle, big_info, little_info, address, event_desc, thumb, venue_box, expand_label) {
	$(toggle).show();
	$(toggle).html('-');
	$(toggle).css('top', '6px');
	$(big_info).slideDown('fast');
	$(address).show();
	$(event_desc).hide();
	$(little_info).hide();
	$(venue_box).css('height', '50px');
	$(thumb).hide();
	$(expand_label).hide();
}

function make_grid() {
	expand_all();
	$('.event-row:not(.featured)').each(function(i) {
		$(this).addClass('grid_view');
		$('.venue-address', this).show();
		$('.venue-thumb', this).hide();
		$('.venue_description', this).hide();
		$('.more_less_toggle', this).hide();
		if ((i + 1) % 3 == 0) {
			$(this).addClass('third');
		}
	});
}

function collapse(toggle, big_info, little_info, address, event_desc, thumb, venue_box, expand_label) {
	$(toggle).show();
	$(toggle).html('+');
	$(toggle).css('top', '10px');
	$(big_info).slideUp('fast');
	$(address).hide();
	$(event_desc).css('display', 'block');
	$(little_info).show();
	$(venue_box).css('height', '65px');
	$(thumb).show();
	$(expand_label).show();
}

function expand_all() {
	$('.event-row:not(.featured)').each(function() {
		$(this).removeClass('grid_view');
		//$('.venue-address', this).css('display', 'inline');
		var toggle = $('.more_less_toggle', this);
		var big_info = $('.details-box', this);
		var little_info = $('.small_info_details', this);
		var address = $('.venue-address', this);
		var event_desc = $('.event-description', this);
		var thumb = $('.venue_thumb', this);
		var venue_box = $('.venue-box', this);
		var expand_label = $('.expand_label', this);

		expand(toggle, big_info, little_info, address, event_desc, thumb, venue_box, expand_label);
	});
}
function collapse_all() {
	$('.event-row:not(.featured)').each(function() {
		$(this).removeClass('grid_view');
		//$('.venue-address', this).css('display', 'inline');
		var toggle = $('.more_less_toggle', this);
		var big_info = $('.details-box', this);
		var little_info = $('.small_info_details', this);
		var address = $('.venue-address', this);
		var event_desc = $('.event-description', this);
		var thumb = $('.venue_thumb', this);
		var venue_box = $('.venue-box', this);
		var expand_label = $('.expand_label', this);
		collapse(toggle, big_info, little_info, address, event_desc, thumb, venue_box, expand_label);
	});
}
