/* Declare a namespace for the site */

var Site = window.Site || {};

/* Create a closure to maintain scope of the '$' and remain compatible with other frameworks. */

(function($) {

	/* Same as $(document).ready(); */

	$(function() {

		/* Smooth Scrolling */
		try {
			$('.brewing-101 a[href*=#]').click(function() {
				var duration=1000;
				var easing='swing';
				var newHash=this.hash;
				var target=$(this.hash).offset().top;
				var oldLocation=window.location.href.replace(window.location.hash, '');
				var newLocation=this;
					// make sure it's the same location
					if(oldLocation+newHash==newLocation)
					{
					// animate to target and set the hash to the window.location after the animation
					$('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
					// add new hash to the browser location
					window.location.href=newLocation;
				});
				return false;
				}
			});
		} catch(e) {}
		
		/* Member Sign-In */

		$(".sign-in form").hide();
		
		/* Print */
		
		$('a.print').click(function() {
			
			window.print();
			
			return false;
		});
		
		/* Form Validation */
		
		var validationOptions = {
			appendToParent: true
		};
				
		$('.validate').inlineValidate(validationOptions);
		
		$('form.validate').submit(function() {
			return $('.validate').isValid(validationOptions);
		});
		
		
		//$(".sign-in p").click(function(){$(this).toggleClass("active").next().toggle();});

		/* Cancel Hyperlink Event */

		//$(".sign-in p a").click(function(event) {event.preventDefault();});

		/* Brewer of the Week Slides */

		$('.brewer-of-the-week .slides').cycle({
			fx: 'fade',
			timeout: '9000',
			prev: '.brewer-of-the-week .previous',
			next: '.brewer-of-the-week .next'
		});

		/* Current Set of Slides */

		$('.gallery .current-set .slides').cycle({
			fx: 'fade',
			timeout: '9000',
			prev: '.gallery .current-set .previous',
			next: '.gallery .current-set .next'
		});

		/* Carousel */

	    $('.home #mycarousel').jcarousel({
	        auto: 2,
	        wrap: 'last',
	        initCallback: mycarousel_initCallback
	    });

		/* Members Slides */

		$('.aside .members .slides').cycle({
			fx: 'fade',
			timeout: '9000',
			prev: '.aside .members .previous',
			next: '.aside .members .next'
		});
		
		$('.brewing-101 .graphic li').mouseover(function() {
			$('.brewing-101 .graphic li').removeClass('hover');
			$(this).addClass('hover');
		});
		
		$('.brewing-101 .graphic li').mouseout(function() {
			$('.brewing-101 .graphic li').removeClass('hover');
		});
		
		$('.dropdown .button').click(function() {
			var $t = $(this);
			var next = $t.parent();
			
			if(!next.hasClass('active'))
				next.addClass('active');
			else
				next.removeClass('active');
				
			return false;
		});

		/* Fixed Floating Element */
		try {
		  var msie6 = $.browser == 'msie' && $.browser.version < 7;
		  
		  if (!msie6) {
		    var top = $('.return-to-top p').offset().top - parseFloat($('.return-to-top p').css('margin-top').replace(/auto/, 0));
		    $(window).scroll(function (event) {
		      // what the y position of the scroll is
		      var y = $(this).scrollTop();
		      
		      // whether that's below the form
		      if (y >= top) {
		        // if so, ad the fixed class
		        $('.return-to-top p').addClass('fixed');
		      } else {
		        // otherwise remove it
		        $('.return-to-top p').removeClass('fixed');
		      }
		    });
		  }
		} catch(e) {} 

	});


	$(window).bind("load", function() {



	});

})(jQuery);
