(function($){
	$.fn.accordion = function(options){
		var params = {
			oneAtATime: false,
			animTime: 300
		}
				
		// overwrite params with custom data if present
		if(typeof(options) !== "undefined"){for(var prop in options){params[prop] = options[prop];}}
				
		// return this to maintain chainability
		this.each(function(){
			var accordLink = $(this).children(".accord-link"),
				accordItem = $(this).children(".accord-item"),
				animTime = 300;
				
			accordLink.click(function(){
				var showMe = $(this).next('.accord-item');		
				// if there is animation in progress, return out
				if (showMe.is(':animated')){return;}		
				// if you click an accordion link that is already open, do this and return out
				else if($(this).is('.active')){
					showMe.slideUp(animTime);
					$(this).removeClass('active');
					return;
				}
				
				// remove active classes from any accordion links and add it to the one you just clicked
				if(params.oneAtATime){
					$(this).addClass("active");
				} else {
					accordLink.filter('.active').removeClass('active').end()
					.filter(this).addClass('active');
					
					// hide any open accordion content block
					$(this).siblings('.accord-item:visible').slideUp(animTime);
				}
		
				// open new accordion content block
				showMe.slideDown(animTime);
				return false;
			}).prepend('<span></span>').next('.accord').wrap('<div class="accord-item" />').end()
			.filter(':even').each(function(){
				$(this).add($(this).next('.accord-item')).addClass('even');
			});
			
			$(this).addClass("visible");
						
		});
		
		function checkHash(){
			if($(window.location.hash).length > 0){
				var jumpTo = $(window.location.hash),
					offset = jumpTo.offset();			
				jumpTo.parent().show().prev(".accord-link").addClass("active");
				window.scroll(0, offset.top - 50);
			}
		}
		checkHash();
		if("onhashchange" in window){window.onhashchange = checkHash;}		
		
		return this;
		
	};
		
})(jQuery);
