(function($){

 var leftSideBar = function(t){
  var c, r = t.rel? t.rel.split('::') : null;
  tests.push(t);
  t = $(t);
  this.im = t.children('img')[0];
  this.width = r && !isNaN(r[0])? +r[0] : 150;
  this.height = r && !isNaN(r[1])? +r[1] : 200;
  this.slideDuration = r && !isNaN(r[2])? +r[2] : 1000;
  this.opacityDuration = r && !isNaN(r[3])? +r[3] : 1500;
  t = t.parent('.sideBar')[0];
  c = $(t).children('.sideBarContents')[0];
  this.isExtended = false;
  this.w = this.im.offsetWidth;
  this.h = this.im.offsetHeight;
  $(c).css({top: this.h / 2, height: this.h, opacity: 0});
  this.fx_1 = function(h, w, t, o, d1, d2){$(c).animate({height: h, width: w, top: t}, d1, 'swing').animate({opacity: o}, {queue: false, duration:d2, easing: 'swing'});};
  this.fx_2 = function(h, w, d){$(t).animate({height: h, width: w}, {queue: false, duration: d, easing: 'swing'});};
  this.stopFx = function(){$(c).stop();$(t).stop();};
  this.extendContract();
 },

 re1 = new RegExp('(\\.[^.]+)$'), re2 = new RegExp('(\\.[^.]+)$'),
 tests = [], bars = [];
 
 leftSideBar.prototype.extendContract = function(){
  this.stopFx();
  if(this.isExtended){
   this.isExtended = false;
   this.fx_1(this.h, 0, this.h / 2, 0, this.slideDuration, this.opacityDuration);
   this.fx_2(this.h, this.w, this.slideDuration + 100);
   // make expand tab arrow image point left
   this.im.src = this.im.src.replace(re1, '$1');
  }
  else {
   this.isExtended = true;
   this.fx_1(this.height, this.width, 0, 1, this.slideDuration + 50, this.opacityDuration);
   this.fx_2(this.height, this.width + this.w, this.slideDuration);
   // make expand tab arrow image point right
   this.im.src = this.im.src.replace(re2, '$1');
  }
 };

 $(document).click(function(e){
  var t = $(e.target).hasClass('sideBarTab')? e.target : $(e.target).parent('.sideBarTab')[0];
  if(t && $.inArray(t, tests) > -1)
   bars[$.inArray(t, tests)].extendContract();
  else if(t)
   bars.push(new leftSideBar(t));
  else return;
  e.preventDefault();
  t.blur();
 });
})(jQuery);