if (typeof console == "undefined") {
    window.console = {
        log: function () {}
    };
}


$(function () {

	// paging enabler
	if ($('#sidebar-mixlist').length > 0) {
		mixlistPaging();
	}
	
	
	// form submits
	$('#lsb_contact_submit').click(function (e) {
		e.preventDefault();
		
		// validate		
		if ($('#lsb_email').val() == '' || $('#lsb_name').val() == '') {
			$('#lsb_error').text("Please complete the required fields (marked with *).").slideDown('fast');
			
			return;
		}
		
		var form = $('#lsb_contact').serialize() + "&wstraub_form=true";
		$.post('/form.processor.php', form, function (data) {
			if (data.status == 'ok')
				$('#lsb_contact').empty().append('<p class="thanks">Thank you for joining the mailing list, you&rsquo;re information has been added to our database and we&rsquo;ll be in touch soon.');
			else
				$('#error_message').text('Oh no! There was a problem completing your request.').slideDown('fast');
		}, 'json');
	});
	
	$('#booking_submit').click(function (e) {
		e.preventDefault();
		
		// validate
		if (
			$('#name').val() == "" ||
			$('#city').val() == "" ||
			$('#country').val() == "" ||
			$('#email').val() == "" ||
			$('#event_details').val() == "" ||
			$('#promoter_details').val() == "")
		{
			$('#error_message').text('Please complete all fields before clicking on Submit.').slideDown('fast');			
			return;
		}
		
		var form = $('#booking_form').serialize() + "&wstraub_form=true";
		
		$.post('/form.processor.php', form, function (data) {
			if (data.status == 'ok')
				$('#booking_form').empty().append('<p class="thanks">Thank you for your inquiry, we&rsquo;ll be in touch soon.</p>');
			else
				$('#error_message').text('Oh no! There was a problem completing your request.').slideDown('fast');
		}, 'json');
		
	});
	
	
	// height adjusters
	if (($('#main').height() - 290)  > $('#left-sidebar').height()) {
    // console.log('content taller than lsb');
		$('#left-sidebar').height($('#main').height() - 290);
	} else {
    // console.log('content shorter than lsb');
		$('#content').height($('#left-sidebar').height() + 209);
	}
	
	if ($('#content').height() > $('#right-sidebar').height()) {
     // console.log('content taller than rsb!');
		$('#right-sidebar').height($('#content').height());
	} else {
     // console.log('content shorter than rsb!')
		$('#content').height($('#right-sidebar').height());
	}
});

var _mix_per_page = 10;
var _mix_total;

mixlistPaging = function () {
	_mix_total = $('#sidebar-mixlist li').length;
	$('#sidebar-mixlist').find('li').hide();
	$('#sidebar-mixlist').find('li:lt('+_mix_per_page+')').show();
	
	$('<p id="list-pager">View more: </p>').insertAfter($('#sidebar-mixlist'));
	
	for(i = 1; i<= (Math.ceil(_mix_total/_mix_per_page)); i++) {
		$('#list-pager').append('<a href="#" id="p_'+i+'">'+i+'</a> ');
	}
	
	$('#p_'+1).addClass('selected');
	
	$('#list-pager a').click(function (e) {
		e.preventDefault();
		
		var id = parseInt($(this).attr('id').replace('p_', '')) - 1;
		
		$('#list-pager a.selected').removeClass('selected');
		$(this).addClass('selected');
		$('#sidebar-mixlist').find('li').hide();
		
		list = $('#sidebar-mixlist').find('li:gt(' + id * _mix_per_page + ')');
		
		$('#sidebar-mixlist').hide();
		for (i=0; i < _mix_per_page; i++) {
			if (list[i] != undefined) {
				$(list[i]).show();
			}
		}
		$('#sidebar-mixlist').slideDown();
		
		//.find('li:lt(' + _mix_per_page +')').show();
	});
}
