function hover_mini_star (img, show)
{
    if (show)
    {
        $(img).parent().children('p').removeClass('hidden');
        $(img).css('background-position', '-51px 0');
    }

    else
    {
        $(img).parent().children('p').addClass('hidden');
        $(img).css('background-position', '0 0');
    }
}



function equipment_head ()
{
    if ($('body').width() < 1190)
        $('.venue-equipment-table .table-head li').addClass('small');
    else
        $('.venue-equipment-table .table-head li').removeClass('small');
}



function show_eq_table (table_num, a)
{
    $('.venue-equipment-table .head-in li').removeClass('active');
    $(a).parent().parent().addClass('active');
    $('.venue-equipment-table .table-holder').addClass('hidden');
    $('.venue-equipment-table #eq-table-'+table_num).removeClass('hidden');
}


function show_arrows (show, field)
{
    if (field == 'photoline')
    {
        if ($('#photoline').width() <= $('#site-wrap').width()-100) return false;

        if (show)
        {
            $('.photo-galleries .arrow').removeClass('hidden');
            var ul_left = $('#photoline').css('marginLeft').replace('px', '');
            if (ul_left >= 100) $('.photo-galleries .arrow-left').addClass('hidden');
            if (ul_left <= 100 - ($('#photoline').width() - ($('#site-wrap').width() - 100))) $('.photo-galleries .arrow-right').addClass('hidden');

        }
        else
        {
            $('.photo-galleries .arrow').addClass('hidden');
        }
    }
    else if (field == 'eventsline')
    {
        if ($('#eventsline').width() <= $('#site-wrap').width()-100) return false;

        if (show)
        {
            $('.venue-afisha .arrow').removeClass('hidden');
        }
        else
        {
            $('.venue-afisha .arrow').addClass('hidden');
        }
    }
    else if (field == 'topslides')
    {
        if (show)
        {
            $('.top-slides-nav').removeClass('hidden');
            if (current_top_slide == 1) $('.top-slides-nav-left').addClass('hidden');
            if (current_top_slide == $('#top-slides-holder>ul li').size()) $('.top-slides-nav-right').addClass('hidden');
        }
        else
        {
            $('.top-slides-nav').addClass('hidden');
        }
    }
}


/***********************************************************************************************************************
* двигаем ленту с фото
***********************************************************************************************************************/
var photoline_timer_id = null;
var photoline_speed = 5;
var start_margin = 100;
var speed_increase_counter = 0;
function start_move_photoline (direction)
{
    if ($('#photoline').width() < $('#site-wrap').width()-100) return false;

    //alert( start_margin - ($('#photoline').width() - ($('#site-wrap').width() - 100)));

    stop_move_photoline();

    if (direction == 'left')
    {
        photoline_timer_id = setInterval("move_photoline('left')", 30);

        /*var ul_left = $('#photoline').css('margin-left').replace('px', '');
        if (ul_left >= 100) return false;
        else
        {
            ul_left = ul_left+1;
            $('#photoline').css('margin-left', ul_left+'px');
        }*/
    }
    else if (direction == 'right')
    {
        photoline_timer_id = setInterval("move_photoline('right')", 30);

        /*var ul_left = $('#photoline').css('margin-left').replace('px', '');
        //if (ul_left >= 100) return false;

        //else
        //{
            ul_left = ul_left-1;
            $('#photoline').css('margin-left', ul_left+'px');
        //}*/
    }
}

function stop_move_photoline ()
{
    if (photoline_timer_id != null) {
        clearInterval(photoline_timer_id);
    }
    photoline_timer_id = null;
    photoline_speed = 5;
    speed_increase_counter = 0;
}

function move_photoline(direction)
{
    if (photoline_speed < 1)
    {
        photoline_speed = 1
    }

    var ul_left = 100;
    speed_increase_counter++;

    if (direction == 'right')
    {
        ul_left = $('#photoline').css('margin-left').replace('px', '');
        if (ul_left <= start_margin - ($('#photoline').width() - ($('#site-wrap').width() - 100))) {
            stop_move_photoline();
            return false;
        }
        ul_left = ul_left-photoline_speed;
        $('#photoline').css('margin-left', ul_left);
    } else if (direction == 'left') {
        ul_left = $('#photoline').css('margin-left').replace('px', '');
        if (ul_left >= 100) {
            stop_move_photoline();
            return false;
        }
        ul_left = parseInt(ul_left)+parseInt(photoline_speed);
        $('#photoline').css('margin-left', ul_left);
    }
    show_arrows(true, 'photoline');

    if (speed_increase_counter > 10) {
        speed_increase_counter = 0;
        photoline_speed++;
    }
}


