//---------------------------------------------------------------------------------
$(document).ready(function(){//----------------------------------------------------
//---------------------------------------------------------------------------------
// Фотогалерея
$("a[rel='photo']").fancybox();
// Смена новостей-картинок
setInterval(update_main_news, 12000);
// Настройки бегущей строки
$jScroller.config.refresh = 40;
$jScroller.add("#jScroller_outer", "#jScroller_inner", "left", 1, true);
$jScroller.start();

// Количество заголовков на панелях
$('div.limits_block a').click(function()
{
    limit_block = $(this).parent('div').attr('limit_block');
    limit = $(this).html();
    
    $.post('/inc/ajax.inc.php', { limit_block: limit_block, limit: limit }, function(txt)
	{
        if (txt == '')
            window.location.reload();
        else
            alert(txt);
	}, 'text');
});
//
$('#login_email').focus(function()
{
    if (typeof bg_login_email == 'undefined')
        bg_login_email = $(this).css('background');
    $(this).css('background', '#fff');
}).blur(function()
{
    if ($(this).val() == '' && bg_login_email !== undefined)
        $(this).css('background', bg_login_email);
});
//
$('#login_pass').focus(function()
{
    if (typeof bg_login_pass == 'undefined')
        bg_login_pass = $(this).css('background');
    $(this).css('background', '#fff');
}).blur(function()
{
    if ($(this).val() == '' && bg_login_pass !== undefined)
        $(this).css('background', bg_login_pass);
});
//
$('#submenu_rubrics').click(function()
{
    $('#submenu_tags_div').hide();
    $('#submenu_more_div').hide();
    $('#submenu_rubrics_div').toggle();
});
//
$('#submenu_tags').click(function()
{
    $('#submenu_rubrics_div').hide();
    $('#submenu_more_div').hide();
    $('#submenu_tags_div').toggle();
});
//
$('#submenu_more').click(function()
{
    $('#submenu_rubrics_div').hide();
    $('#submenu_tags_div').hide();
    $('#submenu_more_div').toggle();
});
//

$('div.sq1-item a img').mouseover(function()
{
    $('div.img-alt-outer').hide();
	obj = $(this).parents('div.sq1-item').prev('div.img-alt-outer');
    if (navigator.appName != 'Microsoft Internet Explorer')
        obj.css('left', obj.attr('left'));

	obj.mouseover(function() 
	             {
					$(this).show();
				 });
    obj.show();
});

//
$('div.sq1-item a img').mouseout(function()
{
    $(this).parents('div.sq1-item').prev('div.img-alt-outer').hide();
});
//
$('#send_to_friend').click(function()
{
    $('#popup_friend_email').toggle();
});
//
$('#send_message_error').click(function()
{
    $('#popup_message_error').toggle();
});
//
$('#send_noresults_handbook').click(function()
{
    if (window.confirm('Действительрно отправить запрос?'))
    {
        $.post('/inc/ajax.inc.php', { send_noresults_handbook: $(this).attr('s'), user_id: $(this).attr('user_id') }, function(json)
    	{
    	   
    	}, 'json');
    }
});
// подписка на новости незарегистрированных пользователей
$('#subscriber_button').click(function()
{
    $.post('/inc/ajax.inc.php', { add_subscriber_email: $('#subscriber_email').val() }, function(txt)
	{
        if (txt == '')
            $('#block_subscriber').css('color', 'red').html('e-mail "' + $('#subscriber_email').val() + '" добавлен в список рассылки.');
        else
            $('#block_subscriber').css('color', 'red').html(txt);
	}, 'text');
});
//
$('#friend_email').click(function()
{
    $('#popup_friend_email').hide();
    $.post('/inc/ajax.inc.php', { send_to_friend: $(this).prev('input').val(), link: window.location.href }, function(json)
	{
	   
	}, 'json');
});
//
$('#message_error').click(function()
{
    $('#popup_message_error').hide();
    $.post('/inc/ajax.inc.php', { send_message_error: $(this).prev('textarea').val(), link: window.location.href }, function(json)
	{
	   
	}, 'json');
});
//
$('#perfomers_chars a').click(function()
{
    $('#perfomers_chars').next('ul.block-list').html('').after(get_loading('text-align:center; margin-top:30px;'));
    $.post('/inc/ajax.inc.php', { get_perfomers_by_letter: $(this).html() }, function(json)
	{
	   $('#perfomers_chars').next('ul.block-list').html(json.data).next('div.loading').remove();
	}, 'json');
});
// показать результаты опросы
$('#show_block_poll_results').css('cursor', 'pointer').css('text-decoration', 'underline').click(function()
{
    $('#block_poll_poll').hide();
    $('#block_poll_results').show();
});
// голосование
$('#block_poll_poll input[type=button]').click(function()
{
    answer_id = $('#block_poll_poll input[type=radio]:checked').val();
    $('#block_poll_poll').after(get_loading('text-align:center; margin:20px 0px;')).remove()
    $.post('/inc/ajax.inc.php', { answer_id: answer_id }, function(json)
	{
	   if (json.status == 1)
       {
            $('#poll_answer_' + answer_id).html(parseInt($('#poll_answer_' + answer_id).html()) + 1);
            $('#block_poll_results').show().prev('div.loading').remove();
       }
	}, 'json');
});
// всплывающие подсказки блоков новостей
$('div.block div.f-block img').css('cursor', 'pointer').hover(function()
{
	$(this).parents('div.block').find('div.info').toggle();
});

$('div.photosline div.photo-f img').css('cursor', 'pointer').hover(function()
{
	$(this).parents('div.photosline').find('div.info').toggle();
});

$('div.subscribe-block').hover(function()
{
	$(this).toggle();
});

//в фотогалереях скрывает последний пустой td
$('.photo-table').find('.empty_td:last').hide();


//---------------------------------------------------------------------------------
});//------------------------------------------------------------------------------
//---------------------------------------------------------------------------------

