(function($)
{
    function ajust_height(time){ 		 
		  setTimeout(function(){
        height = $("#comments_container .tab-content.active").css('height');
        height2 = $("#comments_wrapper .tabs-control").css('height');
        h = parseInt(height) + parseInt(height2);
			  $('#comments_wrapper').animate({height: h + 'px'});
      },time);
    }
$.fn.tabSlider = function(added_text){
    var a = this;
    var url = String(window.location);
    result = url.indexOf("#comment");
    if(result != -1)
      {
        $('#facebook').removeClass('active');
        $('#classic').addClass('active');
      }
    tc_width = a.parent().width();
    if ($('.tab-content', a).length > 1) {
        if(added_text !== '')
          a.before('<div class="tabs-control"><h3>'+ added_text +'</h3><ul class="tabs"></ul></div>');
        else 
          a.before('<div class="tabs-control"><ul class="tabs"></ul></div>');
        tabs = a.siblings().children('.tabs');
        }
    else 
      return;
    $('.tab-content', a).each(function() {
        title = $(this).find('.tab-title');
        label = $('.label', title);
        if ($(this).hasClass('active'))
        active = ' active';
        else
        active = '';
        tabs.append('<li class="tab' + active + '"><a rel="' + $(this).attr('id') + '" href="#"><h3>' + label.text() + '</h3></a></li>');
            title.remove();
                });
     a.css('margin-left', -a.find('.tab-content.active').index() * parseInt(a.parent().width()));
    // ajust_height(1500);
     $('.tab', tabs).click(function(){
           tc_width = a.parent().width();
           $('a', this).blur();
           if(!$(this).hasClass('active')) {
              $(this).addClass('active');
  						$('#comments_container .tab-content.active').removeClass('active').siblings('.tab-content').addClass('active');
              $(this).siblings('.tab').removeClass('active');
              index = $('#' + $(this).find('a').attr('rel')).index();
              $(a).animate({marginLeft: - index * tc_width });
             // ajust_height(0);
              }
           return false;
           });
           };
})(jQuery);