var photo_num = 1;
var photo_count = 0;
var photogallery_id = 0;
var photogallery_module = '';
function show_popup_photogallery (id, module)
{
    photogallery_module = module;
    $('#popup-data .inner').html('');
    $('#popup-data .arrows').hide();
    $('#popup-shade').height($(document).height());
    $('#popup-shade').fadeIn(400, function()
    {
        // показываем загрузчик
        $('#popup-content-loading').removeClass('hidden');

        $.post('/ajax/get_photo_from_gallery', {photogallery_id: id, photo_num: photo_num, module: module}, function(data)
        {
            if (data.status == 0) {
                hide_popup();
                return false;
            }

            // считаем высоту всего контента через буфер
            $('#popup-buffer').html('');
            $('#popup-buffer').append('<div class="popup-photo-content"><div class="title">'+data.title+'</div><div class="inner"></div></div>');
            $('#popup-buffer .inner').html(data.content);
            var height_for_popup_content;

            $('#popup-buffer .inner .gallery-photo-in-popup').load( function () {

                // скрываем индикатор загрузки
                $('#popup-content-loading').hide();

                height_for_popup_content = $('#popup-buffer').height()+5;

                var height_for_popup_holder = $('#popup-buffer').height()+5+28;
                var height_for_popup_img_holder = $('#popup-buffer').height() - 30;
                var width_for_popup = data.img_width;

                if (data.photos_count > 1) {
                   height_for_popup_content = height_for_popup_content+45;
                   height_for_popup_holder = height_for_popup_holder+45;
                }

                // корректируем высоту под окно
                if ($(window).height() < height_for_popup_content)
                {
                    height_for_popup_img_holder = height_for_popup_img_holder - (height_for_popup_content - $(window).height()) - 55;
                    height_for_popup_holder = $(window).height() - 20;
                    height_for_popup_content = height_for_popup_holder - 30;
                    width_for_popup = width_for_popup / (($('#popup-buffer').height() - 30) / height_for_popup_img_holder);
                    alert('1');
                }

                // задаем высоту контента, чтобы был виден фон
                $('#popup-data').height(height_for_popup_content);

                $('#popup-content-holder').removeClass('hidden').animate({'width': width_for_popup, 'height': height_for_popup_holder, 'left': $(window).width()/2-width_for_popup/2, 'top':$(window).height()/2-(height_for_popup_holder)/2}, 300, function()
                {
                    $('#popup-data').append('<div class="popup-photo-content"></div>');
                    $('#popup-data .arrows').show();
                    if ($('#popup-data .arrows').html() == null)
                    {
                        $('#popup-data .popup-photo-content').append('<div class="title"></div><div class="inner" style="height:'+height_for_popup_img_holder+'px;"></div><div class="arrows"></div>');
                        $('#popup-data .title').html(data.title);
                        $('#popup-data .arrows').html($('#photo-arrows').html());
                        photo_count = data.photos_count;
                        photogallery_id = id;
                    }
                    $('#popup-data .arrows a').show();
                    if (photo_num == 1) $('#popup-data .arrows .a-left').hide();
                    if (photo_num == data.photos_count) $('#popup-data .arrows .a-right').hide();

                    $('#popup-data .inner').css('height', height_for_popup_img_holder);
                    $('#popup-data .inner').html(data.content);
                    $('#popup-close').removeClass('hidden');

                    // подключаем прокрутку мышью
                    $('.gallery-photo-in-popup').bind('mousewheel', function(event, delta) {
                        if (delta < 0) show_next_photo_in_photogallery();
                        else if (delta > 0) show_prev_photo_in_photogallery();
                        return false;
                    });
                });
            });

            //$('#popup-data').height(data.img_height+80);

        }, "json");
    });
}


/***********************************************************************************************************************
* показываем попап с фото из «фишки» площадки
***********************************************************************************************************************/