function update_main_news()
{
    new_num = rand(0, 5);
    
    news_ids = [];
    $('div.sq1-item').each(function()
    {
        news_ids.push($(this).attr('new_id'));
    });
    
    
	if (news_ids.length)
	$.post('/inc/ajax.inc.php', { main_news_ids: news_ids.join(',') }, function(json)
	{
	   if (json.status == 1)
       {
            json_new_0_id = json.new_0_id; json_new_0_image = json.new_0_image; json_new_0_link = json.new_0_link; json_new_0_title = json.new_0_title;
            json_new_1_id = json.new_1_id; json_new_1_image = json.new_1_image; json_new_1_link = json.new_1_link; json_new_1_title = json.new_1_title;
            json_new_2_id = json.new_2_id; json_new_2_image = json.new_2_image; json_new_2_link = json.new_2_link; json_new_2_title = json.new_2_title;
            json_new_3_id = json.new_3_id; json_new_3_image = json.new_3_image; json_new_3_link = json.new_3_link; json_new_3_title = json.new_3_title;
            json_new_4_id = json.new_4_id; json_new_4_image = json.new_4_image; json_new_4_link = json.new_4_link; json_new_4_title = json.new_4_title;
            json_new_5_id = json.new_5_id; json_new_5_image = json.new_5_image; json_new_5_link = json.new_5_link; json_new_5_title = json.new_5_title;
            
            // смена картинок
            setTimeout('update_main_new(0, json_new_0_id, json_new_0_image, json_new_0_link, json_new_0_title)', 4000);
            setTimeout('update_main_new(1, json_new_1_id, json_new_1_image, json_new_1_link, json_new_1_title)', 8000);
            setTimeout('update_main_new(2, json_new_2_id, json_new_2_image, json_new_2_link, json_new_2_title)', 0);
            setTimeout('update_main_new(3, json_new_3_id, json_new_3_image, json_new_3_link, json_new_3_title)', 6000);
            setTimeout('update_main_new(4, json_new_4_id, json_new_4_image, json_new_4_link, json_new_4_title)', 2000);
            setTimeout('update_main_new(5, json_new_5_id, json_new_5_image, json_new_5_link, json_new_5_title)', 10000);
       }
	}, 'json');
}

function update_main_new(new_num, new_id, new_image, new_link, new_title)
{
    $('div.sq1-item').eq(new_num).fadeOut(1000, function()
    {
        $('div.sq1-item').eq(new_num).attr('new_id', new_id);
        $('div.sq1-item').eq(new_num).attr('style', "background:url('" + new_image + "') center no-repeat;");
        $('div.sq1-item').eq(new_num).children('a').attr('href', new_link);
        $('div.sq1-item').eq(new_num).prev('div.img-alt-outer').find('div.img-alt-middle-inner').html(new_title);
    });
    $('div.sq1-item').eq(new_num).fadeIn(1000);
}

function get_loading(style, src)
{
	if (src == undefined) src = 'loading.gif';
	if (style == undefined) style = '';
	return '<div class="loading" style="' + style + '"><img src="img/' + src + '" alt="идет загрузка..." title="идет загрузка..."></div>';
}
