function detailed_search_toggle() {
	var on = document.getElementById("detailed_search_on");
	var off = document.getElementById("detailed_search_off");
	on.style.cursor = 'pointer';
	on.onclick = function(){ 
		Effect.toggle('detailed_search_box','appear');
		Effect.toggle(this);
	};
	off.style.cursor = 'pointer';
	off.onclick = function(){ 
		Effect.toggle('detailed_search_box','appear');
		Effect.toggle('detailed_search_on');
	};
}

function detect_environment() {
	var the_pathname = window.location.pathname;
	var the_pathname_array = the_pathname.split("/");
	var the_environment = the_pathname_array[1];
	if(the_environment=="secret") { return the_environment+'/'; }
	if(the_environment=="development") { return the_environment+'/'; }
	return '';
}

function detect_domain() {
	var the_fqdn = window.location.host;
	var the_fqdn = the_fqdn.split(".");
	var the_domain = the_fqdn[1] + '.' + the_fqdn[2];
	return the_domain;
}

function application() {
	//get data from xhtml

	domain = detect_domain();
	home_url = "http://www." + domain + "/";
	env_url = detect_environment();
	//alert(env_url);
	pictures_url = home_url+env_url+"pictures/";
	thumbs_url = home_url+env_url+"thumbs/";
	//alert(pictures_url);

	var map_ido = new Array();
	var map_keido = new Array();
	var map_mode = "";
	if (document.getElementById("map_mode")) {
		map_mode=document.getElementById("map_mode").innerHTML;
	}
	if (document.getElementById("map_ido")) {
		map_ido=document.getElementById("map_ido").innerHTML.split("|");
		if (map_mode == "search") { map_ido.pop(); }
	}
	if (document.getElementById("map_keido")) {
		map_keido=document.getElementById("map_keido").innerHTML.split("|");
		if (map_mode == "search") { map_keido.pop(); }
	}
	//create map
	if ('function' == typeof GBrowserIsCompatible && document.getElementById("map")) {
		if (GBrowserIsCompatible() && map_ido && map_keido && map_mode) {
			map1 = new google_map(map_ido[0], map_keido[0], map_mode);
			if (map_mode == "search" || map_mode == "kakunin" || map_mode == "home" || map_mode == "edit" || document.getElementById("map_chintaibaibai")) {
				map1.get_results_data();
			}
			if (map_ido.length>0) {
				// 逆にする？まだ何かが足りない
				//for (var i = map_ido.length - 1; i >= 0; i-=1) {
				for (var i = 0; i < map_ido.length; i+=1) {
					var point = new GLatLng(map_ido[i],map_keido[i]);
					map1.add_marker(point);
				}
			}
			if (map_mode == "search") {
				map1.autozoom();
				map1.tabbed_info();
			}
			if (map_mode == "edit") {
				map1.attach_click(map1.markers[map1.markers.length-1], 0);
				var marker = map1.markers[map1.markers.length-1];
			}
		}
	}
	//validate form
	if(document.getElementById("form1")) {
		my_form = new form();
		if (my_form.jusho.id) {
			my_form.concat_jusho();
		}
		if (my_form.chintaibaibai.id && map_mode) {
			my_form.switch_chintaibaibai();
			my_form.switch_chikunentype();
		}
		if (my_form.input_fields.length>0) {
			my_form.attach_events();
		}
		if (my_form.btn_rent.id) {
			my_form.tabbed_search_box_attach();
		}
	}
	if (document.getElementById("detailed_search_box") 
		&& document.getElementById("detailed_search_on") 
		&& document.getElementById("detailed_search_off")) {
			detailed_search_toggle();
	}

	divs = document.getElementsByTagName('div');
	if (divs) {
		results = new Array();
		for (i=0; i<divs.length; i=i+1) {
			//if (divs[i].className == 'results') {
			if (divs[i].className == 'clickable_list_item') {
				results.push(divs[i]);
			}
		}
		if (document.getElementById("map")) {
			for (i=0; i<results.length; i=i+1) {
				map1.attach_click_to_result(results[i], i);
			}
		}
	}
	
	if(document.getElementById('ls_shakunyuu')){
		my_loansim = new LoanSim();
	}
}

window.onload = function() {
	application();
};