var feature_module_id = 0;
function show_popup_feature_photo (module_id, item_id, a_id)
{
    $('#popup-data').html('');
    $('#popup-shade').height($(document).height());
    $('#popup-shade').fadeIn(400, function()
    {
        $('#popup-content-loading').show();

        $.post('/ajax/get_photo_from_features', {module_id: module_id, feature_id: item_id, photo_num: photo_num, a_id: a_id}, function(data)
        {
            if (data.status == 0) {
                hide_popup();
                $('#popup-content-loading').hide();
                return false;
            }

            // считаем высоту всего контента через буфер
            $('#popup-buffer').html('');
            $('#popup-buffer').append('<div class="popup-photo-content"><div class="title"><h1>'+$('#'+a_id).html()+'</h1></div><div class="inner"></div></div>');
            $('#popup-buffer .inner').html(data.content);
            var height_for_popup_content;
            $('#popup-buffer .inner .feature-photo-in-popup').load( function () {

                // скрываем индикатор загрузки
                $('#popup-content-loading').hide();

                height_for_popup_content = $('#popup-buffer').height()+5;
                var height_for_popup_holder = $('#popup-buffer').height()+5+28;
                var height_for_popup_img_holder = $('#popup-buffer').height() - 30;
                var width_for_popup = data.img_width;

                if (data.photos_count > 1) {
                   height_for_popup_content = height_for_popup_content+35;
                   height_for_popup_holder = height_for_popup_holder+35;
                }

                // корректируем высоту под окно
                if ($(window).height() < height_for_popup_content)
                {
                    height_for_popup_img_holder = height_for_popup_img_holder - (height_for_popup_content - $(window).height()) - 55;
                    height_for_popup_holder = $(window).height() - 20;
                    height_for_popup_content = height_for_popup_holder - 30;
                    width_for_popup = width_for_popup / (($('#popup-buffer').height() - 30) / height_for_popup_img_holder);
                }

                // задаем высоту контента, чтобы был виден фон
                $('#popup-data').height(height_for_popup_content);

                $('#popup-content-holder').removeClass('hidden').animate({'width': width_for_popup, 'height': height_for_popup_holder, 'left': $(window).width()/2-width_for_popup/2, 'top':$(window).height()/2-(height_for_popup_holder)/2}, 300, function()
                {
                    $('#popup-data').append('<div class="popup-photo-content"></div>');
                    // заполняем заголовок
                    if ($('#popup-data .title').html() == null)
                    {
                        $('#popup-data .popup-photo-content').append('<div class="title"></div>');
                        $('#popup-data .title').html('<h1>'+$('#'+a_id).html()+'</h1>');
                    }

                    // заполняем контент
                    if ($('#popup-data .inner').html() == null)
                    {
                        $('#popup-data .popup-photo-content').append('<div class="inner" style="height:'+height_for_popup_img_holder+'px;"></div>');
                    }

                    // добавляем стрелки, если нужно
                    if ($('#popup-data .arrows').html() == null && data.photos_count > 1)
                    {
                        $('#popup-data .popup-photo-content').append('<div class="arrows"></div>');
                        $('#popup-data .arrows').html('<a href="javascript:;" class="a-left" onclick="show_prev_photo_in_features(\''+a_id+'\')"><img src="/img/interface/arrow_left.png" alt="влево"/></a><a href="javascript:;" class="a-right" onclick="show_next_photo_in_features(\''+a_id+'\')"><img src="/img/interface/arrow_right.png" alt="вправо"/></a>');
                        photo_count = data.photos_count;
                        photogallery_id = item_id;
                        feature_module_id = module_id;
                    }

                    $('#popup-data .arrows a').show();
                    if (photo_num == 1) $('#popup-data .arrows .a-left').hide();
                    if (photo_num == data.photos_count) $('#popup-data .arrows .a-right').hide();

                    $('#popup-data .inner').html(data.content);
                    $('#popup-close').removeClass('hidden');

                    // подключаем прокрутку мышью
                    $('.feature-photo-in-popup').bind('mousewheel', function(event, delta) {
                        if (delta < 0) show_next_photo_in_features(a_id);
                        else if (delta > 0) show_prev_photo_in_features(a_id);
                        return false;
                    });

                    if (data.photos_count > 1) $('#popup-data .arrows').show();
                });
            });
            //$('#popup-data-overflow').height(height_for_popup_content);
        }, "json");
    });
}


/***********************************************************************************************************************
* прячем любой попап
***********************************************************************************************************************/

function hide_popup ()
{
    $('#popup-data').html('');
    $('#popup-close').addClass('hidden');
    //$('#popup-data').hide();
    $('#popup-content-loading').addClass('hidden');
    $('#popup-shade').hide();
    $('#popup-shade').height(0);
    $('#popup-content-holder').width(0).height(0).css('top', $(window).height()/2).css('left', '50%');

    photogallery_id = 0;
    feature_module_id = 0;
    photo_count = 0;
    photo_num = 1;
}


/***********************************************************************************************************************
* навигация по фотографиям в фотогалереях
***********************************************************************************************************************/

