/* ----------------------------------------------------- */
/* 物件詳細印刷用CSS（detail-print.css）適用 */
/* ----------------------------------------------------- */
if(window.name == "printWindow"){
	var printCss = 'css/detail-print.css';
	var loc = document.getElementsByTagName('link')[0].getAttribute('href').split('css')[0] + printCss;
	document.write('<link rel="stylesheet" href="'+ loc +'" type="text/css" media="all" />');
}

/* CSSハック用 */
/* ----------------------------------------------------- */
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();

/* ----------------------------------------------------- */
/* noConflict*/
/* ----------------------------------------------------- */
var $j =jQuery.noConflict();

changeImg = 0;
var siPreLoad = [];
/* ----------------------------------------------------- */
/* jquery ロード*/
/* ----------------------------------------------------- */
$j(function(){

	/* aタグクリック時の枠線無効に */
	/* ----------------------------------------------------- */
	$j('a').focus(
		function(){
		this.blur();
	});

	/* 関数Call */
	/* ----------------------------------------------------- */
		/* TOP 自分の希望で住宅・マンションを選ぶ！ 物件2件ごとに高さ揃える */
		flat('#pickup-article','div',2);

		/* ハッピータウン　地域情報 写真6枚ごとに高さ揃える */
		flat('#happy-town-article ul.area-pic','li',6);
		
		/* 物件詳細画像スワップ */
		SwapImg('#iframes #thum a','#pic-wrap #main-pic')


		/* 物件詳細　お問い合わせページへの物件名引継ぎ */
		setNum('#iframes li.inq a');

		/* iframeコンテンツ */
		iframeHeight('#new-area-iframe');
		
		/* 相互リンクソースコピー */
		linkFunc('#main p.code textarea');

		
	/* ロールオーバー */
	/* ----------------------------------------------------- */
	$j('img.over').not('[src*="-o."]').hover(function()
	{
		Rollover($j(this),$j(this).attr('src'));	
	},function() {
		Rollover($j(this),$j(this).attr('src'));	
	});	

	/* ページ内スクロール */
	/* ----------------------------------------------------- */
  $j('a[href^=#]').click(function(event) {
    var hash = this.hash;
		if(hash!==''){
			var tarPosition = $j(hash).offset().top;
			if(undefined !== window.opera && "function" === typeof window.opera.version){ // opera
				$j('html').animate({scrollTop: tarPosition}, 400, 'easeOutQuad'); 
			}
			else{
				$j('html, body').animate({scrollTop: tarPosition}, 400, 'easeOutQuad');
			}
			return false;
		}
  });

	/* フォーム */
	/* ----------------------------------------------------- */
	$j("table input,table textarea").focus(function(){
		$j(this).addClass('focus');															
  });
	$j("table input,table textarea").blur(function(){
		$j(this).removeClass('focus');															
  });

	/* 物件詳細ページ　プリントページ開く*/
	/* ----------------------------------------------------- */
	$j('#iframes li.print').click(function(){
		openPrintWin(660,700);
		return false;
	});

	/* 施工事例ページ　写真開く*/
	/* ----------------------------------------------------- */
	popupWindow('#example-warp .left-e a.to-popup',660,660,'example1');
	popupWindow('#example-warp li a.to-popup',660,660,'example2');
	popupWindow('#example-warp dt a.to-popup',660,660,'example3');
	popupWindow('#proposal-warp a.to-popup',660,660,'proposal');
	popupWindow('ul.bnr-artilce a.to-popup',800,600,'proposal');
	popupWindow('ul.bnr01 a.to-popup',800,600,'proposal');
	/* ポップアップウィンドウを閉じる */
	/* ----------------------------------------------------- */
	$j('#cls img').click(function(){
		window.close();
	});

	/* 印刷ボタン */
	/* ----------------------------------------------------- */
	$j('#printPageBtn img').click(function(){
			window.print();
	});

	/* エリアタブ */
	/* ----------------------------------------------------- */
	$j('#area ul.tab a').click(function(){
		if(!$j(this).hasClass('active')){
			$j(this).parents('ul').find('.active').removeClass('active');
			$j(this).addClass('active');
		}
	});
	
	/* topニュースチェッカー */
	/* ----------------------------------------------------- */
	if($j("#news-ticker").size()==1){
		$j("#news-ticker").liScroll({travelocity: 0.03});
	}
	/* addclass */
	/* ----------------------------------------------------- */
	//$j('#station-list .station-name dl:even').addClass('even');
	$j('#station-list-i dl:even').addClass('even');
	$j('#sitemap li:first').addClass('first');
	$j('#sitemap li:last-child').addClass('close');
	if($j('body').hasClass('iframe')){
		$j('html').addClass('iframe');
	}

});

/* ----------------------------------------------------- */
/*　ページ内スクロール用　*/
/* ----------------------------------------------------- */
jQuery.easing.easeOutQuad = function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
};

