// JavaScript Document
dojo.require("dojo.io.script");

var ListMark=new Array();

//文字版
function getNewClubList_11(){
	if(ListMark[11]!=1){
		getNewClubList('photo',0,0,8,1,handleFun_1,1,0);//影像活动（原：数码影像）
	}	
}
function getNewClubList_12(){
	if(ListMark[12]!=1){
		getNewClubList('smaf',0,0,8,1,handleFun_1,2,0);//数码暗房
	}
}
function getNewClubList_13(){
	if(ListMark[13]!=1){
		getNewClubList('qczb',0,0,8,1,handleFun_1,3,0);//器材装备
	}
}
function getNewClubList_14(){
	if(ListMark[14]!=1){
		getNewClubList('xyxy',0,0,8,1,handleFun_1,4,0);//摄影学友
	}
}
function getNewClubList_15(){
	if(ListMark[15]!=1){
		getNewClubList('dypb',0,0,8,1,handleFun_1,5,0);//大洋拍吧
	}
}


//图片版
function getNewClubList_21(){
	if(ListMark[21]!=1){
		getNewClubList('rwjs',0,0,5,1,handleFun_2,1,1);//人文纪实
	}
}
function getNewClubList_22(){
	if(ListMark[22]!=1){
		getNewClubList('fglx',0,0,5,1,handleFun_2,2,1);//风光旅行
	}
}
function getNewClubList_23(){
	if(ListMark[23]!=1){
		getNewClubList('rwxx',0,0,5,1,handleFun_2,3,1);//人物肖像
	}
}
function getNewClubList_24(){
	if(ListMark[24]!=1){
		getNewClubList('cys',0,0,5,1,handleFun_2,4,1);//纯艺术
	}
}



function handleFun_1(data,board,cbid,type){
	
	var tempLi=dojo.byId('list_li_'+type);
	var node=tempLi.cloneNode(true);
	var parent=tempLi.parentNode;
	var temp_node=null;
	var mark=0;
	parent.innerHTML='';
	node.style.display='';
	
	for(var k=0;k<data.result.length;k++){
		temp_node=node.cloneNode(true);
		
		temp_node.getElementsByTagName('a')[0].href='http://club.dayoo.com/read.dy?b='+board+'&cbid='+cbid+'&t='+data.result[k].id+'&i='+data.result[k].id+'&p=1';
		temp_node.getElementsByTagName('a')[0].innerHTML=data.result[k].title;
		
		temp_node.getElementsByTagName('span')[1].innerHTML=data.result[k].loginname;
		parent.appendChild(temp_node);
		
		mark=1;
	}
	
	if(mark==1){
		eval("ListMark[1"+type+"]=1");
		dojo.byId('list_loading_'+type).style.display='none';
		parent.style.display='';
	}
	
}

function handleFun_2(data,board,cbid,type){
	
	var tempLi=dojo.byId('pic_li_'+type);
	var node=tempLi.cloneNode(true);
	var parent=tempLi.parentNode;
	var temp_node=null;
	var mark=0;
	parent.innerHTML='';
	node.style.display='';
	
	for(var k=0;k<data.result.length;k++){
		temp_node=node.cloneNode(true);
		
		temp_node.getElementsByTagName('a')[0].href='http://club.dayoo.com/read.dy?b='+board+'&cbid='+cbid+'&t='+data.result[k].id+'&i='+data.result[k].id+'&p=1';
		temp_node.getElementsByTagName('a')[1].href=temp_node.getElementsByTagName('a')[0].href;
		temp_node.getElementsByTagName('a')[1].innerHTML=data.result[k].title;
		
		temp_node.getElementsByTagName('img')[0].src=data.result[k].attachmentURL.replace('http://img.club.dayoo.com/club_data/upload_photo/','http://igw.rnd.dayoo.com/wap/club/');
		temp_node.getElementsByTagName('p')[0].innerHTML=data.result[k].loginname;
		parent.appendChild(temp_node);
		
		mark=1;
	}
	
	if(mark==1){
		eval("ListMark[2"+type+"]=1");
		dojo.byId('pic_loading_'+type).style.display='none';
		parent.style.display='';
	}
	
	dojo.query('.ListImg_'+type).forEach(
		function(n){
			changeImgWidth(n,120);
		}
	);
	
}

function getNewClubList(board,cbid,distillate,limit,page,handleFun,type,pic){
	var postValue={
		"method":"getClubPic",
		"params":new Array(board,cbid,distillate,limit,page,0,pic)
	};
	var postURL= "http://app5.dayoo.com/Service/script_src_io.php";

	
	var params={handler:'ClubPic',type:'club',callbackType:"1",HttpCache:"1",HttpCacheTime:"900",params:dojo.toJson(postValue)};

	var kw = dojo.io.script.get( {
		url: postURL,
 		callbackParamName: "callback",
 		content: params,
 		handleAs: "json",
 		preventCache: false,
 		handle: function(response, ioArgs){
			if (response instanceof Error) {

			 }else{
				handleFun( response,board,cbid,type);
			 }
		}
	} );
}


function strftime(time, format) {
	var monthArray = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
	
	var aTime = new Date(time);
	
	var month = (aTime.getMonth()+1).toString().length==1?'0'+(aTime.getMonth()+1):(aTime.getMonth()+1);
	var day = aTime.getDate().toString().length==1?'0'+aTime.getDate():aTime.getDate();
	var hour = aTime.getHours().toString().length==1?'0'+aTime.getHours():aTime.getHours();
	var min = aTime.getMinutes().toString().length==1?'0'+aTime.getMinutes():aTime.getMinutes();
	var sec = aTime.getSeconds().toString().length==1?'0'+aTime.getSeconds():aTime.getSeconds();
	
	if (!format){
		return (monthArray[aTime.getMonth()]+' '+day+' '+aTime.getFullYear()+' '+hour+':'+min+':'+sec);
	} else {
		return (format.replace(/%[a-zA-Z%]/g, function (word){
			switch (word) {
				case '%%': return '%';
				case '%Y': return aTime.getFullYear();
				case '%m': return month;
				case '%d': return day;
				case '%H': return hour;
				case '%i': return min;
				case '%s': return sec;
				case '%M': return monthArray[aTime.getMonth()];
			}
		}));
	}
}

//改变图片宽
function changeImgWidth(img,maxWidth){

		//过快LOAD出了的
		if (img.width>img.height  && img.width > maxWidth) {
			img.width = maxWidth;
			img.alt = '点击查看原始尺寸图';
		}else if(img.width<img.height  && img.height > maxWidth){
			img.height = maxWidth;
			img.alt = '点击查看原始尺寸图';
		}
		
		//未LOAD出的
		img.onload = function() {
			if (this.width>this.height  && this.width > maxWidth) {
				this.width = maxWidth;
				this.alt = '点击查看原始尺寸图';
			}else if(this.width<this.height  && this.height > maxWidth){
				this.height = maxWidth;
				this.alt = '点击查看原始尺寸图';
			}
		}
}