function show_next_photo_in_photogallery()
{
    if (photo_num < photo_count)
    {
        photo_num++;
        show_popup_photogallery (photogallery_id, photogallery_module);
    }
    else
    {
        return false;
        //photo_num = 1;
        //show_popup_photogallery (photogallery_id, photogallery_module);
    }
}
function show_prev_photo_in_photogallery()
{
    if (photo_num > 1)
    {
        photo_num--;
        show_popup_photogallery (photogallery_id, photogallery_module);
    }
}


/***********************************************************************************************************************
* навигация по фотографиям в «фишках»
***********************************************************************************************************************/

function show_next_photo_in_features (a_id)
{
    if (photo_num < photo_count)
    {
        photo_num++;
        show_popup_feature_photo (feature_module_id, photogallery_id, a_id);
    }
}
function show_prev_photo_in_features (a_id)
{
    if (photo_num > 1)
    {
        photo_num--;
        show_popup_feature_photo (feature_module_id, photogallery_id, a_id);
    }
}


/***********************************************************************************************************************
* показываем попап «задать вопрос»
***********************************************************************************************************************/

function show_popup_feedback ()
{
    $('#popup-shade').height($(document).height());
    $('#popup-shade').fadeIn(400, function()
    {
        $('#popup-data').html($('#feedback-source').html());
        $('#popup-close').removeClass('hidden');
        $('#popup-content-holder').removeClass('hidden').animate({'width': $('#popup-data').width(), 'height': 340, 'left': $(window).width()/2-$('#popup-data').width()/2, 'top':$(window).height()/2-170}, 300, function() {

        });
    });
}


/***********************************************************************************************************************
* оправляем вопрос от пользователя
***********************************************************************************************************************/
var feedback_process = false;
function send_feedback ()
{
    if (feedback_process) return false;

    $('#feedback_email').removeClass('error');

    if ($('#feedback_name').val() == '') {
        $('#feedback_name').focus(); return false;
    }

    if ($('#feedback_email').val() == '') {
        $('#feedback_email').focus(); return false;
    }

    if (!check_email_format($('#feedback_email').val())) {
        $('#feedback_email').focus().addClass('error'); return false;
    }

    if ($('#feedback_text').val() == '') {
        $('#feedback_text').focus(); return false;
    }

    $('#popup-data form .loading').removeClass('hidden');
    $('#feedback_name').attr('disabled', 'disabled');
    $('#feedback_email').attr('disabled', 'disabled');
    $('#feedback_text').attr('disabled', 'disabled');
    feedback_process = true;
    $.post('/ajax/new_feedback', {f_name: $('#feedback_name').val(), f_email: $('#feedback_email').val(), f_text: $('#feedback_text').val()}, function(data)
    {
        $('#popup-data form .loading').addClass('hidden');
        if (data.status == 1)
        {
            $('#popup-data').height( $('#popup-data').height() );
            $('#popup-data .feedback-form').animate({'height': 0}, 300, function() {
                $('#popup-data .feedback-form').remove();
                $('#popup-data').append('<div class="feedback-success" style="display:none;">Спасибо, Ваш вопрос принят.</div>');
                $('#popup-data .feedback-success').fadeIn();
            });
            feedback_process = false;
        }
    }, "json");
}


/***********************************************************************************************************************
* двигаем ленту с афишей
***********************************************************************************************************************/
var eventsline_timer_id = null;
var eventsline_speed = 5;
var eventsline_start_margin = 100;
var speed_increase_counter = 0;
function start_move_eventsline (direction)
{
    if ($('#eventsline').width() < $('#site-wrap').width()-100) return false;

    stop_move_eventsline();

    if (direction == 'left')
    {
        eventsline_timer_id = setInterval("move_eventsline('left')", 30);
    }
    else if (direction == 'right')
    {
        eventsline_timer_id = setInterval("move_eventsline('right')", 30);
    }
}

function stop_move_eventsline ()
{
    if (eventsline_timer_id != null) {
        clearInterval(eventsline_timer_id);
    }
    eventsline_timer_id = null;
    eventsline_speed = 5;
    speed_increase_counter = 0;
}

