/**
 * ...
 * @author DefaultUser
 */

 
(function() {
	MYNAMESPACE.namespace('modules.ForResidenceInArticle');
	MYNAMESPACE.modules.ForResidenceInArticle = function() {
		this.prefixPath = "";
		this.dataArr = [];
		this.compCount = 0;
		this.compNum = 0;
		this.termsType = "";
	//	this.callbackInfo;
		this.initialize.apply(this, arguments);
	};
	MYNAMESPACE.modules.ForResidenceInArticle.prototype = {
		
	//	initialize: function(prefixPath, dataArr, callbackInfo) {
		initialize: function(prefixPath, dataArr, termsType) {
			var thisObj = this;
			thisObj.prefixPath = prefixPath;
			thisObj.dataArr = dataArr;
			thisObj.compNum = thisObj.dataArr.length;
			thisObj.termsType = termsType;
		//	thisObj.callbackInfo = callbackInfo;
		},
		
		execute: function() {
			var thisObj = this;
			
			var master = $("#contents div.residenceWrapper").clone();
			var preElem = $("#contents div.residenceWrapper").eq(0);
			
			for (var i=0; i<thisObj.compNum; i++) {
				thisObj.dataArr[i].num = 0;
				var clone = $(master).clone();
				clone.attr("id", thisObj.dataArr[i].elemId);
				preElem.after(clone);
				preElem = clone;
			}
			for (var i=0; i<thisObj.compNum; i++) {
				var cls = new MYNAMESPACE.modules.ForResidence(thisObj.prefixPath, thisObj.dataArr[i].elemId, {method:thisObj.callback, scope:thisObj});
			//	cls.load(new MYNAMESPACE.modules.FileLoader(), thisObj.dataArr[i].xml, -1);
				cls.load(new MYNAMESPACE.modules.FileLoader(), thisObj.dataArr[i].xml, -1, thisObj.termsType);
			}
			$("#contents div.residenceWrapper").eq(0).remove();
		},
		callback: function(filePath, targetId, row) {
			var thisObj = this;
			for (var i=0; i<thisObj.compNum; i++) {
				if (thisObj.dataArr[i].xml === filePath && thisObj.dataArr[i].elemId === targetId) {
					thisObj.dataArr[i].num = row;
					break;
				}
			}
			
			/*
			console.log('');
			console.log('----------------------');
			console.log('	targetId = ' + targetId);
			console.log('----------------------');
			console.log('');
			*/
			switch (targetId) {
				case "residenceOfToshin":
				case "residenceOfJounan":
				case "residenceOfJouhoku":
				case "residenceOfJousai":
				case "residenceOfJoutou":
				case "residenceOfTokyoToka":
				case "residenceOfKanagawa":
				case "residenceOfChiba":
				case "residenceOfSaitama":
					/*
					$("#" + targetId + " .kantoLinks").css("display", "block");
					$("#" + targetId + " .kansaiLinks").css("display", "none");
					*/
					$(".summarize .areaBtns .east", "#" + targetId).css("display", "block");
					$(".summarize .areaBtns .west", "#" + targetId).css("display", "none");
					break;
					
				case "residnceOfOsaka":
				case "residenceOfKyoto":
				case "residenceOfHyogo":
					/*
					$("#" + targetId + " .kantoLinks").css("display", "none");
					$("#" + targetId + " .kansaiLinks").css("display", "block");
					*/
					$(".summarize .areaBtns .east", "#" + targetId).css("display", "none");
					$(".summarize .areaBtns .west", "#" + targetId).css("display", "block");
					break;
					
				case "residenceOfOther":
					/*
					$("#" + targetId + " .kantoLinks").css("display", "none");
					$("#" + targetId + " .kansaiLinks").css("display", "none");
					$("#" + targetId + " .btns").css("background", "url()");
					*/
					$(".summarize .areaBtns .east", "#" + targetId).css("display", "none");
					$(".summarize .areaBtns .west", "#" + targetId).css("display", "none");
					$(".summarize .areaBtns .title", "#" + targetId).css("display", "none");
					break;
			}
			
			fixedLayout(targetId, row);
			
			$("#"+targetId).css("visibility", "visible");
			
			$(".cBox").attr("checked", "");
			
			thisObj.compCount ++;
			if (thisObj.compCount === thisObj.compNum) {
				
			//	$.yuga.scroll();
				$.yuga.rollover();
				$.yuga.tab();
				
				var tab = new MYNAMESPACE.modules.Tab("#searchFromMap", "#east", "sumisho-sumai");
				tab.activate();
				
				if (location.hash.indexOf("#") === 0) {
					customScrollTo(location.hash.replace("#", ""));
				}
				
				var clsObj = {};
				clsObj["BulkRequest"] = new MYNAMESPACE.modules.BulkRequest();
				clsObj["BulkRequest"].init();
				clsObj["BulkRequest"].eventEnabled(true);
				
				heightLineMethod("heightLine");
				/*
				if (thisObj.callbackInfo && thisObj.callbackInfo.method && thisObj.callbackInfo.scope) {
					thisObj.callbackInfo.method.call(thisObj.callbackInfo.scope);
				}
				*/
			}
		}
	};
})();
