/**
 * Created by JetBrains PhpStorm.
 * User: sergasd
 * Date: 16.08.11
 * Time: 15:41
 * SWAP TEXT PLUGIN
 * Меняет местами блоки при клике на кнопке триггере
 * Кнопка триггер задается опцией selector
 */


(function($){

    $.swaptext = function(options){

        /*OPTIONS*/
        options = $.extend({
            'selector' : '.more',
            'expandedClass' : 'expanded',
            'collapsedClass' : 'collapsed',
            'firstTextClass' : '.desc_small_text',
            'secondTextClass' : '.desc_full_text',
            'expandedButtonText' : 'подробнее...',
            'collapsedButtonText' : 'кратко...'
        },options);


        /*EVENT BIND*/
        $(options['selector']).click(function(e){
            var state = $(this).hasClass(options['expandedClass']) ? options['expandedClass'] : options['collapsedClass'];

            if(state === options['expandedClass'])
            {
                $(this).prevAll(options['firstTextClass']).show();
                $(this).prevAll(options['secondTextClass']).hide();
                $(this).addClass(options['collapsedClass']).removeClass(options['expandedClass']);
                $(this).text(options['expandedButtonText']);
            }
            else if(state === options['collapsedClass'])
            {
                $(this).prevAll(options['firstTextClass']).hide();
                $(this).prevAll(options['secondTextClass']).show();
                $(this).addClass(options['expandedClass']).removeClass(options['collapsedClass']);
                $(this).text(options['collapsedButtonText']);
            }

            e.preventDefault();
        });

    };

})(jQuery);