function move_eventsline(direction)
{
    if (eventsline_speed < 1)
    {
        eventsline_speed = 1
    }

    var ul_left = 100;
    speed_increase_counter++;

    if (direction == 'right')
    {
        ul_left = $('#eventsline').css('margin-left').replace('px', '');
        if (ul_left <= eventsline_start_margin - ($('#eventsline').width() - ($('#site-wrap').width() - 100))) {
            stop_move_eventsline();
            return false;
        }
        ul_left = ul_left-eventsline_speed;
        $('#eventsline').css('margin-left', ul_left);
    } else if (direction == 'left') {
        ul_left = $('#eventsline').css('margin-left').replace('px', '');
        if (ul_left >= 100) {
            stop_move_eventsline();
            return false;
        }
        ul_left = parseInt(ul_left)+parseInt(eventsline_speed);
        $('#eventsline').css('margin-left', ul_left);
    }

    if (speed_increase_counter > 10) {
        speed_increase_counter = 0;
        eventsline_speed++;
    }
}



/***********************************************************************************************************************
* показывем попап с информацией о событии
***********************************************************************************************************************/

function show_popup_event_info (event_id)
{
    $('#popup-data').html('');
    $('#popup-shade').height($(document).height());
    $('#popup-shade').fadeIn(400, function()
    {
        $('#popup-content-loading').show();

        $.post('/ajax/get_event_info', {event_id: event_id}, function(data)
        {
            if (data.status == 0) {
                hide_popup();
                return false;
            }

            // скрываем индикатор загрузки
            $('#popup-content-loading').hide();

            // считаем высоту всего контента через буфер
            $('#popup-buffer').html('');
            $('#popup-buffer').append('<div class="popup-event-content">'+data.content+'</div>');

            var height_for_popup_content;
            var width_for_popup_content = $('.popup-event-content').width()+90;

            // создаем буфер
            var tmp_div = $('<div id="tmp-buf" class="popup-event-content"></div>');
            $(tmp_div).html(data.content);
            $('body').append(tmp_div);

            height_for_popup_content = $('#tmp-buf .popup-event-content h1').height()+8+$('#tmp-buf .popup-event-content .event-short-info').height()+20+$('#tmp-buf .popup-event-content .event-text').height()+34+35;
            //height_for_popup_content = $('#popup-buffer .popup-event-content h1').height()+8+$('#popup-buffer .popup-event-content .event-short-info').height()+20+$('#popup-buffer .popup-event-content .event-text').height()+34+35;

            if($('#tmp-buf .event-desc').children('.event-middle-photo').size() > 0)
            {
                $('#tmp-buf .event-middle-photo').load(function() {

                    height_for_popup_content = $('#tmp-buf').height();
                    //alert(height_for_popup_content);
                    $('#tmp-buf').remove();

                    // задаем высоту контента, чтобы был виден фон
                    $('#popup-data').height(height_for_popup_content);

                    $('#popup-content-holder').removeClass('hidden').animate({'width': width_for_popup_content, 'height': height_for_popup_content+28, 'left': $(window).width()/2-width_for_popup_content/2, 'top':$(window).height()/2-height_for_popup_content/2-14}, 300, function()
                    {
                        // заполняем контент
                        if ($('#popup-data .popup-event-content').html() == null)
                        {
                            $('#popup-data').append('<div class="popup-event-content"></div>');
                        }

                        $('#popup-data .popup-event-content').html(data.content);
                        $('#popup-close').removeClass('hidden');
                    });

                    //height_for_popup_content = height_for_popup_content + $('#tmp-buf .popup-event-content .event-desc .event-middle-photo').attr('height') + parseInt($('#tmp-buf .popup-event-content .event-desc .event-middle-photo').css('marginBottom').replace('px', ''));
                    //alert($('#popup-buffer .popup-event-content .event-desc .event-middle-photo').attr('height'));
                });
            }
            else {
                height_for_popup_content = $('#tmp-buf').height();

                $('#tmp-buf').remove();

                // задаем высоту контента, чтобы был виден фон
                $('#popup-data').height(height_for_popup_content);

                $('#popup-content-holder').removeClass('hidden').animate({'width': width_for_popup_content, 'height': height_for_popup_content+28, 'left': $(window).width()/2-width_for_popup_content/2, 'top':$(window).height()/2-height_for_popup_content/2-14}, 300, function()
                {
                    // заполняем контент
                    if ($('#popup-data .popup-event-content').html() == null)
                    {
                        $('#popup-data').append('<div class="popup-event-content"></div>');
                    }

                    $('#popup-data .popup-event-content').html(data.content);
                    $('#popup-close').removeClass('hidden');
                });
            }

            /*if($('#popup-buffer .popup-event-content .event-desc').children('.event-middle-photo').size() > 0)
            {
                height_for_popup_content = height_for_popup_content + $('#popup-buffer .popup-event-content .event-desc .event-middle-photo').attr('height') + parseInt($('#popup-buffer .popup-event-content .event-desc .event-middle-photo').css('marginBottom').replace('px', ''));
            }*/
        }, "json");
    });
}


