var lab_num_unread_sms;
var box_inside_notice;
var box_outside_notice;
var lst_categories;

function init_ui()
{
	
	lab_num_unread_sms	= $('span#labNumUnreadMsg');
	box_inside_notice = $('div#box_inside_notice');
	box_outside_notice	= $('div#box_outside_notice');
	lst_categories = $('select#lst_categories');
}

$(document).ready(function(){
	
	init_ui();

	// 打开首页读取未读短信数量，以后每隔30秒钟开始读取一次未读短信数量。
	load_num_unread_sms();
	$(this).everyTime('30s', 'load_num_unread_sms', function(){
		load_num_unread_sms();
	});
	
	box_inside_notice.hover( // 鼠标悬停，停止滚动字幕。
		function(){ $(this).stop(true); },
		function(){ display_notice() }
	);
	
	box_inside_notice.css({	"margin-top": "160px" });
	display_notice();
	
	// 快速通道跳转
	lst_categories.change(open_galley_category);
});

// 点击在线影展的快速通道，就直接打开搜索查看指定的分类。
function open_galley_category(){
	var id = lst_categories.find('option:selected').val();
	if(id == 0)
	{
		return;
	}
	var url = 'controllers/gallery/gallery.php?category=' + id;
	if(window.open(url, '_blank') == null)
	{
		alert('弹出窗口被您的浏览器禁用了，请永远允许本站点弹出窗口。');
	}
}

// 滚动字幕
function display_notice(){
	
	
	box_inside_notice.animate(
		{
			"margin-top": box_inside_notice.height() * -1
		}, 30000,
		function()
		{
			box_inside_notice.css({	"margin-top": "160px" });
			display_notice();
		}
	);
}

// 定时读取未读短信
function load_num_unread_sms(){
	
	$.ajax({
		async: true,
		url: "controllers/userspace/load_num_unread_sms.php",
		dataType: "json",
		beforeSend:
			function()
			{
				lab_num_unread_sms.empty();
				lab_num_unread_sms.append('<img src="styles/images/loading.gif" alt="loading" />');
			},
		success:
			function(data)
			{
				lab_num_unread_sms.empty();
				if(data.error != undefined)
				{
					lab_num_unread_sms.append('err');
					return;
				}
				lab_num_unread_sms.append(data.num_unread);
			},
		error:
			function()
			{
				lab_num_unread_sms.empty();
				lab_num_unread_sms.append('err');
			}
	});
}
