function handler_bestar( guid )
{
    $('div.buttons').find('div.about').click(function()
    {
        location.href = '/bestar/';
    });

    $('div.buttons').find('div.vote').click(function()
    {
        location.href = '/bestar/vote/';
    });

    $('div.buttons').find('div.top').click(function()
    {
        location.href = '/bestar/top/';
    });

    if ( guid == 'vote' )
    {
        $('div.buttons').find('div.vote').css
        ({
            backgroundPosition: 'bottom'
        });

        $('div.buttons').find('div.about').hover
        (
            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'bottom'
                });
            },

            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'top'
                });
            }
        );

        $('div.buttons').find('div.top').hover
        (
            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'bottom'
                });
            },

            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'top'
                });
            }
        );

        jQuery.get
        (
            '/cgi-bin/bestar/current' ,
            {
            }                         ,
            function( data )
            {
                core_bestar_list_vote(data);
                $('div.bs_info').show();

            } ///;~
        );
    }
    else if ( guid == 'top' )
    {
        $('div.buttons').find('div.top').css
        ({
            backgroundPosition: 'bottom'
        });

        $('div.buttons').find('div.about').hover
        (
            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'bottom'
                });
            },

            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'top'
                });
            }
        );

        $('div.buttons').find('div.vote').hover
        (
            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'bottom'
                });
            },

            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'top'
                });
            }
        );

        jQuery.get
        (
            '/cgi-bin/bestar/list' ,
            {
            }                      ,
            function( data )
            {
                core_bestar_list_tour(data);

            } ///;~
        );
    }
    else
    {
        $('div.buttons').find('div.about').css
        ({
            backgroundPosition: 'bottom'
        });

        $('div.buttons').find('div.vote').hover
        (
            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'bottom'
                });
            },

            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'top'
                });
            }
        );

        $('div.buttons').find('div.top').hover
        (
            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'bottom'
                });
            },

            function()
            {
                $(this).css
                ({
                      backgroundPosition: 'top'
                });
            }
        );

        jQuery.get
        (
            '/cgi-bin/bestar/top' ,
            {
                guid: 'NULL'
            }                     ,
            function( data )
            {
                core_bestar_list_top_current(data);

            } ///;~
        );
    }

} ///;~

function core_bestar_list_vote( data )
{
    var size   = $('option' , data).size();
    var tour   = $('item'   , data);
    var parent = $('guid'   , tour).text();
    var title  = $('title'  , tour).text();
    var choice = $('choice' , tour).text();
    var code   = $('data'   , tour).text();
    var total  = $('voice'  , tour).text();
    var choice = $('choice' , tour).text();
    var item   = $('div.core_bs_item:last');

    $('div.core_bs_party').html(item);
    $('option', data).each(function( position )
    {
        var place      = position + 1;
        var guid       = $('guid'       , this).text();
        var data       = $('data'       , this).text();
        var statement  = $('statement'  , this).text();
        var assessment = $('assessment' , this).text();
        var thumbnail  = $('thumbnail'  , this).text();
        var voice      = $('voice'      , this).text();
        var closure    = 'ов';

        switch( voice )
        {
            case '1': var closure = ''; break;
            case '2':
            case '3':
            case '4': var closure = 'а'; break;
        }

        var sympathy = $('sympathy', this).text();
        var sympathy = parseFloat(sympathy) + parseFloat(assessment);
        var sympathy = (sympathy).toFixed(2);

        if ( photo == 'NULL' ) var photo = 'empty.gif';
        if ( guid  == choice )
        {
            $('div.core_bs_info').text
            (
                'Спасибо! Ваш голос отдан: ' + data
            );
        }

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_place')
                              .text(place + ' место');

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_name')
                              .text(data);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_statement')
                              .text(statement);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_assessment')
                              .find('span.core_bs_assessment')
                              .text(assessment);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_assessment')
                              .find('span.core_bs_voice')
                              .text(voice);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_assessment')
                              .find('span.core_bs_closure')
                              .text(closure);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_thumbnail')
                              .find('img')
                              .attr
        ({
            title: data + ' / ' + statement ,
            alt:   data + ' / ' + statement
        });

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_thumbnail')
                              .css
        ({
            backgroundImage:    'url(\'/libpixmap/bestar/' + thumbnail + '\')' ,
            backgroundRepeat:   'no-repeat'                                    ,
            backgroundPosition: '75px 15px'
        });

        if ( choice == 'NULL' )
        {
            $('div.core_bs_party').find('div.core_bs_item:last')
                                  .find('div.core_bs_action')
                                  .find('img')
                                  .click(function()
            {
                core_bestar_submit
                (
                    guid   ,
                    parent ,
                    code
                );
            });
        }
        else
        {
            $('div.core_bs_party').find('div.core_bs_item:last')
                                  .find('div.core_bs_action')
                                  .text('(' + sympathy  + ') баллов');
        }

        if ( (position + 1) != size )
        {
            $('div.core_bs_party').find('div.core_bs_item:last')
                                  .clone()
                                  .appendTo('div.core_bs_party');
        }
    });

    $('div.core_bs_info').show();
    $('div.core_bs_party').show();

} ///;~