/***********************************************************************************************************************
* двигаем слайды верхней большой галереи
***********************************************************************************************************************/

var prevent_top_slides_move = 150;
var current_top_slides_left = 0;
var current_top_slide = 1;

function top_slides_init ()
{
    $('#top-slides-holder ul').width( $('#top-slides-holder').width() * $('#top-slides-holder ul li').size() );
    $('#top-slides-holder ul li').width( $('#top-slides-holder').width() );

    if ($('#top-slides-holder ul li').size() > 1)
    {
        $('#top-slides-holder ul').draggable({ axis: 'x', start: function(event, ui) {  }, stop: function(event, ui) {

            var ul_offset = $('#top-slides-holder ul').position();
            // если мало подвинули влево
            if ( (ul_offset.left < current_top_slides_left && current_top_slides_left-ul_offset.left<prevent_top_slides_move) || (ul_offset.left < current_top_slides_left && current_top_slide == $('#top-slides-holder ul li').size()) )
            {
                $('#top-slides-holder ul').animate({'left' : current_top_slides_left}, 300, function() { });
            }
            // если достаточно подвинули влево
            else if ( ul_offset.left < current_top_slides_left && current_top_slides_left-ul_offset.left>=prevent_top_slides_move && current_top_slide < $('#top-slides-holder ul li').size() )
            {
                if (top_slides_type == 'stars' || top_slides_type == 'events')
                {
                    $('#top-slides-holder ul').animate({'left' : current_top_slides_left - $('#top-slides-holder ul li').width()}, 300, function() {
                        current_top_slides_left = $('#top-slides-holder ul').position().left;
                        current_top_slide++;
                        top_slides_moving = false;
                        if (top_slides_type == 'stars') { fill_star_info(); }
                        else if (top_slides_type == 'events') fill_event_info();
                        show_arrows(true, 'topslides');
                    });
                }
                else
                {
                    $('#top-slides-holder ul').animate({'left' : current_top_slides_left - $('#top-slides-holder ul li').width()}, 300, function() {
                        current_top_slides_left = $('#top-slides-holder ul').position().left;
                        current_top_slide++;
                        show_arrows(true, 'topslides');
                    });
                }
            }
            // если мало подвинули вправо
            else if ( (ul_offset.left > current_top_slides_left && (current_top_slides_left*-1)-(ul_offset.left*-1)<prevent_top_slides_move) || (ul_offset.left > current_top_slides_left && current_top_slide == 1) )
            {
                $('#top-slides-holder ul').animate({'left' : current_top_slides_left}, 300);
            }
            // если достаточно подвинули вправо
            else if ( ul_offset.left > current_top_slides_left && (current_top_slides_left*-1)-(ul_offset.left*-1)>=prevent_top_slides_move && current_top_slide > 1 )
            {
                if (top_slides_type == 'stars' || top_slides_type == 'events')
                {
                    $('#top-slides-holder ul').animate({'left' : current_top_slides_left + $('#top-slides-holder ul li').width()}, 300, function() {
                        current_top_slides_left = $('#top-slides-holder ul').position().left;
                        current_top_slide--;
                        top_slides_moving = false;
                        if (top_slides_type == 'stars') { fill_star_info(); }
                        else if (top_slides_type == 'events') fill_event_info();
                        show_arrows(true, 'topslides');
                    });
                }
                else
                {
                    $('#top-slides-holder ul').animate({'left' : current_top_slides_left + $('#top-slides-holder ul li').width()}, 300, function() {
                        current_top_slides_left = $('#top-slides-holder ul').position().left;
                        current_top_slide--;
                        show_arrows(true, 'topslides');
                    });
                }
            }
            }
        });
        $('#top-slides-holder ul').addClass('movable');
    }
}

var top_slides_moving = false;
function move_top_slides (direction)
{
    if (top_slides_moving) return false;
    var wrap_width = $('#top-slides-holder').width();

    if (direction == 'left')
    {
        if (current_top_slide > 1)
        {
            top_slides_moving = true;
            $('#top-slides-holder ul').animate({'left' : parseInt($('#top-slides-holder ul').css('left').replace('px', '')) + wrap_width }, 300, function() {
                current_top_slides_left = $('#top-slides-holder ul').position().left;
                current_top_slide--;
                top_slides_moving = false;
                show_arrows(true, 'topslides');
            });
        }
    }
    else if (direction == 'right')
    {
        if (current_top_slide < $('#top-slides-holder ul li').size())
        {
            top_slides_moving = true;
            $('#top-slides-holder ul').animate({'left' : $('#top-slides-holder ul').css('left').replace('px', '')-wrap_width }, 300, function() {
                current_top_slides_left = $('#top-slides-holder ul').position().left;
                current_top_slide++;
                top_slides_moving = false;
                show_arrows(true, 'topslides');
            });
        }
    }
}


