(function ($) {

	$.fn.shtorken = function () {

		var
			jNode = $(this),
			ajHeads = jNode.find('.head, .body'),
			ajTabs = jNode.find('.tab'),
			jCurrent = ajTabs.filter('.current'),
			that = this;

		jNode.data('current', jCurrent);
		jNode.data('animated', false);

		this.showContent = function ( jElement ) {
			if (!jElement.data('scrollLoaded') && jElement.hasClass('customScrollBox')) {
				jElement.mCustomScrollbar("vertical");
				jElement.data('scrollLoaded', true);
			} else if (jElement.hasClass('customScrollBox')) {
				jElement.find('.dragger_container').show(100);
			}
			jElement.find('.content').fadeIn(300);
			jElement.find('.bghider').fadeIn(300);
		}
		this.hideContent = function ( jElement ) {
			jElement.find('.content').fadeOut(300);
			jElement.find('.bghider').fadeOut(300);
			if (jElement.data('scrollLoaded')) {
				jElement.find('.dragger_container').hide(100);
			}
		}

		this.showContent(jCurrent);

		ajHeads.bind('click', function() {
			var jSender = $(this).closest('.tab');
			if (jSender.hasClass('current') || jNode.data('animated')) {
				return;
			}
			that.hideContent(jNode.data('current'));
			jNode.data('animated', true);
			jNode.data('current').animate( { width: 124 }, { step:function (now, fx){
				jSender.css('width', 124+331-now);
			}, complete : function () {
				jNode.data('current').removeClass('current');
				jSender.addClass('current');
				jNode.data('current', jSender);
				jNode.data('animated', false);
				that.showContent(jNode.data('current'));
			}});
		})

	}

})(jQuery)
