var cpoEstate = function(){
	/*インスタンス作成*/
	this.main = function(){
		this.estList;
		this.queryList;
		this.pageNum = 1;
		this.sortOrder = 0;
		this.listPictType = 0;
		this.listLength = 20;
		this.ckList = new Array();
		this.fvList = new Array();
		this.reqURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/cpoestate.cgi';
		this.sesURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/session.cgi';

		/*===== スクロール初期動作 =====*/
		$(document).ready(function(){
			var cpoScrollObj = new cpoScroll();

			$('span.cpo-totop').css('cursor','pointer');
			$('span.cpo-toprev').css('cursor','pointer');
			$('span.cpo-tonext').css('cursor','pointer');
			$('span.cpo-toprevtarget').css('cursor','pointer');
			$('span.cpo-tonexttarget').css('cursor','pointer');

			$('span.cpo-totop').click(function(){	cpoScrollObj.scrollTop();	});
			$('span.cpo-toprev').click(function(){	cpoScrollObj.scrollPrev();	});
			$('span.cpo-tonext').click(function(){	cpoScrollObj.scrollNext();	});
			$('span.cpo-toprevtarget').click(function(){	cpoScrollObj.scrollPrevTarget();	});
			$('span.cpo-tonexttarget').click(function(){	cpoScrollObj.scrollNextTarget();	});

			$("a[href*='#']").click(function(){
				cpoScrollObj.scrollIDMove( $(this).attr('href') );
				return false;
			});

			var cpoStalkerObj = new cpoStalker;

			if( location.href.match(/#/) ){
				cpoStalkerObj.move();
		//		cpoScrollObj.scrollIDJump();
			}

			$(window).scroll(function(){
				cpoStalkerObj.move();
			});
		});

	};
	/*初期動作　トップページ用*/
	this.theTopEarly = function(){
		$("#main-panel input[type=checkbox]").click( function(){
			cpoestate.topFormChange();
		});
		$("#main-panel input[type=radio]").click( function(){
			cpoestate.topFormChange();
		});
		$("#main-panel select").change( function(){
			cpoestate.topFormChange();
		});
		var queryLine = '';
		var i = 0;
		$("#main-panel :input").each(function(){
			if( $(this).attr('checked') == true ){
				( i == 0 ) ? queryLine += '?' : queryLine += '&';
				queryLine += $(this).attr('name') + '=' + $(this).val();
				i = i + 1;
			}
		});
		queryLine += '&va='+ $("#main-panel select.va").children(':selected').val();
		queryLine += '&vu='+ $("#main-panel select.vu").children(':selected').val();
		queryLine += '&to='+ $("#main-panel select.to").children(':selected').val();
		queryLine += '&ch='+ $("#main-panel select.ch").children(':selected').val();
		$.getJSON( (cpoestate.sesURL), this.workSession );
		$.getJSON( ('http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatetop.cgi' + queryLine), function(thisData){
			$('#panel-result-num02').replaceWith('<span id="panel-result-num02" class="panel-result-num02">'+ thisData[0]['resultCount'] +'</span>');
		});
	};
	/*初期動作　詳細ページ用*/
	this.theDetailEarly = function(){
		/*ローディング外し*/
		$('#pleasewait').hide();
		/*イメージにhoverイベント付け*/
		var i = 0;
		$('#cpopictlist a').each(function(){
			$(this).mouseover( function(){cpoestate.imageChange( $(this).attr('href'),$(this).find('img').attr('id') ) });
			i = i + 1;
		});
		/*イメージリストの高さ調整(初回)*/
		if( Math.floor( $('#detail-pictlist').css('height').replace(/\D/g,"") ) < Math.floor( $('#detail-pictmain').css('height').replace(/\D/g,"") ) ){
			var detailPictlistHeight = $('#detail-pictmain').css('height').replace(/\D/g,"");
			detailPictlistHeight = ( Math.floor(detailPictlistHeight) + 3 )+ 'px';
			
			$('#detail-pictlist').css({'height': detailPictlistHeight });
		}

		/*cookie読み出し*/
		$.getJSON( (cpoestate.sesURL), function(thisData){
			cpoestate.queryList = thisData;
			var fvckURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatefvck.cgi';
			if( cpoestate.queryList[0].ck ){//最近チェックしたページ表示
				$.getJSON( (fvckURL + '?que=' + cpoestate.queryList[0].ck ), cpoestate.ckShow );
			}
			if( cpoestate.queryList[0].fv ){//お気に入り表示
				$.getJSON( (fvckURL + '?que=' + cpoestate.queryList[0].fv ), cpoestate.fvShow );
			}
		});
	};
	/*初期動作　一覧ページ用*/
	this.theListEarly = function(){
		/*フォームイベント付け*/
		$("#cpoestatesearchpanel-top input[type=checkbox]").click( function(){
			cpoestate.formChange('top',this.name);
		});
		$("#cpoestatesearchpanel-top input[type=radio]").click( function(){
			cpoestate.formChange('top',this.name);
		});
		$("#cpoestatesearchpanel-top select").change( function(){
			cpoestate.formChange('top',this.name);
		});
		$("#cpoestatesearchpanel-bottom input[type=checkbox]").click( function(){
			cpoestate.formChange('bottom',this.name);
		});
		$("#cpoestatesearchpanel-bottom input[type=radio]").click( function(){
			cpoestate.formChange('bottom',this.name);
		});
		$("#cpoestatesearchpanel-bottom select").change( function(){
			cpoestate.formChange('bottom',this.name);
		});

		$('#pleasewait').fadeIn('fast');

		//セッションからフォームなど復帰
		$.getJSON( (cpoestate.sesURL), function( thisData ){
			cpoestate.queryList = thisData;
			(cpoestate.queryList[0]['pn']) ? cpoestate.pageNum = cpoestate.queryList[0]['pn'] : cpoestate.pageNum = 1;
			(cpoestate.queryList[0]['so']) ? cpoestate.sortOrder = cpoestate.queryList[0]['so'] : cpoestate.sortOrder = 0;
			(cpoestate.queryList[0]['ll']) ? cpoestate.listLength = cpoestate.queryList[0]['ll'] : cpoestate.listLength = 20;
			var i = 0;
			var queryLine = '';
			for (var index in cpoestate.queryList[0]) {
				( i == 0 ) ? queryLine += '?' : queryLine += '&';
				if( index == 'station' ){
					var line = 'input[name=station][value=' + cpoestate.queryList[0][index] + ']';
					$(line).attr('checked',true);
				}
				else if( index != 'va' && index != 'to' && index != 'ch' ){
					var line = 'input[name=' + index + ']';
					if( cpoestate.queryList[0][index] == 1 || cpoestate.queryList[0][index] == true ){
						$(line).attr('checked',true);
					}
					else{
						$(line).attr('checked',false);
					}
				}
				else{
					var line = 'select[name=' + index + '] option[value=' + cpoestate.queryList[0][index] + ']';
					$(line).attr('selected',true);
				}
				queryLine += index + '=' + cpoestate.queryList[0][index];
				i = i + 1;
			}
			$.getJSON( (cpoestate.reqURL + queryLine + '&pn=' + cpoestate.pageNum + '&ll=' + cpoestate.listLength + '&so=' + cpoestate.sortOrder ), cpoestate.getData );

			var fvckURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatefvck.cgi';
			if( cpoestate.queryList[0].ck ){//最近チェックしたページ表示
				$.getJSON( (fvckURL + '?que=' + cpoestate.queryList[0].ck ), cpoestate.ckShow );
			}
			if( cpoestate.queryList[0].fv ){//お気に入り表示
				$.getJSON( (fvckURL + '?que=' + cpoestate.queryList[0].fv ), cpoestate.fvShow );
			}
		});
	};
	/*初期動作　一括問い合わせ用*/
	this.theRecForm = function(){
		$.getJSON( (cpoestate.sesURL), function( thisData ){
			cpoestate.queryList = thisData;
			var fvckURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatefvck.cgi';
			if( cpoestate.queryList[0].ck ){//最近チェックしたページ表示
				$.getJSON( (fvckURL + '?que=' + cpoestate.queryList[0].ck ), cpoestate.ckShow );
			}
			if( cpoestate.queryList[0].fv ){//お気に入り表示
				$.getJSON( (fvckURL + '?que=' + cpoestate.queryList[0].fv ), cpoestate.fvShow );
			}

			var fvckURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatefvck.cgi';
			$.getJSON( (fvckURL + '?que=' + cpoestate.queryList[0].fv ), function(fvData){
				var i = 0;
				var line = '';
				while( i < fvData.length ){
					if( i > 0 ){
						line += ' , ';
					}
					line += fvData[i].ss2number;
					i = i + 1;
				}
				$('#mailreclist').val(line);
			});
		});
	}
	/*トップページ フォームクリック時呼び出し*/
	this.topFormChange = function(){
		var queryLine = '';
		var i = 0;
		
		$('.panel-result-num02').replaceWith('<span id="panel-result-num02" class="panel-result-num02"><img src="http://www.kanouhome.co.jp/common/img/pleasewait.gif" width="32" height="32" alt="読み込み中" /></span>');
		$("#main-panel :input").each(function(){
			if( $(this).attr('checked') == true ){
				( i == 0 ) ? queryLine += '?' : queryLine += '&';
				queryLine += $(this).attr('name') + '=' + $(this).val();
				i = i + 1;
			}
		});
		queryLine += '&va='+ $("#main-panel select.va").children(':selected').val();
		queryLine += '&vu='+ $("#main-panel select.vu").children(':selected').val();
		queryLine += '&to='+ $("#main-panel select.to").children(':selected').val();
		queryLine += '&ch='+ $("#main-panel select.ch").children(':selected').val();
		$.getJSON( (cpoestate.sesURL + queryLine), this.workSession );
		$.getJSON( ('http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatetop.cgi' + queryLine), function(thisData){
			$('#panel-result-num02').replaceWith('<span id="panel-result-num02" class="panel-result-num02">'+ thisData[0]['resultCount'] +'</span>');
		});
	};


	/*一覧ページ　フォームクリック時呼び出し*/
	this.formChange = function(thisData,thisName){
		//上下のフォーム合わせ
		cpoestate.pageNum = 1;

		var lineA = '#cpoestatesearchpanel-top input[name=' + thisName + ']';
		var lineB = '#cpoestatesearchpanel-bottom input[name=' + thisName + ']';
		if( thisData == 'top' ){
			if(thisName == 'vu' || thisName == 'va' || thisName == 'to' || thisName == 'ch'){
				$('#cpoestatesearchpanel-bottom select[name='+ thisName +']').children('option[value='+ $('#cpoestatesearchpanel-top select[name='+ thisName +']').children('option[selected=true]').val() +']').attr('selected',true);
			}
			else if(thisName == 'station'){

				$('#cpoestatesearchpanel-bottom input[name=station][value='+ $('#cpoestatesearchpanel-top input[name=station]:checked').val() + ']').attr('checked',true);
			}
			else{
				$('#cpoestatesearchpanel-bottom input[name=' + thisName + ']').attr( 'checked',$('#cpoestatesearchpanel-top input[name=' + thisName + ']').attr('checked') );
			}
		}
		else{
			if(thisName == 'vu' || thisName == 'va' || thisName == 'to' || thisName == 'ch'){
				$('#cpoestatesearchpanel-top select[name='+ thisName +']').children('option[value='+ $('#cpoestatesearchpanel-bottom select[name='+ thisName +']').children('option[selected=true]').val() +']').attr('selected',true);
			}
			else if(thisName == 'station'){
				$('input[name=station][value=' + thisName + ']').attr('checked',true);
			}
			else{
				$('#cpoestatesearchpanel-top input[name=' + thisName + ']').attr( 'checked',$('#cpoestatesearchpanel-bottom input[name=' + thisName + ']').attr('checked') );
			}
		}

		/*#####110502追加 数値のみ変更って流れ*/
		$('.panel-result-num02').replaceWith('<span class="panel-result-num02"><img src="http://www.kanouhome.co.jp/common/img/pleasewait.gif" width="32" height="32" alt="読み込み中" /></span>');
		$.getJSON( (cpoestate.sesURL + makeQuery(thisData)), this.workSession );
		$.getJSON( ('http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatetop.cgi' + makeQuery(thisData)), function(thisData){
			$('.panel-result-num02').replaceWith('<span class="panel-result-num02">'+ thisData[0]['resultCount'] +'</span>');
		});
		/*#####110502 ここまで*/
	};

	/*一覧ページ　ボタン押下時呼び出し*/
	this.submitButton = function(){
		$('#pleasewait').fadeIn('fast');
		$.getJSON( (cpoestate.sesURL + makeQuery('top') + '&pn=' + cpoestate.pageNum + '&ll=' + cpoestate.listLength + '&so=' + cpoestate.sortOrder), function( thisData ){
			cpoestate.queryList = thisData;
			var i = 0;
			var fvckURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatefvck.cgi';
			if( cpoestate.queryList[0].ck ){//最近チェックしたページ表示
				$.getJSON( (fvckURL + '?que=' + cpoestate.queryList[0].ck ), cpoestate.ckShow );
			}
			if( cpoestate.queryList[0].fv ){//お気に入り表示
				$.getJSON( (fvckURL + '?que=' + cpoestate.queryList[0].fv ), cpoestate.fvShow );
			}

			$.getJSON( (cpoestate.reqURL + makeQuery('top') + '&pn=' + cpoestate.pageNum + '&ll=' + cpoestate.listLength + '&so=' + cpoestate.sortOrder ), cpoestate.getData );
		});
	};
	/*一覧ページ　初回・フォームクリック時呼び出し2*/
	this.getData = function(thisData){
		cpoestate.estList = thisData;
		$('.panel-result-num02').text( cpoestate.estList[0]['resultCount'] );
		$('#l2listinner').replaceWith('<div id="l2listinner"></div>');
		var i = 1;
		var line = '';
//alert(cpoestate.listLength);
		while( i < cpoestate.estList.length ){
			line = '';

			line = line + '			<div class="l2list-item">';
			line = line + '				<p class="l2list-image"><a href="' + cpoestate.estList[i]['entry_basename'] + '.html"><img src="';

			if( cpoestate.listPictType == 0 ){
				( cpoestate.estList[i]['ss2pict01'] ) ? line = line + cpoestate.estList[i]['ss2pict01'] : line = line + 'http://www.kanouhome.co.jp/common/img/dummy-listpic.gif';
			}
			else{
				( cpoestate.estList[i]['ss2madorizu'] ) ? line = line + cpoestate.estList[i]['ss2madorizu'] : line = line + 'http://www.kanouhome.co.jp/common/img/dummy-listpic.gif';
			}
			line = line + '" width="177" alt="" /></a></p>';
			line = line + '				<div class="l2list-content">';
			line = line + '					<h3><a href="' + cpoestate.estList[i]['entry_basename'] + '.html">';

			//日付判定（Newマーク関連）
			if( cpoestate.estList[i]['ss2newcancell'] && cpoestate.estList[i]['ss2newcancell'] == 1 ){}
			else if( cpoestate.estList[i]['ss2newmark'] && cpoestate.estList[i]['ss2newmark'] == 1 ){
				line = line + '<img src="http://www.kanouhome.co.jp/common/img/newsmark.gif" width="49" height="16" alt="新着賃貸物件" />';
			}
			else if( cpoestate.estList[i]['ss2newcancell'] != 1 ){
				var oneList = cpoestate.estList[i]['entry_modified_on'].split(/ /);
				var oneList2 = oneList[0].split(/\-/);
				var dt1 = new Date(oneList2[0], ( oneList2[1] - 1 ), oneList2[2]);

				var date = new Date();
				var dt2 = new Date(date.getFullYear(), date.getMonth(), date.getDate());
				var diff = dt2.getTime() - dt1.getTime();
				var diffDay = diff / 86400000;//1日は86400000ミリ秒
				if( diffDay < 31 ){
					line = line + '<img src="http://www.kanouhome.co.jp/common/img/newsmark.gif" width="49" height="16" alt="新着賃貸物件" />';
				}
				else{

				}
			}
			//ただいま商談中マーク
			if( cpoestate.estList[i]['ss2discussion'] ){
				line = line + ' <img src="http://www.kanouhome.co.jp/common/img/bismark.gif" width="49" height="16" alt="現在商談中" />';
			}
			line = line + '&nbsp;【物件番号: ' + cpoestate.estList[i]['ss2number'] + '】' + cpoestate.estList[i]['ss2catch'] + '</a></h3>';
			line = line + '					<ul class="l2list-adst">';
			line = line + '						<li class="l2list-address">' + cpoestate.estList[i]['ss2address1'] + cpoestate.estList[i]['ss2address2'] + '</li>';
			( cpoestate.estList[i]['ss2accessbus'] ) ? line = line + '						<li class="l2list-station">' + cpoestate.estList[i]['ss2access'] + ' バス' + cpoestate.estList[i]['ss2accessbus'] +'分 徒歩' + cpoestate.estList[i]['ss2toho'] + '分</li>' : line = line + '						<li class="l2list-station">' + cpoestate.estList[i]['ss2access'] + ' 徒歩' + cpoestate.estList[i]['ss2toho'] + '分</li>';
			line = line + '					</ul>';
			line = line + '					<ul class="l2list-price">';
			line = line + '						<li class="l2list-value">賃料: <span>' + addFigure(cpoestate.estList[i]['ss2value']) + '円</span></li>';
			line = line + '						<li class="l2list-etcvalue">';
			line = line + '							管理費・共益費: ';
			( cpoestate.estList[i]['ss2kanri'] ) ? line = line + addFigure(cpoestate.estList[i]['ss2kanri']) + '円<br />' : line = line + '0円<br />';
			line = line + '							 敷: ';
			( cpoestate.estList[i]['ss2shikikin'] ) ? line = line + cpoestate.estList[i]['ss2shikikin'] : line = line + '0';
			line = line + ' / 礼: ';
			( cpoestate.estList[i]['ss2reikin'] ) ? line = line + cpoestate.estList[i]['ss2reikin'] : line = line + '0';
			line = line + '						</li>';
			line = line + '					</ul>';
			line = line + '					<ul class="l2list-equip">';
			line = line + '						<li>間取り:';
			( cpoestate.estList[i]['ss2madori'] =='3LDK～' && cpoestate.estList[i]['ss2madorifree'] ) ? line = line + cpoestate.estList[i]['ss2madorifree'] : line = line + cpoestate.estList[i]['ss2madori'];
			line = line + ' / 専有面積: ' + cpoestate.estList[i]['ss2senyu'] + 'm<sup>2</sup></li>';
			line = line + '						<li>階層　:' + cpoestate.estList[i]['ss2kai'] + '/' + cpoestate.estList[i]['ss2kaidate'] + '階 / 物件種目: ' + cpoestate.estList[i]['ss2bukkensyumoku'] + '</li>';
			line = line + '						<li>築年月:' + cpoestate.estList[i]['ss2chikunennen'] + '</li>';
			line = line + '					</ul>';
			line = line + '					<ul class="l2list-icon">';
			line = line + '						<li><img src="';
			( cpoestate.estList[i]['ss2pets'] && cpoestate.estList[i]['ss2pets'] == 1 ) ? line = line + 'http://www.kanouhome.co.jp/common/img/itemicon05_on.gif' : line = line + 'http://www.kanouhome.co.jp/common/img/itemicon05_off.gif';
			line = line + '" width="47" height="47" alt="ペット相談" /></li>';
			line = line + '						<li><img src="';
			if(cpoestate.estList[i]['ss2bukkensyumoku'] != 'テラスハウス'){
				( cpoestate.estList[i]['ss2kai'] && cpoestate.estList[i]['ss2kai'] > 1 ) ? line = line + 'http://www.kanouhome.co.jp/common/img/itemicon04_on.gif' : line = line + 'http://www.kanouhome.co.jp/common/img/itemicon04_off.gif';
			}
			else{
				( cpoestate.estList[i]['ss2kai'].match('[2-9]') ) ? line = line + 'http://www.kanouhome.co.jp/common/img/itemicon04_on.gif' : line = line + 'http://www.kanouhome.co.jp/common/img/itemicon04_off.gif';
			}
			line = line + '" width="47" height="47" alt="二階以上" /></li>';
			line = line + '						<li><img src="';
			( cpoestate.estList[i]['ss2aircon'] && cpoestate.estList[i]['ss2aircon'] == 1 ) ? line = line + 'http://www.kanouhome.co.jp/common/img/itemicon03_on.gif' : line = line + 'http://www.kanouhome.co.jp/common/img/itemicon03_off.gif';
			line = line + '" width="47" height="47" alt="エアコン" /></li>';
			line = line + '						<li><img src="';
			( cpoestate.estList[i]['ss2sentaku'] && cpoestate.estList[i]['ss2sentaku'] == 1 ) ? line = line + 'http://www.kanouhome.co.jp/common/img/itemicon02_on.gif' : line = line + 'http://www.kanouhome.co.jp/common/img/itemicon02_off.gif';
			line = line + '" width="47" height="47" alt="室内洗濯機置き場" /></li>';
			line = line + '						<li><img src="';
			( cpoestate.estList[i]['ss2bathtoire'] && cpoestate.estList[i]['ss2bathtoire'] == 1 ) ? line = line + 'http://www.kanouhome.co.jp/common/img/itemicon01_on.gif' : line = line + 'http://www.kanouhome.co.jp/common/img/itemicon01_off.gif';
			line = line + '" width="47" height="47" alt="バストイレ別" /></li>';
			line = line + '					</ul>';
			line = line + '					<ul class="l2list-btn"><!--';
			line = line + '						--><li><a href="' + cpoestate.estList[i]['entry_basename'] + '.html"><img src="http://www.kanouhome.co.jp/common/img/list-btn-det_n.gif" width="255" height="31" alt="" /></a></li><!--';
			line = line + '						--><li><a href="javascript:cpoestate.fvAdd(' + cpoestate.estList[i]['entry_id'] + ');"><img src="http://www.kanouhome.co.jp/common/img/list-btn-fv_n.gif" width="213" height="31" alt="" /></a></li><!--';
			line = line + '					--></ul>';
			line = line + '				</div>';
			line = line + '			</div>';

			$('#l2listinner').append(line);
			i = i + 1;
		}

		$('#pleasewait').fadeOut('fast');
		//ページャー入れ替え

		var i = 1;
		var line = '			<div class="l2list-pager" id="l2list-pager">';

		( (cpoestate.pageNum) != 1 ) ? line = line + '<a href="javascript:cpoestate.pageChanger('+ Math.max(1,(cpoestate.pageNum - 1) ) +')">&lt;前へ</a>' : line = line + '<span>&lt;前へ</span>';

		while( i < (Math.ceil( Math.max(cpoestate.estList[0]['resultCount'],0) / cpoestate.listLength ) + 1) ){
			( i == cpoestate.pageNum ) ? line = line + '<span>'+ i +'</span>' : line = line + '<a href="javascript:cpoestate.pageChanger('+ i +')">' + i + '</a>';
			i = i + 1;
		}
		( (cpoestate.pageNum * 1 + 1) != i ) ? line = line + '<a href="javascript:cpoestate.pageChanger('+ Math.min( Math.ceil( cpoestate.estList[0]['resultCount'] / cpoestate.listLength ),(cpoestate.pageNum * 1 + 1) ) +')">次へ&gt;</a>			</div>' : line = line + '<span>次へ&gt;</span>';
		$('#l2list-pager').replaceWith(line);
	};
	/*ページャー*/
	this.pageChanger = function(thisData){
		this.pageNum = thisData;
		$('#pleasewait').fadeIn('fast');

		$.getJSON( (cpoestate.sesURL + makeQuery(thisData) + '&pn=' + cpoestate.pageNum + '&ll=' + cpoestate.listLength + '&so=' + cpoestate.sortOrder), function( thisData ){
			cpoestate.queryList = thisData;
			(cpoestate.queryList[0]['pn']) ? cpoestate.pageNum = cpoestate.queryList[0]['pn'] : cpoestate.pageNum = 1;
			(cpoestate.queryList[0]['so']) ? cpoestate.sortOrder = cpoestate.queryList[0]['so'] : cpoestate.sortOrder = 0;
			(cpoestate.queryList[0]['ll']) ? cpoestate.listLength = cpoestate.queryList[0]['ll'] : cpoestate.listLength = 20;
			$.getJSON( (cpoestate.reqURL + makeQuery('top') + '&pn=' + cpoestate.pageNum + '&ll=' + cpoestate.listLength + '&so=' + cpoestate.sortOrder ), cpoestate.getData );
		});

		$('#backtolisttop').click();
	};
	/*ソート*/
	this.sortOderChange = function(thisData){
		this.sortOrder = thisData;
		this.pageNum = 1;
		$('#pleasewait').fadeIn('fast');
		$.getJSON( (cpoestate.sesURL + makeQuery(thisData) + '&pn=' + cpoestate.pageNum + '&ll=' + cpoestate.listLength + '&so=' + cpoestate.sortOrder), function( thisData ){
			cpoestate.queryList = thisData;
			(cpoestate.queryList[0]['pn']) ? cpoestate.pageNum = cpoestate.queryList[0]['pn'] : cpoestate.pageNum = 1;
			(cpoestate.queryList[0]['so']) ? cpoestate.sortOrder = cpoestate.queryList[0]['so'] : cpoestate.sortOrder = 0;
			(cpoestate.queryList[0]['ll']) ? cpoestate.listLength = cpoestate.queryList[0]['ll'] : cpoestate.listLength = 20;
			$.getJSON( (cpoestate.reqURL + makeQuery('top') + '&pn=' + cpoestate.pageNum + '&ll=' + cpoestate.listLength + '&so=' + cpoestate.sortOrder ), cpoestate.getData );
		});

		$('#backtolisttop').click();
	}
	/*一覧表示用　表示画像変更*/
	this.listPict = function(thisData){
		this.listPictType = thisData;
		var i = 1;
		if(cpoestate.listPictType == 0){
			$('.l2list-image img').each(function(){
				(cpoestate.estList[i]['ss2pict01']) ? $(this).attr('src',cpoestate.estList[i]['ss2pict01']) : $(this).attr('src','http://www.kanouhome.co.jp/common/img/dummy-listpic.gif');
				i = i + 1;
			});
		}
		else{
			$('.l2list-image img').each(function(){
				(cpoestate.estList[i]['ss2madorizu']) ? $(this).attr('src',cpoestate.estList[i]['ss2madorizu']) : $(this).attr('src','http://www.kanouhome.co.jp/common/img/dummy-listpic.gif');
				i = i + 1;
			});
		}
		$('#backtolisttop').click();
	}
	/*表示件数変更*/
	this.listLengthChange = function(thisData){
		this.listLength = thisData;
		this.pageNum = 1;
		$('#pleasewait').fadeIn('fast');

		$.getJSON( (cpoestate.sesURL + makeQuery(thisData) + '&pn=' + cpoestate.pageNum + '&ll=' + cpoestate.listLength + '&so=' + cpoestate.sortOrder), function( thisData ){
			cpoestate.queryList = thisData;
			(cpoestate.queryList[0]['pn']) ? cpoestate.pageNum = cpoestate.queryList[0]['pn'] : cpoestate.pageNum = 1;
			(cpoestate.queryList[0]['so']) ? cpoestate.sortOrder = cpoestate.queryList[0]['so'] : cpoestate.sortOrder = 0;
			(cpoestate.queryList[0]['ll']) ? cpoestate.listLength = cpoestate.queryList[0]['ll'] : cpoestate.listLength = 20;
			$.getJSON( (cpoestate.reqURL + makeQuery('top') + '&pn=' + cpoestate.pageNum + '&ll=' + cpoestate.listLength + '&so=' + cpoestate.sortOrder ), cpoestate.getData );
		});

		$('#backtolisttop').click();
	}
	/*セッション関係*/
	this.workSession = function( thisData ){
		cpoestate.queryList = thisData;
	};
	/*最近見たページ追加*/
	this.ckAdd = function( thisData ){
		var queryLine = '?mode=ck&ck='+ thisData;
		$.getJSON( (cpoestate.sesURL + queryLine), function(thisData){
			cpoestate.queryList = thisData;
			var ckURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatefvck.cgi';
			$.getJSON( (ckURL + '?que=' + cpoestate.queryList[0].ck ), cpoestate.ckShow );
		});
	};
	/*最近見たページ表示のみ*/
	this.ckShow = function( ckData ){
		var i = 0;
		var line = '<ul id="ckarea">';
		while( i < 5 && i < ckData.length ){
			line += '<li><a href="'+ ckData[i].entry_basename +'.html"><span class="ckimage">';
			line += '<img src="';
			( ckData[i].ss2pict01 ) ? line = line + ckData[i].ss2pict01 : line = line + 'http://www.kanouhome.co.jp/common/img/dummy-listpic.gif';
			line = line + '" width="160" alt="" />';
			line += '</span><span class="ckcomment"><span>';
			line += '【物件番号: ' + ckData[i].ss2number + '】<br />';
			line += '賃料: ' + addFigure(ckData[i].ss2value) + '円 / ';
			(ckData[i].ss2madorifree && ckData[i].ss2madori == '3LDK～') ? line = line + ckData[i].ss2madorifree : line = line + ckData[i].ss2madori;
			line += '</span></span></a></li>';
			i = i + 1;
		}
		line += '</ul>';
		$('#ckarea').replaceWith(line);
	}
	/*お気に入り追加*/
	this.fvAdd = function( thisData ){
		var queryLine = '?mode=fv&fv='+ thisData;
		$.getJSON( (cpoestate.sesURL + queryLine), function(thisData){
			cpoestate.queryList = thisData;
			var fvURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatefvck.cgi';
			$.getJSON( (fvURL + '?que=' + cpoestate.queryList[0].fv ), cpoestate.fvShow );
		});
	};
	/*お気に入り削除*/
	this.fvRemove = function(thisData){
		var queryLine = '?mode=fvremove&fv='+ thisData;
		$.getJSON( (cpoestate.sesURL + queryLine), function(thisData){
			cpoestate.queryList = thisData;
			var fvURL = 'http://www.kanouhome.co.jp/common/js/cpoestate/cpoestatefvck.cgi';
			$.getJSON( (fvURL + '?que=' + cpoestate.queryList[0].fv ), cpoestate.fvShow );
		});
	};
	/*お気に入り表示*/
	this.fvShow = function(fvData){
		var i = 0;
		var line = '<ul id="fvarea">';
		while( i < fvData.length ){
			line += '<li><a href="'+ fvData[i].entry_basename +'.html">';
			line += '<span class="fvimage">';
			line += '<img src="';
			( fvData[i].ss2pict01 ) ? line = line + fvData[i].ss2pict01 : line = line + 'http://www.kanouhome.co.jp/common/img/dummy-listpic.gif';
			line = line + '" width="160" alt="" />';
			line += '</span>';
			line += '<span class="fvcomment"><span>';
			line += '【物件番号: ' + fvData[i].ss2number + '】<br />';
			line += '賃料: ' + addFigure(fvData[i].ss2value) + '円 / ';
			(fvData[i].ss2madorifree && fvData[i].ss2madori == '3LDK～') ? line = line + fvData[i].ss2madorifree : line = line + fvData[i].ss2madori;
			line += '</span></span>';
			line += '</a>';
			line += '<span class="fvclose"><a href="javascript:cpoestate.fvRemove('+ fvData[i].entry_id +');" title="閉じる"><img src="http://www.kanouhome.co.jp/common/img/l2-side-itemclose.gif" width="14" height="14" alt="" /></a></span>';
			line += '</li>';

			i = i + 1;
		}
		line += '</ul>';
		$('#fvarea').replaceWith(line);
	};
	/*詳細ページ イメージ入れ替え*/
	this.imageSwitch = 0;
	this.imageChange = function(thisItem,imgID){
		if( this.imageSwitch == 0 && $('#detail-pictmain img').attr('src') != thisItem ){
			this.imageSwitch = 1;
			$('#detail-pictmain').fadeOut("fast" , function(){
				$('#detail-pictlist').css({'height': 'auto' });
				var thisImage = new Image, tick = 0;
				thisImage.src = thisItem;

				var thisItemSize = new imgTrueSize(thisImage);
				var viewSize;
				( 518 > thisItemSize.width ) ? viewSize = thisItemSize.width : viewSize = 518;

				$('#detail-pictmain p').replaceWith(
					'<p><img src="'+ thisItem +'" width="'+ viewSize +'" alt="" ></p>'
				);

				if( Math.floor( $('#detail-pictlist').css('height').replace(/\D/g,"") ) < Math.floor( $('#detail-pictmain').css('height').replace(/\D/g,"") ) ){
					var detailPictlistHeight = $('#detail-pictmain').css('height').replace(/\D/g,"");
					detailPictlistHeight = ( Math.floor(detailPictlistHeight) + 3 )+ 'px';
					
					$('#detail-pictlist').css({'height': detailPictlistHeight });
				}
			});
			$('#detail-pictmain').fadeIn("fast", function(){
				cpoestate.imageSwitch = 0;
			});
		}
	};
	/*google map 表示*/
	this.showMap = function(addressLine,stSwitch,addressPoint,compass){
		addressLine = decodeURI(addressLine); 
		var latlng;
		var geocoder;
		if( stSwitch == '0' ){
			$('#gmaps').css({'width':'50%' , 'height':'435px' , 'float':'left'});
			this.showStreetview(addressLine,addressPoint,compass);
		}
		else{
			$('#gmaps').css({'width':'100%' , 'height':'435px'});
		}

		if(addressPoint != ""){
			latlng = new google.maps.LatLng(addressPoint);
			var myOptions = {
				zoom: 15,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				center: latlng
			};
			var map = new google.maps.Map(document.getElementById("gmaps"), myOptions);
			var marker = new google.maps.Marker({
				position: latlng,
				map: map
			});
		}
		else{
			geocoder = new google.maps.Geocoder();
			if(geocoder){
				geocoder.geocode( { 'address': addressLine }, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						var myOptions = {
							zoom: 15,
							mapTypeId: google.maps.MapTypeId.ROADMAP,
							center: results[0].geometry.location
						};
						var gmapsView = new google.maps.Map(document.getElementById("gmaps"), myOptions);
						var gmapsMarker = new google.maps.Marker({
							position: results[0].geometry.location,
							map: gmapsView
						});
					} else {
						alert("google map エラーコード: " + status);
					}
				});
			}
		}
	};
	/*google streetview 表示*/
	this.showStreetview = function(addressLine,addressPoint,compass){
		var compassNum;
		if( compass == '北' ){
			compassNum = 0;
		}
		else if( compass == '北東' ){
			compassNum = 45;
		}
		else if( compass == '東' ){
			compassNum = 90;
		}
		else if( compass == '南東' ){
			compassNum = 135;
		}
		else if( compass == '南' ){
			compassNum = 180;
		}
		else if( compass == '南西' ){
			compassNum = 225;
		}
		else if( compass == '西' ){
			compassNum = 270;
		}
		else if( compass == '北西' ){
			compassNum = 315;
		}

		$('#gstview').css({'width':'50%' , 'height':'435px' , 'float':'left'});

		if(addressPoint != ""){
			var stLatlng = new google.maps.LatLng(addressPoint);
			var stOptions = {
				position : stLatlng
			};
			var gstView = new google.maps.StreetViewPanorama(document.getElementById("gstview"), stOptions);
		}
		else{
			var stGeocoder = new google.maps.Geocoder(addressLine);
			if (stGeocoder) {
				stGeocoder.geocode( { 'address': addressLine }, function(results, status) {
					if(status == google.maps.GeocoderStatus.OK) {
						var stOptions = {
							'position': results[0].geometry.location,
							'pov': {
								heading: compassNum,
								pitch: 10,
								zoom: 1
							}
						};
						var gstView = new google.maps.StreetViewPanorama( document.getElementById("gstview"), stOptions);
					}
					else{
						alert("Geocode was not successful for the following reason: " + status);
					}
				});
			}
		}
	};

	function makeQuery(thisData){
		var i = 0;
		var queryLine = '';
		if( thisData == 'top' ){
			$("#cpoestatesearchpanel-top :input").each(function(){
				if( $(this).attr('checked') == true ){
					( i == 0 ) ? queryLine += '?' : queryLine += '&';
					queryLine += $(this).attr('name') + '=' + $(this).val();
					i = i + 1;
				}
			});
			queryLine += '&vu='+ $("#cpoestatesearchpanel-top select.vu").children(':selected').val();
			queryLine += '&va='+ $("#cpoestatesearchpanel-top select.va").children(':selected').val();
			queryLine += '&to='+ $("#cpoestatesearchpanel-top select.to").children(':selected').val();
			queryLine += '&ch='+ $("#cpoestatesearchpanel-top select.ch").children(':selected').val();
		}
		else{
			$("#cpoestatesearchpanel-bottom :input").each(function(){
				if( $(this).attr('checked') == true ){
					( i == 0 ) ? queryLine += '?' : queryLine += '&';
					queryLine += $(this).attr('name') + '=' + $(this).val();
					i = i + 1;
				}
			});
			queryLine += '&vu='+ $("#cpoestatesearchpanel-bottom select.vu").children(':selected').val();
			queryLine += '&va='+ $("#cpoestatesearchpanel-bottom select.va").children(':selected').val();
			queryLine += '&to='+ $("#cpoestatesearchpanel-bottom select.to").children(':selected').val();
			queryLine += '&ch='+ $("#cpoestatesearchpanel-bottom select.ch").children(':selected').val();
		}
		return queryLine;
	}
}