function top_slides_check ()
{
    if ($('#top-slides-holder').html() != null)
    {
        $('#top-slides-holder ul li').width( $('#site-wrap').width() );
        $('#top-slides-holder ul').width( $('#site-wrap').width() * $('#top-slides-holder ul li').size() );
        $('#top-slides-holder ul').css('left', (-1 * (current_top_slide-1) * $('#site-wrap').width()) + 'px');
        current_top_slides_left = $('#top-slides-holder ul').position().left;
    }
}

function stripes_check ()
{
    if ($('#photoline').html() != null)
    {
        ul_left = $('#photoline').css('margin-left').replace('px', '');
        if (ul_left <= start_margin - ($('#photoline').width() - ($('#site-wrap').width() - 100)))
        {
            $('#photoline').css('margin-left',  (start_margin - ($('#photoline').width() - ($('#site-wrap').width() - 100))) + 'px');
        }
    }

    if ($('#eventsline').width() > $('#site-wrap').width())
    {
        ul_left = $('#eventsline').css('margin-left').replace('px', '');
        if (ul_left <= start_margin - ($('#eventsline').width() - ($('#site-wrap').width() - 100)))
        {
            $('#eventsline').css('margin-left',  (start_margin - ($('#eventsline').width() - ($('#site-wrap').width() - 100))) + 'px');
        }
    }
}



/***********************************************************************************************************************
* активируем Звезду
***********************************************************************************************************************/
var current_slide_in_stars = 1;

function select_star (star_id)
{
    $('.stars li').removeClass('active');
    $('#star-'+star_id).addClass('active');
    $('.stars li').each (function(a, b) {
        if ($(b).attr('id') == 'star-'+star_id)
        {
             $('html, body').animate({scrollTop:100}, 300, function(){
                 var new_slide_num = parseInt($(b).attr('class').replace(' active', '').replace('li-star-', ''));

                 if (new_slide_num > current_top_slide)
                 {
                     move_top_slides_in_stars('right', new_slide_num-current_top_slide);
                 }
                 else if (new_slide_num < current_top_slide)
                 {
                     move_top_slides_in_stars('left', current_top_slide-new_slide_num);
                 }
             });
        }
    });
}

/***********************************************************************************************************************
* прокручиваем слайдер в Звездах
***********************************************************************************************************************/

function move_top_slides_in_stars (direction, slides_count)
{
    if (top_slides_moving) return false;
    var wrap_width = $('#top-slides-holder').width();
    $('.star-full-info h1').html('');
    $('.star-full-info .full-desc').html('');
    $('.star-full-info .photos').addClass('hidden');
    $('.star-full-info .photos .holder').html('');

    if (direction == 'left')
    {
        if (current_top_slide > 1)
        {
            top_slides_moving = true;
            $('#top-slides-holder ul').animate({'left' : parseInt($('#top-slides-holder ul').css('left').replace('px', '')) + wrap_width*slides_count }, 300, function() {
                current_top_slides_left = $('#top-slides-holder ul').position().left;
                //current_top_slide--;
                top_slides_moving = false;
                current_top_slide = current_top_slide - slides_count;

                if (top_slides_type == 'stars') { fill_star_info(); }
                else if (top_slides_type == 'events') fill_event_info();

                show_arrows(true, 'topslides');
            });
        }
    }
    else if (direction == 'right')
    {
        if (current_top_slide < $('#top-slides-holder ul li').size())
        {
            top_slides_moving = true;
            $('#top-slides-holder ul').animate({'left' : $('#top-slides-holder ul').css('left').replace('px', '')-wrap_width*slides_count }, 300, function() {
                current_top_slides_left = $('#top-slides-holder ul').position().left;
                //current_top_slide++;
                top_slides_moving = false;
                current_top_slide = current_top_slide + slides_count;

                if (top_slides_type == 'stars') { fill_star_info(); }
                else if (top_slides_type == 'events') fill_event_info();

                show_arrows(true, 'topslides');
            });
        }
    }
}

