/*
Name of project: Fermentas
Author: Sergej Rozkov <s.rozkov@citrus.lt>
*/

//
//  BancoDyn v0.1   Функцинальность динамических блоков для Banco TransAtlantico

//------------------- BancoDyn v0.1 -----------------------------------------------
//Функцинальность динамических блоков для Banco TransAtlantico
//issues: no

function BancoDyn() {
    //иконки
    var Icon = {};
        Icon['templates/images/icon_dollar.gif'] = 'templates/images/icon_dollar_active.gif';
        Icon['templates/images/icon_question.gif'] = 'templates/images/icon_question_active.gif';
        Icon['templates/images/icon_microphone.gif'] = 'templates/images/icon_microphone_active.gif';
        Icon['templates/images/icon_calculator.gif'] = 'templates/images/icon_calculator_active.gif';
        
        Icon['templates/images/icon_dollar_active.gif'] = 'templates/images/icon_dollar.gif';
        Icon['templates/images/icon_question_active.gif'] = 'templates/images/icon_question.gif';
        Icon['templates/images/icon_microphone_active.gif'] = 'templates/images/icon_microphone.gif';
        Icon['templates/images/icon_calculator_active.gif'] = 'templates/images/icon_calculator.gif';
        
    //подготовка контейнера для динамических блоков
    Container = $j('<div id="Con" class="vote_div"></div>');
    Icons = $j('<div id="conIcons" class="vote_icons"></div>');
    $j('.vote_div').each(function(i) {
        $j(this).attr('num', i).addClass('dClose');
        $j('.vote_icon_item', this).attr('num', i).clone().appendTo(Icons);
    });
    Icons.appendTo(Container)
    Container.insertAfter($j('.vote_div:last'));
    
    //выбор активного элемента
        //берём первый загруженный
    $j('.vote_div:eq(0) .vote_question').clone().appendTo('#Con');
    $j('#conIcons .vote_icon_item').each(function() {
        if ( $j(this).attr('num') == $j('.vote_div').attr('num')) {
            $j(this).removeClass('vote_icon_item').addClass('vote_icon_item_active');
            $j('IMG', this).attr('src', Icon[$j('IMG', this).attr('src')])
            $j('<span></span>').prependTo($j(this));
        }
    });
    
    //Функцианальности Кликов на иконки динамических блоков
    $j('#conIcons DIV').click(function() {
         $j('#conIcons .vote_icon_item_active IMG').attr('src', Icon[$j('#conIcons .vote_icon_item_active IMG').attr('src')])
         $j('#conIcons .vote_icon_item_active').removeClass('vote_icon_item_active').addClass('vote_icon_item');
         
         $j(this).removeClass('vote_icon_item').addClass('vote_icon_item_active');
         $j('IMG', this).attr('src', Icon[$j('IMG', this).attr('src')]);
         $j('<span></span>').prependTo($j(this));
         num = $j(this).attr('num');
         $j('#Con .vote_question').remove();
         $j(".vote_div[num="+num+"] .vote_question").clone().appendTo('#Con');
    })
}      