//博客首页 2011-7-15
var objAjax = new JAjax();
function createObject(){
	return function(){
		this.load.apply(this,arguments);	
	}
}

var musicClass=null;
//博客首页 2011-7-19
setTimeout("loadPageMusic()",500);
function loadPageMusic(){
	musicClass=new musicObject();	
}
var musicObject=new createObject();
//初始化执行
musicObject.prototype.load=function(){
	this.musicTabDiv=$("musicTabDiv");
	this.musicTabBodyDiv=$("musicTabBodyDiv");
	this.useType=urlPar("useType");//获取当前的群信息
	
	this.pagesize=16;//每页数量
	this.page=1;//当前页数
	this.pages=0;//总页数
	this.pagecount=0;//数据总条数
	
	if(this.typeMenuID==null){
		this.typeMenuID=0;	
	}
	if(this.useType==null){
		this.useType=0;
	}
	
	this.user=urlPar("user");
	if(this.user==null){		
		this.user=userName;
	}	

	this.isBunch=isBunch;
	for(var i=0;i<this.musicTabDiv.childNodes.length;i++){
		if(i==0)
		this.selTabObj=this.musicTabDiv.childNodes[0];
		this.musicTabDiv.childNodes[i].onclick=function(){
				musicClass.clickTab(this);	
		}
	}		
	if(this.isBunch=="0"){
		this.tab=menuTabMusic;
		this.musicTabDiv.childNodes[0].innerHTML="用户音乐";	
		this.musicTabDiv.childNodes[1].innerHTML="大家音乐";	
		this.musicTabDiv.childNodes[2].innerHTML="用户好友音乐";	
	}else{
		this.tab=menuTabBunMusic;
		this.musicTabDiv.childNodes[0].innerHTML="群公开音乐";	
		this.musicTabDiv.childNodes[1].innerHTML="群内音乐";	
		this.musicTabDiv.childNodes[2].style.display="none";
	}
	this.loadDate();
}
//点击选项卡加载数据
musicObject.prototype.clickTab=function(obj){
	if(obj.className=="optionCar_1"){
		var parentDiv=obj.parentNode;
		this.selTabObj=obj;
		this.musicTabBodyDiv.innerHTML="<div class='loadCss'>努力加载中....</div>";
		for(var i=0;i<parentDiv.childNodes.length;i++){
			if(parentDiv.childNodes[i]!=obj){
				parentDiv.childNodes[i].className="optionCar_1";	
			}else{
				parentDiv.childNodes[i].className="optionCar";	
			}
		}
		this.page=1;
		this.typeMenuID=0
		setTimeout("musicClass.loadDate()",1000);
	}
}
//加载数据信息
musicObject.prototype.loadDate=function(){
	var objResponse=new JHttpResponse();
	objResponse.write("selTabIndex",this.selTabObj.id);//当前获取数据的格式信息
	objResponse.write("page",this.page);	
	objResponse.write("pagesize",this.pagesize);	
	objResponse.write("loadType","3");	
	var out=objAjax.getText("post","./cs/indexServer.aspx?type=loadClassDate&useType="+this.useType+"&user="+this.user,objResponse,null); 
	if(out.indexOf(c3)>-1){
		out=out.split(c3);
		this.pagecount=out[0];
		this.pages=parseInt(this.pagecount)/parseInt(this.pagesize);
		if(parseInt(this.pages)<parseFloat(this.pages)){
			this.pages=parseInt(this.pages)+1;	
		}		
		this.loadMusic(out[1]);	
		var spanPage=$("pages");
		var spanPage_1=$("pages_1");
		spanPage.innerHTML="<span style=\"font-size:13px; height:24px;\">1/1页</span><select style='margin:5px;'><option>跳转到第1页</option></select>";
		spanPage_1.innerHTML="<span style=\"font-size:13px; height:24px;\">1/1页</span><select style='margin:5px;'><option>跳转到第1页</option></select>";
		if(parseInt(this.pages)>1){
			spanPage.innerHTML="<span style=\"font-size:13px; height:24px;\">"+this.page+"/"+this.pages+"页</span>";
			spanPage_1.innerHTML="<span style=\"font-size:13px; height:24px;\">"+this.page+"/"+this.pages+"页</span>";
			if(this.page=="1"||parseInt(this.pages)>parseInt(this.page)){
				var nSpan=document.createElement("span");
				nSpan.style.cssText="cursor:pointer;color:blue;"
				nSpan.innerHTML="下一页";
				nSpan.onclick=function(){
					musicClass.page=parseInt(musicClass.page)+1;
					musicClass.loadDate();
				}
				spanPage.firstChild.appendChild(nSpan);
				var nSpan_1=document.createElement("span");
				nSpan_1.style.cssText="cursor:pointer;color:blue;"
				nSpan_1.innerHTML="下一页";
				nSpan_1.onclick=function(){
					musicClass.page=parseInt(musicClass.page)+1;
					musicClass.loadDate();
				}
				spanPage_1.firstChild.appendChild(nSpan_1);
			}
			if(parseInt(this.page)>1){
				var nSpan=document.createElement("span");
				nSpan.style.cssText="cursor:pointer;color:blue;"
				nSpan.innerHTML="上一页";
				nSpan.onclick=function(){
					musicClass.page=parseInt(musicClass.page)-1;
					musicClass.loadDate();
				}
				spanPage.firstChild.appendChild(nSpan);
				var nSpan_1=document.createElement("span");
				nSpan_1.style.cssText="cursor:pointer;color:blue;"
				nSpan_1.innerHTML="上一页";
				nSpan_1.onclick=function(){
					musicClass.page=parseInt(musicClass.page)-1;
					musicClass.loadDate();
				}
				spanPage_1.firstChild.appendChild(nSpan_1);
			}
			var cSel=document.createElement("select");	
			cSel.style.cssText="margin:5px;";
			for(var i=1;i<=parseInt(this.pages);i++){
				cSel.options.add(new Option("跳转到第"+i+"页",i));
				if(i==parseInt(this.page)){
					cSel.options[i-1].selected=true;	
				}
			}
			cSel.onchange=function(){
				musicClass.page=parseInt(this.options[this.selectedIndex].value);
				musicClass.loadDate();
			}
			spanPage.appendChild(cSel);
			var cSel_1=document.createElement("select");	
			cSel_1.style.cssText="margin:5px;";			
			for(var i=1;i<=parseInt(this.pages);i++){
				cSel_1.options.add(new Option("跳转到第"+i+"页",i));
				if(i==parseInt(this.page)){
					cSel_1.options[i-1].selected=true;	
				}
			}
			cSel_1.onchange=function(){
				musicClass.page=parseInt(this.options[this.selectedIndex].value);
				musicClass.loadDate();
			}
			spanPage_1.appendChild(cSel_1);
		}		
	}else{
		var spanPage=$("pages");
		var spanPage_1=$("pages_1")
		spanPage.innerHTML="";
		spanPage_1.innerHTML="";
		this.musicTabBodyDiv.innerHTML=out;		
	}
}
//生成音乐信息
musicObject.prototype.loadMusic=function(out){
	this.musicTabBodyDiv.innerHTML="";
	// 0     1         2     3       4    5
	//id,groupname,userid,username,photo,num
	out=out.split(c2);
	for(var i=0;i<out.length;i++){
		var vp=out[i].split(c1);
		var cDiv=document.createElement("div");
		var isBool=false;		
		if(isBunch=="0"){
			if(parseInt(homeUserID)==parseInt(userID)&&this.selTabObj.id=="1"||parseInt(cUserID)==parseInt(userID)&&this.selTabObj.id=="1"){
				isBool=true;	
			}
		}else{
			if(parseInt(homeUserID)==parseInt(userID)&&this.selTabObj.id=="2"||parseInt(cUserID)==parseInt(userID)&&this.selTabObj.id=="2"){
				isBool=true;	
			}
		}
		if(isBool){
			cDiv.style.cssText="float:left;margin-left:5px;position:relative;overflow:hidden;width:168px;height:200px;margin-top:7px;border:solid 2px #e0e0e0;";
		}else{
			cDiv.style.cssText="float:left;margin-left:5px;position:relative;overflow:hidden;width:168px;height:185px;margin-top:7px;border:solid 2px #e0e0e0;"			
		}
		cDiv.onmouseover=function(){this.style.border="solid 2px #cccccc";}
		cDiv.onmouseout=function(){this.style.border="solid 2px #efefef";}

		this.musicTabBodyDiv.appendChild(cDiv);
		
		var cDivImg=document.createElement("div");
		cDivImg.className="photoalignCss";
		cDiv.appendChild(cDivImg);
		
		var cA=document.createElement("a");
		cA.href="../../home/musics.aspx?user="+vp[3]+"&typeMenuID="+vp[0]+"&userid="+vp[2];
		cDivImg.appendChild(cA);
		
		var cCaDiv=document.createElement("div");
		cCaDiv.style.cssText="height:88px;width:136px;overflow:hidden;";
		cCaDiv.innerHTML="<img  onload='setImgWH(this)'  src='"+vp[4]+"'/>";
		cA.appendChild(cCaDiv);	
		
		var cBodyDiv=document.createElement("div");
		cDiv.appendChild(cBodyDiv);
		var cDivTitle=document.createElement("div");
		cDivTitle.className="photoTitleCss";
		cDivTitle.style.cssText="text-align:left;padding-left:10px;";
		cDivTitle.innerHTML="<a href='./musics.aspx?user="+vp[3]+"&typeMenuID="+vp[0]+"&userid="+vp[2]+"&useType="+this.useType+"'>"+vp[1]+"</a>";
		cBodyDiv.appendChild(cDivTitle);
		
		var cDivUser=document.createElement("div");
		cDivUser.className="photoUserCss";
		cDivUser.style.cssText="text-align:left;padding-left:10px;";
		cDivUser.innerHTML="共"+vp[5]+"首,创建者:<a href='./index.aspx?user="+vp[3]+"'>"+vp[3]+"</a>";
		cBodyDiv.appendChild(cDivUser);	
		
		if(isBool){
			var cDivEditor=document.createElement("div");
			cDivEditor.className="photoUserCss";
			cDivEditor.style.cssText="text-align:left;";
			cBodyDiv.appendChild(cDivEditor);	
			
			cSpanUser=document.createElement("span");
			cSpanUser.className="delMessageCss"
			cSpanUser.title="删除音乐专辑"
			cSpanUser.innerHTML="删除"
			cSpanUser.onmouseover=function(){this.style.color="red";}
			cSpanUser.onmouseout=function(){this.style.color="#000000";}		
			cSpanUser.setAttribute("id",vp[0])
			cSpanUser.onclick=function(){	
				if(confirm("数据删除后将无法恢复,确认要执行该操作吗?")){	
					var out=delUserMenuClass("3",this.id,musicClass.user,musicClass.useType);
					if(out=="ok"){
						alert("删除成功");
						musicClass.page=1;
						musicClass.loadDate();
					}else{
						alert(out);	
					}
				}
			}
			cDivEditor.appendChild(cSpanUser);			
			cSpanUser=document.createElement("span");
			cSpanUser.title="编辑音乐专辑";			
			cSpanUser.onmouseover=function(){this.firstChild.style.color="red";}
			cSpanUser.onmouseout=function(){this.firstChild.style.color="#000000";}
			cSpanUser.className="editorMessageCss"
			cSpanUser.innerHTML="<a href='Management.aspx?typeid=3&useType="+this.useType+"&user="+this.user+"'>编辑</a>";
			cDivEditor.appendChild(cSpanUser);
		}
	}		
}
