var vi={
	dir:"/script/action/videoindex/data/",
	init:function(){
		vi.e={l:$("#List")};
		vi.e.l.html("<h3>正在载入视频列表，请稍等……</h3>");
		$.get(vi.dir+"list.txt",function(d){
			eval("var r="+d);
			var s="<link rel='stylesheet' href='/script/action/videoindex/index.css'/><div id='MO'></div><div id='VS'></div>",i,o,f=null;
			//保存一个按日期为索引的对象
			vi.r={};
			for(i in r){
				o=r[i];
				if(f==null){f=o.d;}
				vi.r[o.d]=o;
/*				if(o.d.indexOf(" ")>=0||o.d.split("-").length!=3){continue;}
				s+="<div class='d' onclick='vi.v("+i+")'>\
<h3 class='t' onmouseover='vi.hide_v()'>"+o.d+"("+o.m+"条视频)</h3>\
<div id='D"+o.d+"' class='vs' style='display:none'></div></div>";
*/
			}
			vi.e.l.html(s);
			vi.month(f);
		});
	},
	get:function(d){
		return this.r[d];
/*		var i,o;
		for(i in this.r){
			o=this.r[i];
			if(o.d==d){return o;}
		}
		return null;
*/
	},
	//显示指定月份的表格
	month:function(d){
		if(typeof d=="string"){
			d=d.split("-");
			if(d.length<2){alert("日期格式有误");return;}
			if(d.length<3){d[2]=1;}
			d=new Date(d[0],d[1]-1,d[2]);
		}
		var y=d.getFullYear(),m=d.getMonth()+1,date=d.getDate(),
			yp=(y-1)+"-"+m+"-"+date,yn=(y+1)+"-"+m+"-"+date,
			mp=y+"-"+(m-1)+"-"+date,mn=y+"-"+(m+1)+"-"+date;
		$("#MO").html("<div class='row_ym'><div id='YP' onclick='vi.month(\""+yp+"\")'>←</div>\
<div id='Year'>"+d.getFullYear()+"</div><div id='YN' onclick='vi.month(\""+yn+"\")'>→</div></div>\
<div class='clear'></div>\
<div class='row_ym'><div id='MP' onclick='vi.month(\""+mp+"\")'>←</div>\
<div id='Month'>"+(d.getMonth()+1)+"</div><div id='MN' onclick='vi.month(\""+mn+"\")'>→</div></div>\
<div id='Days'></div>\
<div class='clear'></div>");
		var s="",i,days=new Date(y,m-1,0).getDate(),o,day1,dayl;
		d=new Date(y,m-1,1);
		day1=d.getDay();
		//顯示在1前面的空格
		for(i=day1-1;i>=0;i--){s+="<div></div>";}
		for(i=1;i<=days;i++){
			d=y+"-"+(m<10?"0"+m:m)+"-"+(i<10?"0"+i:i);
			o=vi.get(d);
			s+="<div d='"+d+"' id='D"+i+"'"+(o?" onclick='vi.v(\""+d+"\")' class='c'":"")+">"+i+(o?"<span class='m'>("+o.m+")</span>":"")+"</div>";
		}
		dayl=new Date(y,m-1,i).getDay();
		for(i=7-dayl;i>0;i--){s+="<div></div>";}
		s+="<p class='clear'></p>";
		$("#Days").html(s);
	},
	v:function(i){
		var o=vi.get(i);
		if(typeof o.vs=="object"){vi.show_v(o.vs);}
		else{
			$.get(vi.dir+i+".txt",function(d){
				eval("var r="+d);
				var o=vi.get(r.d);
				if(o){o.vs=r;}
				vi.show_v(r);
			});
		}
	},
	show_v:function(r){
		var s="<h3>"+r.d+"播出视频</h3>",i,e=$("#VS");
		for(i in r.vos){
			o=r.vos[i];
			s+="<div class='v'><a href='"+o.URL+"' target='_blank'>"+o.Title+"</a></div>";
		}
		e.html(s);
	}
}
window.onload=vi.init;