function core_bestar_list_top_current( data )
{
    var size   = $('option' , data).size();
    var tour   = $('item'   , data);
    var parent = $('guid'   , tour).text();
    var title  = $('title'  , tour).text();
    var choice = $('choice' , tour).text();
    var code   = $('data'   , tour).text();
    var total  = $('voice'  , tour).text();
    var choice = $('choice' , tour).text();
    var item   = $('div.core_bs_item:last');

    $('div.core_bs_party').html(item);
    $('option', data).each(function( position )
    {
        var place      = position + 1;
        var guid       = $('guid'       , this).text();
        var data       = $('data'       , this).text();
        var statement  = $('statement'  , this).text();
        var assessment = $('assessment' , this).text();
        var thumbnail  = $('thumbnail'  , this).text();
        var voice      = $('voice'      , this).text();
        var closure    = 'ов';

        switch( voice )
        {
            case '1': var closure = ''; break;
            case '2':
            case '3':
            case '4': var closure = 'а'; break;
        }

        var sympathy = $('sympathy', this).text();
        var sympathy = parseFloat(sympathy) + parseFloat(assessment);
        var sympathy = (sympathy).toFixed(2);

        if ( photo == 'NULL' ) var photo = 'empty.gif';

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_place')
                              .text(place + ' место');

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_name')
                              .text(data);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_statement')
                              .text(statement);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_assessment')
                              .find('span.core_bs_assessment')
                              .text(assessment);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_assessment')
                              .find('span.core_bs_voice')
                              .text(voice);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_assessment')
                              .find('span.core_bs_closure')
                              .text(closure);

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_action')
                              .text('(' + sympathy  + ') баллов');

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_thumbnail')
                              .find('img')
                              .attr
        ({
            title: data + ' / ' + statement ,
            alt:   data + ' / ' + statement
        });

        $('div.core_bs_party').find('div.core_bs_item:last')
                              .find('div.core_bs_thumbnail')
                              .css
        ({
            backgroundImage:    'url(\'/libpixmap/bestar/' + thumbnail + '\')' ,
            backgroundRepeat:   'no-repeat'                                    ,
            backgroundPosition: '75px 15px'
        });

        if ( (position + 1) != size )
        {
            $('div.core_bs_party').find('div.core_bs_item:last')
                                  .clone()
                                  .appendTo('div.core_bs_party');
        }
    });

    $('div.core_bs_party').show();

} ///;~