/*画像の本来のサイズ取得（借りもの）*/
var imgTrueSize = function(image){
	var w = image.width ,
		h = image.height;

	if ( typeof image.naturalWidth !== 'undefined' ) {  // for Firefox, Safari, Chrome
		w = image.naturalWidth;
		h = image.naturalHeight;

	} else if ( typeof image.runtimeStyle !== 'undefined' ) {	// for IE
		var run = image.runtimeStyle;
		var mem = { w: run.width, h: run.height };  // keep runtimeStyle
		run.width  = "auto";
		run.height = "auto";
		w = image.width;
		h = image.height;
		run.width  = mem.w;
		run.height = mem.h;

	} else {		 // for Opera
		var mem = { w: image.width, h: image.height };  // keep original style
		image.removeAttribute("width");
		image.removeAttribute("height");
		w = image.width;
		h = image.height;
		image.width  = mem.w;
		image.height = mem.h;
	}

	return {width:w, height:h};
}
function addFigure(thisData) {
	var changeNum = new String(thisData).replace(/,/g, "");
	while(changeNum != (changeNum = changeNum.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return changeNum;

}


/*
#　c-po scroller ver0.2b
#　since: 2009.10.22
#　last up date: 2010.04.28
#
#　jQueryが必要です
#
#　ページ送り的にスクロールしてくれます
#　基本、css指定だけです。
#　下にある設定項目部分で、ターゲットにする要素をCSS的に指定してください
#
#　別ページからのID属性でのジャンプとか
#　ページ内のID属性のジャンプにも対応しました。
#　※別ページからのIDジャンプがうまく動かないので、調整中
#　　#での指定を?に強制的に置き換えて、受け側で取得するようにする(未定)
#
#　ページ内のナビゲーションは、こんな風に指定してください
#　一番上へ: <span class="cpo-totop"></span>
#　1画面上へ: <span class="cpo-toprev"></span>
#　1画面下へ: <span class="cpo-tonext"></span>
#　前のターゲットへ: <span class="cpo-toprevtarget"></span>
#　次のターゲットへ: <span class="cpo-tonexttarget"></span>
#
###########
#　対応ブラウザ
#　IE6以上
#　FF
#　chrome
#　Opera
#　Safari(4.04 Winで確認）は、なんか変な残像が残って変...　コントローラをcssでfixedにするなら大丈夫かな？
###########
#
#　2010.03.18 / スクロールが変なので調整
#　2010.03.23 / IDジャンプのスクロールを調整
#　　　　　　 / Operaのスクロールが変だったのを修正　晴れてOpera対応ということで
#　2010.04.28 / なんか挙動が変なので調整
#　　　　　　 / FireFoxで、次のターゲット押下時、最後のターゲットに行かない
#　　　　　　 / どうやら小数点以下の数値で現在地点にズレがでるからのよう
#　　　　　　 / javascriptは小数点以下の計算精度が低いのと、ブラウザ表示は当然1px単位だからか
#　　　　　　 / ターゲット決定の際、小数点以下切り捨てにする
#*/

/*▼▼▼▼▼設定項目▼▼▼▼▼*/
/*ターゲットにする要素をCSS的に指定してください*/
cpoDOMSelector = '#article h2,#article h3';	/* h2 / body h3 / h2.className ...etc */

/*付いてきてほしい要素をCSS的に指定*/
cpoStalkerBox = '#cpopagescrnavigator';

/*▲▲▲設定項目おしまい▲▲▲*/

/*===== スムーススクロールみたいなヤツ =====*/
var cpoScroll = function(){
	this.scrollTop = function(){
		var cpoYNowPos = 0;
		this.scrollBody(cpoYNowPos);
	}
	this.scrollPrev = function(){
		var cpoYNowPos = 0;
		var cpoNowPoint = $(document).scrollTop();
		var cpoWindowHeight = cpoGetWindowSize();
		if( cpoYNowPos > 100 ){
			cpoYNowPos  = cpoNowPoint - cpoWindowHeight.height + 100;
		}
		else{
			cpoYNowPos  = Math.max( 0,cpoNowPoint - cpoWindowHeight.height + 100 );
		}

		this.scrollBody(cpoYNowPos);
	}
	this.scrollNext = function(){
		var cpoYNowPos = 0;
		var cpoWindowHeight = cpoGetWindowSize();
		var cpoNowPoint = $(document).scrollTop();

		if( ( cpoNowPoint + cpoWindowHeight.height ) > ( $(document).height() - cpoNowPoint ) ){
			cpoYNowPos  = $(document).height() - cpoWindowHeight.height;
		}
		else{
			cpoYNowPos  = (cpoWindowHeight.height - 100) + cpoNowPoint;
		}

		this.scrollBody(cpoYNowPos);
	}
	this.scrollPrevTarget = function(){
		var cpoTargetPoint = new Array();
		for( i = 0; i < $(cpoDOMSelector).length; i++ ){
			cpoTargetPoint[i] = $( $(cpoDOMSelector)[i] ).offset();
		}
		var cpoNowPoint = $(document).scrollTop();
		var cpoYNowPos = undefined;
		var cpoWindowHeight = cpoGetWindowSize();

		for( i = 0; i < cpoTargetPoint.length; i++ ){
			if( Math.floor(cpoTargetPoint[i].top) < Math.floor(cpoNowPoint) ){
				if( cpoYNowPos != undefined ){
					cpoYNowPos = Math.max(cpoYNowPos,cpoTargetPoint[i].top);
				}
				else{
					cpoYNowPos = cpoTargetPoint[i].top;
				}
			}
		}
		if( cpoYNowPos == undefined ){
			cpoYNowPos = 0;
		}
		this.scrollBody(cpoYNowPos);
	}
	this.scrollNextTarget = function(){
		var cpoTargetPoint = new Array();
		for( i = 0; i < $(cpoDOMSelector).length; i++ ){
			cpoTargetPoint[i] = $( $(cpoDOMSelector)[i] ).offset();
		}
		var cpoWindowHeight = cpoGetWindowSize();
		var cpoNowPoint = $(document).scrollTop();

		var cpoYNowPos = undefined;
		for( i = 0; i < cpoTargetPoint.length; i++ ){
			if( Math.floor(cpoTargetPoint[i].top) > Math.floor(cpoNowPoint) ){
				if( cpoYNowPos != undefined ){
					cpoYNowPos = Math.min(cpoYNowPos,cpoTargetPoint[i].top);
				}
				else{
					cpoYNowPos = cpoTargetPoint[i].top;
				}
			}
		}
		if( cpoYNowPos == undefined ){
			cpoYNowPos  = $(document).height() - cpoWindowHeight.height;
		}
		cpoYNowPos = Math.min( cpoYNowPos , ( $(document).height() - cpoWindowHeight.height) );

		this.scrollBody(cpoYNowPos);
	}
	this.scrollIDJump = function(){
		var cpoScrollTarget = location.href.split("?");
		
		var cpoScrollTarget = $('#'+cpoScrollTarget[1]);
		var cpoScrollTarget = cpoScrollTarget.offset();
		
		this.scrollBody( cpoScrollTarget.top );
	}
	this.scrollIDMove = function(cpoScrollTargetID){
		var cpoScrollTarget = $(cpoScrollTargetID);
		var cpoScrollTarget = cpoScrollTarget.offset();
		var cpoWindowHeight = cpoGetWindowSize();

		var cpoYNowPos = Math.min( cpoScrollTarget.top , $(document).height() - cpoWindowHeight.height );

		this.scrollBody( cpoYNowPos );
	}
	this.scrollBody = function(cpoYLandingPos){

		var cpoScrollBodyName = $.support.boxModel ? navigator.appName.match(/Opera/) ? "html" : "html,body" : "body";
		$(cpoScrollBodyName).animate({ scrollTop: cpoYLandingPos + 'px' }, 500,'easeInOutCubic');
	}
}
/*===== ついてくるやつ =====*/
var cpoStalker = function(){
	var cpoNaviPos = $('#cpopagescrnavigator').css('top');
	if( ! cpoNaviPos.match(/px/) ){
		cpoNaviPos = 0;
	}
	this.naviPos = cpoNaviPos.replace(/px/i,'');
	this.move = function(){
		var cpoNowPoint = Math.max( $('html').scrollTop() , $('body').scrollTop() );
		var cpoStalkYou = Math.max( 0 , cpoNowPoint * 1 - $(cpoStalkerBox).parents().offset().top * 1 ) + (this.naviPos*1);
		var cpoStalkYou = Math.min( cpoStalkYou , ($(cpoStalkerBox).parents().height() * 1 - $(cpoStalkerBox).height() * 1 ) );

		$(cpoStalkerBox).animate({ top: cpoStalkYou + 'px' },20);
	}
}

/*===== 汎用 =====*/
/*画面高さ取得 opera対応用*/
function cpoGetWindowSize(){
	return{
		height: (jQuery.browser.opera ?
			document.documentElement.clientHeight : $(window).height()),
		width: (jQuery.browser.opera ?
			document.documentElement.clientWidth : $(window).width())
	}
}