/* ----------------------------------------------------- */
/*　ロールオーバー　*/
/* ----------------------------------------------------- */
var Rollover = function(obj,thisSrc) {
	/* 変数宣言 */
	var sTempSrc = thisSrc;
	var ftype = thisSrc.substring(thisSrc.lastIndexOf('.'), thisSrc.length);
	var hsrc = thisSrc.replace(ftype, '-o'+ftype);	
	var aPreLoad = new Image();

	/* プリロード */
	aPreLoad.src = hsrc;

	re = new RegExp('-o');
	
	if(!sTempSrc.match(re)){
		$j(obj).attr('src', hsrc);
	}
	
	if (sTempSrc.match(re)) {
		sTempSrc = $j(obj).attr('src').replace('-o'+ftype, ftype);
		$j(obj).attr('src', sTempSrc);
	}
}
/* ----------------------------------------------------- */
/* iframeの高さ調整 */
/* ----------------------------------------------------- */
var iframeHeight = function(tar){

	if(window.parent.document && $j('#frames').size()!=0){
		height = $j('#frames div:eq(0)').height();
		$j(tar,window.parent.document).height(height);
	}
}

/* iframeの高さ取得 */
/* ----------------------------------------------------- */

function getHeight(id, name)
{
    if (document.height) {
        if(parent.frames[name].document.height > 0) {
            fh = parent.frames[name].document.height + 30;
        }
    } else {
        if(parent.frames[name].document.body.scrollHeight > 20) {
            fh = parent.frames[name].document.body.scrollHeight;
        }
    }
    document.getElementById(id).style.height = fh + "px";
}

/* ----------------------------------------------------- */
/* リンクソースコピー　*/
/* ----------------------------------------------------- */
var linkFunc  = function(obj){	
	$j(obj).click(function(){
		$j(this).select();																	 
	})
	.focus(function(){
		$j(this).select();																			 
	});
};

/* ----------------------------------------------------- */
/* flatHeights */
/* ----------------------------------------------------- */
var flat = function(obj,flatobj,num){
	var sets = [], temp = [];
	/* numごとで高さ揃える */
		$j(obj).find(flatobj).each(function(i) {
				temp.push(this);
				if ((i+1) % num == 0) {
						sets.push(temp);
						temp = [];
				}
		});
		if (temp.length) sets.push(temp);

		/* 各組ごとに高さ揃え */
		$j.each(sets, function() {
				$j(this).flatHeights();
		});
		sets = [], temp = [];
}

/* ----------------------------------------------------- */
/* スワップ */
/* ----------------------------------------------------- */
var SwapImg = function(href,mainImg){
	/* プリロード */
	$j(href).each(function(i){				
	src = $j(this).attr('href');
	siPreLoad[i] = new Image();
	siPreLoad[i].src = src;
	});
	Max = $j(href).length;
	imgTimer = setInterval('sizeCheck(changeImg)',100);

	/* クリック */
	$j(href).click(function(){
		src = $j(this).attr('href');
		imgClass = $j(this).attr('class');
		$j(mainImg).find('img').removeClass().addClass(imgClass).attr('src',src);
		return false;
	});
}

/* プリロード直後は画像がキャッシュされないみたいなのでsetIntervalでディレイ処理　 */
var sizeCheck = function(i,href){
	if(i<Max){
		changeImg++;
		var w = siPreLoad[i].width;
		var h = siPreLoad[i].height;
		var compar = Math.ceil(h*(558/w));
		if(compar>367){
			$j('#iframes #thum a,#open-houselist #thum a').eq(i).addClass('h100');
		}else{
			$j('#iframes #thum a,#open-houselist #thum a').eq(i).addClass('w100');
		}
		if(i===0){
			var imgSize = $j('#iframes #thum a,#open-houselist #thum a').eq(0).attr('class');
			$j('#iframes #main-pic img,#open-houselist #main-pic img').eq(0).addClass(imgSize)
		}
	}
	else{
			clearInterval(imgTimer);
	}
}

/* ----------------------------------------------------- */
/* 印刷用ページポップアップ */
/* ----------------------------------------------------- */
var openPrintWin= function(w,h){
		var features="scrollbars=yes";
		features+=", left="+(window.screen.width-w)/2;
		features+=", top="+(window.screen.height-h)/2;
		features+=", width="+w;
		features+=", height="+h;
		var newWin = window.open(window.location.href,"printWindow",features);
		newWin.focus();
}


/* ----------------------------------------------------- */
/* ポップアップウィンドウ開く */
/* ----------------------------------------------------- */
var popupWindow = function(tar,w,h,windowName){
	$j(tar).click(function(){
		var Loc = $j(this).attr('href');
		var features="scrollbars=yes,resizable=yes";
		features+=", left="+(window.screen.width-w)/2;
		features+=", top="+(window.screen.height-h)/2;
		features+=", width="+w;
		features+=", height="+h;
		var newWin=window.open(Loc,windowName,features);
		newWin.focus();
		return false;
	});
}

/* ----------------------------------------------------- */
/* 物件名引継ぎ */
/* ----------------------------------------------------- */
var setNum = function(obj){
	$j(obj).click(function(){
		var Insert_No = new Array();
		var Parameter = new Array();	
		Parameter[0] = "No_Name";
		var Str,Target,Value;
		var Set_Url ="";
		Value = "";
		URL =$j(this).attr("href");
		Str = $j('#num').text();
		Value += Str;
		Set_Url += "?" +Parameter[0]  + "=" + escape(Value);
		URL = URL + Set_Url;
		$j(this).attr("href",URL)
	});
}


