function $p(id){
	return parent.document.getElementById(id);
}

var _loadingDom = $p('loadhtml');
var _divProcessing = $p('divProcessing');
var _categoryLoading = null;
var stop = false;

function htmlCreateReady(){
	switch( type)
	{
		case 'a':
		case 'f':
		case 't':
		case 'm':
			htmlCreateGo();
		break;

		case 'c':
			htmlAcategoryCreateGo();
		break;
	}
}

function htmlCreateGo()
{
	if( stop == true) return;
	if( parent.index == parent.data.length ){
		_divProcessing.style.display = 'none';
		if( parent.data.length == parent.pagesize){
			parent.htmlReady( parent.tp, ++parent.pg);
			return;
		}
		if(parent.htmlFlag==0){
			parent.htmlFlag= 1;
			parent.pg      = 1;
			alert('HTML静态文件生成完毕');
			parent.disabledButton(false);
		}
		return true;
	}
	htmlCreate( parent.data[parent.index]);
	parent.index++;
	_loadingDom.width = Math.ceil(parent.index/parent.data.length*100)+"%";
	_loadingDom.innerHTML = '<font color=green>'+parent.index+'</font>/<font color=green>'+parent.data.length+'</font>';
}

function htmlCreate( str)
{
	var arr = str.split("-");
	if(arr.length == 1) arr[1] = 1;
	for( var i=1; i<=arr[1]; i++){
		_divProcessing.style.display = 'block';
		var link = "../index.php?mod="+channelid+"&ac="+contentphp+"&id="+arr[0]+"&page="+i+"&hash="+previewHash;
		AJAX.request( link,{
			method		: "get",
			onComplete	: function(json){
				htmlCreateGo();
			}
		});
	}
}

function htmlAcategoryCreateGo()
{
	if( stop == true) return;
	if( parent.index == parent.data.length ){
		_divProcessing.style.display = 'none';
		if(parent.htmlFlag==0){
			alert('生成完成');
			parent.htmlFlag=1;
			parent.disabledButton(false);
			_loadingDom.width = 1;
			_loadingDom.innerHTML = '';
			Each(getElementsByClassName(parent.document, 'c-loading'), function(){
				this.style.width = '0%';
			});
			Each(getElementsByClassName(parent.document, 'item-click'), function(){
				removeClassName(this, 'item-click');
			});
			Each(parent.document.getElementsByTagName('input'), function(){
				if(this.type.toLowerCase() == 'checkbox') this.checked = false;
			});
		}
		return true;
	}
	htmlAcategoryCreate( parent.data[parent.index], 1);
	parent.index++;
	_loadingDom.width = parent.index > 0 ? (parent.index / parent.data.length * 100 + '%') : '1';
	_loadingDom.innerHTML = '<font color=green>'+parent.index+'</font>/<font color=green>'+parent.data.length+'</font>';
}
function htmlAcategoryCreate( cid, pageno)
{
	if( stop == true) return;
	_divProcessing.style.display = 'block';
	var link = "../index.php?mod="+channelid+"&ac="+listphp+"&cid="+cid+"&pageno="+pageno+"&hash="+previewHash;
	AJAX.request( link,{
		method		: "get",
		onComplete	: function(json){
			var json = evaljson(json);
			try{
				var total =  json[1] > 0 ? json[1] : 1;
				$p('loading-'+cid).style.width = parseInt((pageno/total)*100)+"%";
				if( pageno < total){
					pageno++;
					htmlAcategoryCreate( cid, pageno);
				}else{
					var doc = $p('ids_' + cid);
					if(doc != null){
						doc.checked = false;
						removeClassName(doc.parentNode.parentNode, 'item-hover');
					}
					htmlAcategoryCreateGo();
				}
			}catch(e){
				htmlAcategoryCreateGo();
			}
		}
	});
}