/**
 * @author caojj
 * @version	1.0.0.2
 */
/***************************路径解析****************************/
try{XN}catch(ex){XN={}};
function getHostSuffix(){
	if (!getHostSuffix.suffix) {		
		var matcher = location.host.match(/\.(.*\..*)/i);
		hostSuffix = matcher && matcher[1];
		
		getHostSuffix.suffix = hostSuffix;
	}

	return getHostSuffix.suffix || "d1xn.com";
}
getHostSuffix.suffix = "";

XN.GlobalPath={};
XN.GlobalPath.userfile={};
XN.GlobalPath.userfile.LevelNum=5;
XN.GlobalPath.userfile.PerNum=100;
XN.GlobalPath.userfile.ResPath="/res/public/userfile/";

XN.GlobalPath.userfileface={};
XN.GlobalPath.userfileface.LevelNum=5;
XN.GlobalPath.userfileface.PerNum=100;
XN.GlobalPath.userfileface.ResPath="/comres/pic/userfile/";

XN.GlobalPath.blogspace={};
XN.GlobalPath.blogspace.LevelNum=4;
XN.GlobalPath.blogspace.PerNum=1000;
XN.GlobalPath.blogspace.ResPath="/res/public/blogspace/";

XN.GlobalPath.imagespace={};
XN.GlobalPath.imagespace.LevelNum=4;
XN.GlobalPath.imagespace.PerNum=1000;
XN.GlobalPath.imagespace.ResPath="http://resimage."+getHostSuffix()+"/image/";

XN.GlobalPath.videospace={};
XN.GlobalPath.videospace.LevelNum=4;
XN.GlobalPath.videospace.PerNum=1000;
XN.GlobalPath.videospace.ResPath="http://resvideo."+getHostSuffix()+"/video/";

XN.GlobalPath.musicspace={};
XN.GlobalPath.musicspace.LevelNum=4;
XN.GlobalPath.musicspace.PerNum=1000;
XN.GlobalPath.musicspace.ResPath="http://resmusic."+getHostSuffix()+"/music/";

XN.GlobalPath.profile={};
XN.GlobalPath.profile.LevelNum=5;
XN.GlobalPath.profile.PerNum=100;
XN.GlobalPath.profile.ResPath="/profile/";

XN.GlobalPath.www="";

/**
 * 资源解析
 * @param {Object} resId
 * @param {Object} type [userfile|blogspace|imagespace|videospace|musicspace|profile] or {level, per, path}
 */
XN.PathParse = function(resId, type){
	var userRootStr = "";
	
	if (type && typeof type == "string" && XN.GlobalPath[type]) {
		var LevelNum = XN.GlobalPath[type].LevelNum||4;
		var PerNum = XN.GlobalPath[type].PerNum||1000;
		var ResPath = XN.GlobalPath[type].ResPath||"";
	} else {
		if (!type) {type={}};
		var LevelNum = type.level||4;
		var PerNum = type.per||1000;
		var ResPath = type.path||"";
	}
	
	var gene = 1;
	for (var i = 1; i < LevelNum; i++) {
		gene *= PerNum;
	}
	var tempUserID = parseInt(resId);
	for (var i = 0; i < LevelNum; i++) {
		if (LevelNum != i + 1) {
			var temp = Math.floor(tempUserID / gene);
			tempUserID = tempUserID % gene;
			userRootStr += temp + "/";
			gene /= PerNum;
		} else {
			userRootStr += resId;
		}
	}
	return ResPath + userRootStr + "/";
}