function fill_star_info()
{
    $('.stars li').removeClass('active');
    $('.stars li.li-star-'+current_top_slide).addClass('active');
    if (!$('.top-slide-'+current_top_slide+' .img-src').hasClass('activated'))
    {
        $('.top-slide-'+current_top_slide).append('<div style="background:url('+$('.top-slide-'+current_top_slide+' .img-src').html()+') no-repeat center 0; width:100%; height:700px;"></div>');
        $('.top-slide-'+current_top_slide+' .img-src').addClass('activated');
    }
    $('.star-full-info h1').html($('.top-slide-'+current_top_slide+' .h').html());
    $('.star-full-info .full-desc').html($('.top-slide-'+current_top_slide+' .txt').html());

    $('.star-full-info .photos .holder').html('');
    $('.star-full-info .photos').addClass('hidden');
    if ($('.top-slide-'+current_top_slide+' .photoalbum').html() != null)
    {
        $('.star-full-info .photos .holder').html($('.top-slide-'+current_top_slide+' .photoalbum').html());
        $('.star-full-info .photos').removeClass('hidden');
    }
}


function fill_event_info()
{
    if (!$('.top-slide-'+current_top_slide+' .img-src').hasClass('activated'))
    {
        $('.top-slide-'+current_top_slide).append('<div style="background:url('+$('.top-slide-'+current_top_slide+' .img-src').html()+') no-repeat center 0; width:100%; height:700px;"></div>');
        $('.top-slide-'+current_top_slide+' .img-src').addClass('activated');
    }
    $('.event-full-info h1').html($('.top-slide-'+current_top_slide+' .h').html());
    $('.event-full-info .full-desc').html($('.top-slide-'+current_top_slide+' .txt').html());
    $('.event-full-info .tickets-inner .phones').html($('.top-slide-'+current_top_slide+' .phones').html());
    $('.event-full-info .tickets-inner .btn-holder').html('');
    if ($('.top-slide-'+current_top_slide+' .buy-tickets').html() != '')
    {
        $('.event-full-info .tickets-inner .btn-holder').html('<a href="javascript:;" onclick="show_popup_event_tickets_info('+current_top_slide+')"><img src="/img/interface/tickets_btn_buy.png" alt=""/></a>');
        $('.event-full-info .tickets-inner .btn-holder').removeClass('hidden');
    }
    else $('.event-full-info .tickets-inner .btn-holder').addClass('hidden');
    $('.event-full-info .tickets').removeClass('hidden');
}


function highlight_events (stage_id, a)
{
    $('.events-bill-holder .stages li').removeClass('active');
    $(a).parent().addClass('active');
    if (stage_id == 0)
        $('.events-bill-holder .lines-holder li').addClass('highlighted');
    else
    {
        $('.events-bill-holder .lines-holder li').removeClass('highlighted');
        $('.events-bill-holder .lines-holder li.stage-'+stage_id).addClass('highlighted');
    }
}



/***********************************************************************************************************************
* показывем попап с информацией о покупке билетов
***********************************************************************************************************************/

function show_popup_event_tickets_info (event_num)
{
    $('#popup-data').html('');
    $('#popup-shade').height($(document).height());
    $('#popup-shade').fadeIn(400, function()
    {
        $('#popup-content-loading').show();

        // скрываем индикатор загрузки
        $('#popup-content-loading').hide();

        // считаем высоту всего контента через буфер
        $('#popup-buffer').html('');
        $('#popup-buffer').append('<div class="popup-event-tickets-content">'+$('.top-slide-'+event_num+' .buy-tickets').html()+'</div>');

        var height_for_popup_content;
        var width_for_popup_content = $('.popup-event-tickets-content').width()+40;

        // создаем буфер и считаем высоту
        var tmp_div = $('<div id="tmp-buf" class="popup-event-tickets-content"></div>');
        $(tmp_div).html($('.top-slide-'+event_num+' .buy-tickets').html());
        $('body').append(tmp_div);
        height_for_popup_content = $('#tmp-buf').height()+45;
        $('#tmp-buf').remove();

        // задаем высоту контента, чтобы был виден фон
        $('#popup-data').height(height_for_popup_content);

        $('#popup-content-holder').removeClass('hidden').animate({'width': width_for_popup_content, 'height': height_for_popup_content+28, 'left': $(window).width()/2-width_for_popup_content/2, 'top':$(window).height()/2-height_for_popup_content/2-14}, 300, function()
        {
            // заполняем контент
            if ($('#popup-data .popup-event-tickets-content').html() == null)
            {
                $('#popup-data').append('<div class="popup-event-tickets-content"></div>');
            }

            $('#popup-data .popup-event-tickets-content').html($('.top-slide-'+event_num+' .buy-tickets').html());
            $('#popup-close').removeClass('hidden');
        });
    });
}
