$(document).ready(function() {

	if($('#whatsHot ul').children().size()>1) {
		$('#whatsHot ul').after('<div id="hotPrev" class="sliderControls prev"></div><div id="hotNext" class="sliderControls next"></div>');
		
		$('#whatsHot ul li img[alt]').each(function() {
			if ($(this).attr('alt').length)
				$(this).after('<div class="caption">'+$(this).attr('alt')+'</div>');
		});
		
		$('#whatsHot ul').cycle({
			fx: 'scrollHorz',
			timeout: 3000,
			speed: 500,
			pause: 1,
			next: '#hotNext', 
			prev: '#hotPrev'
		});
		// Stop Autoplay after prev or next buttons are pressed
		$('#hotNext, #hotPrev').click(function() { 
			$('#whatsHot>ul').cycle('pause'); 
		});
	} else if ($('#whatsHot ul').children().size()==0)
		$('#whatsHot').css('display','none');

	if ($('#kegulator').length) {
		var theOutput = new Array();
		function kegulate(kegSize) {
			switch(parseInt(kegSize)) {
				case 1:
					theOutput = ["160","6 &#190;"];
					break;
				case 2:
					theOutput = ["80","3 &#189;"];
					break;
				case 3:
					theOutput = ["140","5 &#190"];
					break;
				case 4:
					theOutput = ["84","3 &#189;"];
					break;
				case 5:
					theOutput = ["53","2 &#188;"];
					break;
				default:
					theOutput = ["",""];
			}
			console.log(theOutput[0]);
			$('#kegulated').html(' is equal to <strong>'+theOutput[0]+'</strong> 12 oz beers or <strong>'+theOutput[1]+'</strong> cases.');
		}
		$('#kegulatorMenu').change(function() {
			kegulate($(this).val());
		});

	}
	
	if ($('#inHomeBeerTasting').length) {
		$('#inHomeBeerTasting').cycle({
			fx: 'fade',
			timeout: 3000,
			speed: 1200
		});
	}

	if ($('#contact').length) {
		$(document).on('submit', '#contact', function(e){
			e.preventDefault();
			var form = this;
			var action = $(form).attr('action');
			$('#submit')
				.after('<img src="img/ajax-loader.gif" class="loader">')
				.attr('disabled','disabled');

			$.post(action, {
					name: $('#name').val(),
					address: $('#address').val(),
					city: $('#city').val(),
					state: $('#state').val(),
					zip: $('#zip').val(),
					email: $('#email').val(),
					message: $('#message').val()
				},
				function(data){
					$('#contact #submit').removeAttr("disabled");
					$('#response').remove();
					$('#contact').before('<div id="response" class="response">'+data+'</div>');
					$('#response').hide().slideDown();
					$('#contact img.loader').fadeOut(500,function(){$(this).remove()});
					if(data=='Your message has been sent.') $('#contact').slideUp();
				}
			);
		});
	}

	if ($('#brewer').length) {
		$(document).on('submit', '#brewer', function(e){
			e.preventDefault();
			var form = this;
			var action = $(form).attr('action');
			$('#submit')
				.after('<img src="img/ajax-loader.gif" class="loader">')
				.attr('disabled','disabled');

			$.post(action, {
					name: $('#name').val(),
					email: $('#email').val(),
					message: $('#message').val()
				},
				function(data){
					$('#brewer #submit').removeAttr("disabled");
					$('#response').remove();
					$('#brewer').before('<div id="response" class="response">'+data+'</div>');
					$('#response').hide().slideDown();
					$('#brewer img.loader').fadeOut(500,function(){$(this).remove()});
					if(data=='Your message has been sent.') $('#brewer').slideUp();
				}
			);
		});
	}

});