function core_bestar_list_top_tour( data ,
                                    guid )
{
    var size   = $('option' , data).size();
    var tour   = $('item'   , data);
    var parent = $('guid'   , tour).text();
    var title  = $('title'  , tour).text();
    var choice = $('choice' , tour).text();
    var code   = $('data'   , tour).text();
    var total  = $('voice'  , tour).text();
    var choice = $('choice' , tour).text();
    var item   = $('#' + guid).find('div.core_bs_item:last');

    $('#' + guid).html(item);
    $('option', data).each(function( position )
    {
        var place      = position + 1;
        var data       = $('data'       , this).text();
        var statement  = $('statement'  , this).text();
        var assessment = $('assessment' , this).text();
        var thumbnail  = $('thumbnail'  , this).text();
        var voice      = $('voice'      , this).text();
        var closure    = 'ов';

        switch( voice )
        {
            case '1': var closure = ''; break;
            case '2':
            case '3':
            case '4': var closure = 'а'; break;
        }

        var sympathy = $('sympathy', this).text();
        var sympathy = parseFloat(sympathy) + parseFloat(assessment);
        var sympathy = (sympathy).toFixed(2);

        if ( photo == 'NULL' ) var photo = 'empty.gif';

        $('#' + guid).find('div.core_bs_item:last')
                     .find('div.core_bs_place')
                     .text(place + ' место');

        $('#' + guid).find('div.core_bs_item:last')
                     .find('div.core_bs_name')
                     .text(data);

        $('#' + guid).find('div.core_bs_item:last')
                     .find('div.core_bs_statement')
                     .text(statement);

        $('#' + guid).find('div.core_bs_item:last')
                     .find('div.core_bs_assessment')
                     .find('span.core_bs_assessment')
                     .text(assessment);

        $('#' + guid).find('div.core_bs_item:last')
                     .find('div.core_bs_assessment')
                     .find('span.core_bs_voice')
                     .text(voice);

        $('#' + guid).find('div.core_bs_item:last')
                     .find('div.core_bs_assessment')
                     .find('span.core_bs_closure')
                     .text(closure);

        $('#' + guid).find('div.core_bs_item:last')
                     .find('div.core_bs_action')
                     .text('(' + sympathy  + ') баллов');

        $('#' + guid).find('div.core_bs_item:last')
                     .find('div.core_bs_photo')
                     .find('img')
                     .attr
        ({
            title: data + ' / ' + statement ,
            alt:   data + ' / ' + statement
        });

        $('#' + guid).find('div.core_bs_item:last')
                     .find('div.core_bs_thumbnail')
                     .css
        ({
            backgroundImage:    'url(\'/libpixmap/bestar/' + thumbnail + '\')' ,
            backgroundRepeat:   'no-repeat'                                    ,
            backgroundPosition: '75px 15px'
        });

        if ( (position + 1) != size )
        {
            $('#' + guid).find('div.core_bs_item:last')
                         .clone()
                         .appendTo('#' + guid);
        }
    });

    $('#' + guid).show();

} ///;~

function core_bestar_list_tour( data )
{
    var size = $('item', data).size();
    var item = $('div.core_bs_top').find('div.core_bs_tour:last');

    if ( size == 0 )
    {
    }
    else
    {
    }

    $('div.core_bs_top').html(item);
    $('item', data).each(function( position )
    {
        var guid = $('guid', this).text();
        var data = $('data', this).text();

        $('div.core_bs_top').find('div.core_bs_tour:last')
                            .find('div.core_bs_tour_title')
                            .find('span')
                            .text(data);

        $('div.core_bs_top').find('div.core_bs_tour:last')
                            .find('div.core_bs_party')
                            .attr
        ({
            id: guid
        });

        jQuery.get
        (
            '/cgi-bin/bestar/top' ,
            {
                guid: guid
            }                     ,
            function( data )
            {
                core_bestar_list_top_tour
                (
                    data ,
                    guid
                );

            } ///;~
        );

        if ( (position + 1) != size )
        {
            $('div.core_bs_top').find('div.core_bs_tour:last')
                                .clone()
                                .appendTo('div.core_bs_top');
        }
    });

    $('div.core_bs_top').show();

} ///;~

function core_bestar_submit( option ,
                             parent ,
                             data   )
{
    jQuery.get
    (
        '/operator/bestar/submit.php' ,
        {
            option: option ,
            parent: parent ,
            data:   data
        }                             ,
        function( data )
        {
            location.href = '/bestar/vote/';

        } ///;~
    );

} ///;~
