// JavaScript Document
/* Accordeons */
(function($){
	$.fn.accordeon = function(){
		return this.each(function(){
			var $container = $(this);
			var $content = $('.content', $container);
			(!$container.hasClass('close'))? $content.data('isVisible', true) : $content.data('isVisible', false);
			if($container.hasClass('close')) $('.animate', $content).css({height: 0});
						
			$('.header h3,.header .icon', $container).bind('click', function(e){
				hexagram.tools.stopEvent(e);
				toogle();
				return false;
			});
			
			var toogle = function(){				
				($content.data('isVisible'))? _close() : _open();
				return false;
			};
			
			var _open = function(){
				$content.data('isVisible', true);
				$container.removeClass('close');		
				var height = $('.wrapper', $content).outerHeight();
				$('.animate', $content).stop().animate({height: height}, {'duration': 450, 'queue': false, 'easing': 'easeInOutQuad', 'complete': function(){}});
			};
			
			var _close = function(){
				$content.data('isVisible', false);
				
				$('.animate', $content).css({overflow: 'hidden'}).stop().animate({height: 0}, {'duration': 450, 'queue': false, 'easing': 'easeInOutQuad', 'complete': function(){
					$container.addClass('close');
				}});
			};	
		});	
	};
})(jQuery);

$(document).ready(function(e){
	$('.accordeon', $('.accordeons')).accordeon();
});
