﻿(function($){
	// accordion
	$.fn.accordion = function(options) {
		// settings
		var defaults = {
			duration: 300
		};
		
		var settings = $.extend({}, defaults, options);
		
		// init
		var $accordion = this;
		var $slides = this.find(".item");
		var $activeSlide = null;
		
		// popravi id-eve slideova
		$slides.each(function(i, elm) {
			var $self = $(elm).find(".content");
			if (!$self.attr('id')) 
				$self.attr('id', '_' + i);
		});
		
		this.switchSlide = function($slide) {
			if (!!$activeSlide) {
				$activeSlide.slideUp(settings.duration);
				if ($slide.attr("id") == $activeSlide.attr("id")) {
					$activeSlide = null;
					return;
				}
			}
			$slide.slideDown(settings.duration);
			$activeSlide = $slide;
		}
		
		$slides.find(".title").bind("click", function() {
			var $this = $(this);
			
			$accordion.switchSlide($this.nextAll(".content"));
		});
		
		
		return this;
		
	}

}(jQuery));
