!function(){
	var layout = $('#status'),
		l = function(selector){
			return layout.find(selector);
		},
		content = l('.content'),
		index = 0;
	
	var runTime = l('.runtime span'), h = m = s = 0;
	setInterval(function(){
			if(s < 59) {
				s++;
			} else {
				s = 0; m++;
				if(m > 59) {
					m = 0; h++;
				}
			}
			runTime.html((h < 10 ? '0' + h : h) + '时' + (m < 10 ? '0' + m : m) + '分' + (s < 10 ? '0' + s : s) + '秒');		
	}, 1000);
	
	var Notice = (function(){
		var notices =  [];
		
		return {
			init: function(){
				var self =  this;
				self.change();
				setInterval(function(){
					self.change();
				}, 1000 * 30);
				content.click(function(){
					self.show($(this).attr('href'));
					return false;
				});
			},
			show: function(id){
				Dialog.alert({
					title: '官方公告',
					content: '<iframe frameborder="0" width="550" height="350" src="'+Dwd.makeFullPath('DefaultPage/notice/noticeshow.asp?id=' + id)+'&t='+Math.random()+'"></iframe>',
					style: {
						overflow: 'auto'
					}
				});
			},
			change: function(){
				if(notices.length && notices[index]){
					var notice = notices[index];
					content.text(decodeURI(notice.title));
					content.attr('href', notice.id);
					index++;
				}else{
					index = 0;
					this.get();
				}
			},
			get: function(){
				var self = this;
				var thisAction = arguments.callee;
				if(isActionRunning(thisAction, 1000 * 60 * 10)) return false;
				Dwd.interface('读取公告', 'notice/notice.asp',{
					action: 'getTitleList',
					code: '官方公告'
				}, function(result, errMsg){
					thisAction.ing = false;
					if(!result){
						//alert(errMsg);
						return false;
					}
					
					index = 0;
					notices = result.list;
					self.change();
				});				
			}
		}
	})();

	window.Notice = Notice;

	Dwd.loginSuccess(function(){
		Notice.init();
	});
}();