/*
The qcordion plugin
© Teemu Alapoikela 2010
MIT License (http://jquery.org/license)
*/
(function($){

  $.fn.qcordion = function(options) {
    
    var defaults = {
      header: ".qcordion-header",
      content: ".qcordion-content",
      useSlide: "no",
      slideContainer: ""
    };
    
    var options = $.extend(defaults, options);
    
    return this.each(function(){
      
      var $t = $(this);
    
      //If qSlider is in use, initialize the visible content with qSlider
      if (options.useSlide = "yes") {
        $t.find(options.content+":visible").find(options.slideContainer).qslider({
          useQcordion: "yes"
        });
      }
      
      //Bind the headers to toggle content when clicked  
      $t.find(options.header).bind("click",function(e){
        
        if ($t.find(options.content).is(":visible") == false) {
          $(options.content+":visible").not(this).slideToggle("slow");
          $t.find(options.content).slideToggle("slow", function(){
            //At the end of the slide animation, attach qslider to the content, if in use
            if (options.useSlide = "yes") {
              $t.find(options.slideContainer).qslider({
                useQcordion: "yes"
              });
            }           
          });
        }
      
      });
    
    });
    
  };
  
})(jQuery);