/**
 * 
 * @param options
 * @return void
 */ 
var Accordion = function(options) {
      this.current = 0;
      this.options = options ||  new Object();
      this.className = this.options.className || 'accordion';
      this.initializer();
  };
  
  Accordion.prototype = {
    
    initializer : function() {
          var self = this;
          $('.'+this.className).css({'height':'365px'});
          $('.'+this.className + ' .item').each(function (i){
              $(this).bind('mouseenter', {index:i, self:self }, function(event) {
                  self.toggle(event);
              });
        });
          $('.'+this.className + ' .item').eq(0)
        .stop()
              .animate(
                  {height:"321px"}, 
                  500
        );
      },
      toggle : function (event) {
          try {
              var self = event.data.self;
              var index = event.data.index;
              if(index != self.current) {
                  $('.'+self.className + ' .item')
                  .eq(index)
                  .stop()
                  .animate(
                          {height:"321"}, 
                          500,
                          function () {}
                   );
                $('.'+self.className + ' .item')
                  .eq(self.current)
                  .stop()
                    .animate(
                      {height:"45px"}, 
                      500,
                      function () {
                          self.current = index;
                      }
                );
              }
          } catch(error) {alert(error);}
      }
  };
  $(function(){
    /* Accordion */
      new Accordion();
  });
  

/**
 * Tabs object 
 * 
 * @param options (class names, ids, etc, other)
 */
Tabs = function(options) {
  this.initialize(options);
};
/**
 * Tabs class body
 */
Tabs.prototype = {
    
  /**
   *  Initializer 
   * @param options
   * @return void
   */
  initialize : function (options) {
    this.currentIndex  = 0;
    var title = $('.tabs>.title>.c')[this.currentIndex];
    $(title).children("a").css({border: 'none', color: '#fffd5f'});
    this.tabs();

  },
  /**
   * Create tabs
   * 
   * @return void
   */
  tabs : function () {
    var self = this;
    $('.tabs>.title>.c a').each(function (i){
      $(this).bind('click', {index:i}, function(event) {
        event.preventDefault();
        self.toggle(i);
      });
    });
  },
  
  toggle : function (index) {
    try {
        var self = this;
        var title = $('.tabs>.title>.c')[this.currentIndex];
        var content = $('.tabs>.corners>.content>.c')[this.currentIndex];
        $(title).children("p").slideUp();
        $(title).children("a").css({borderBottom: '1px dotted', color: '#fff'});
        $(content).fadeOut(300, function f() {
          self.currentIndex = index;
          var title = $('.tabs>.title>.c')[self.currentIndex];
          var content = $('.tabs>.corners>.content>.c')[self.currentIndex];
          $(title).children("p").slideDown();
          $(title).children("a").css({border: 'none', color: '#fffd5f'});
          $(content).fadeIn(300);
        });
    } catch(error) {}
  }, 
  initEvents : function() {

  }  
};
/*
$(document).ready(function () {
  new Tabs(null);
}); */
