var mainOrder = ["type", "pref", "mcity", "city", "region", "line", "station"];
var wordOrder = ["wordType","wordText"/*,"wordCode1","wordCode2"*/];
var basicOrder = ["propType1", "propType2", "propType3", "buyFrom", "buyTo", "layout1R", "layout1K", "layout1L", "layout2K", "layout2L", "layout3K", "layout3L", "layout4K", "layout4L", "layout5K", "layout5L", "sizeFrom", "sizeTo", "landSizeTo", "landSizeFrom", "buildSizeTo", "buildSizeFrom", "walkTm", "compDt", "usage1", "usage2", "yield", "owner1", "owner2"]; 
var partOrder = ["info1", "info2", "info3", "info4", "info5", "floorNum1", "floorNum2", "floorNum5", "floorNum10", "floorNum20", "floorEnv1", "floorEnv2", "floorEnv3", "highMan", "buyMnCnd1", "buyMnCnd2", "buyMnCnd3", "buyMnCnd4", "buyMnCnd5", "buyMnCnd6", "buyMnCnd7", "buyMnCnd8", "buyMnCnd9", "buyMnCnd10", "buyMnCnd11", "buyHsCnd1", "buyHsCnd2", "buyHsCnd3", "buyHsCnd4", "buyHsCnd5", "buyHsCnd6", "buyHsCnd7", "buyHsCnd8", "buyHsCnd9", "buyHsCnd10", "buyHsCnd11", "buyLdCnd1", "buyLdCnd2", "buyLdCnd3", "buyLdCnd4", "buyLdCnd5", "buyLdCnd6", "facilityDist", "facility1", "facility2", "facility3", "facility4", "facility5", "facility6", "facility7"];
var dispOrder = ["display", "perPage", "currentPage", "sort"];

Century21.BuySearchManager = function(){
	this.initialize.apply(this, arguments);
}

Century21.BuySearchManager.prototype = new Century21.SearchManager();

Century21.BuySearchManager.prototype.clear2ndConditions = function() {
	var kind = this.condBasic.getValueByKey("kind");
	Century21.SearchManager.prototype.clear2ndConditions.call(this);
	this.condBasic.put("kind", kind);
}

$(document).ready(function(){	
	//検索条件
	param = new Century21.BuySearchManager("/buy/property/ajaxSearch");
	
	//ソート条件の設定
	param.condMain.setUrlOrder(mainOrder);
	param.condWord.setUrlOrder(wordOrder);
	param.condBasic.setUrlOrder(basicOrder);
	param.condPart.setUrlOrder(partOrder);
	param.condDisp.setUrlOrder(dispOrder);
	
	//URLを取得する
	param.getUrl = function() {
		var map = param.map4url();
		var path = location.pathname.replace(/a\d\d\/?/, '');
		
		//pathが/で終わっていない場合
		if (path.lastIndexOf("\/") + 1 != path.length) {
			path = path + "/";
		}
		
		//都道府県コードを取得
		var pref = map["p.pref"];
		if(pref){
			var prefs = pref.split(":");
			if(prefs.length == 1){
				//都道府県コードが一つの場合
				path += "a" + pref + "/";
				delete map["p.pref"];
			}
		}
		
		//物件種別コード
		var kind = map["p.kind"];
		if(kind){
			delete map["p.kind"];
		}
		
		var arr = new Array();
		jQuery.each(map, function(key, value) {
			arr.push(key + "=" + encodeURI(value));
		});
		
		path = "http://" + location.host + path;
		if (arr.length > 0) path = path + "?" + arr.join("&");
		return path;
	};
	
	//こだわり条件の画像を非表示に
	$("dl.kodawari li").css("display", "none");
	
	param.switchLeftConditions();
});
