/* 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;
}();

/* ----------------------------------------------------- */
/* jquery ロード*/
/* ----------------------------------------------------- */
$(function(){

	/* aタグクリック時の枠線無効に */
	/* ----------------------------------------------------- */
	$('a').focus(
		function(){
		this.blur();
	});

	/* 関数Call */
	/* ----------------------------------------------------- */
	/* 物件詳細お問い合わせページへの物件名引継ぎ */
	setNum('#contents a.to-inq');

	/* 過去チラシ一覧3件ごとに高さ揃える */
	flat('#flyer-back-num','>dl',3);
	
	/* 施工事例2件ごとに高さ揃える */
	flat('#example-wrap dl','dd',2);
	
	
	/* ロールオーバー */
	/* ----------------------------------------------------- */
	$('img.over').not('[src*="-o."]').hover(function()
	{
		Rollover($(this),$(this).attr('src'));	
	},function() {
		Rollover($(this),$(this).attr('src'));	
	});	

	/* ページ内スクロール */
	/* ----------------------------------------------------- */
  $('a[href^=#]').click(function(event) {
    var hash = this.hash;
		if(hash!==''){
			var tarPosition = $(hash).offset().top;
			if(undefined !== window.opera && "function" === typeof window.opera.version){ // opera
				$('html').animate({scrollTop: tarPosition}, 400, 'easeOutQuad'); 
			}
			else{
				$('html, body').animate({scrollTop: tarPosition}, 400, 'easeOutQuad');
			}
			return false;
		}
  });

	/* addclass */
	/* ----------------------------------------------------- */
	$('#gnav li:last-child').addClass('last-c');
	$('#side #news dd.wrap dd:last').addClass('last-c');
	$('div.intermediate-list dd.wrap div dl:last-child').addClass('last-c');
	$('dl.joyhouse-list dd.wrap div dl:last-child').addClass('last-c');
	$('#sitemap li:first').addClass('first');
	$('#sitemap li:last-child').addClass('close');

	/* 仲介物件一覧　soldoutの画像を縦センターに */
	if($('div.intermediate-list dd.wrap p.price').size()>0){
		$('div.intermediate-list dd.wrap p.price').each(function(){
			var obj = $(this);
			var marT = eval((obj.next('div').height()-$('img',obj).height())/2-6);
			$('img',obj).css('margin-top',marT+'px')
		
		});
	}

	/* 物件詳細　お問い合わせボタンに物件名設定 */
	/* ----------------------------------------------------- */
	if($('#environ-map').size()===1){
		$('#contents a.to-inq').each(function(){
			var aName = $('#contents h2:first').text();
			$(this).attr('title',aName);
		});
	}

	/* フォーム */
	/* ----------------------------------------------------- */
	$("table input,table textarea").focus(function(){
		$(this).addClass('focus');															
  });
	$("table input,table textarea").blur(function(){
		$(this).removeClass('focus');															
  });

});

/* ----------------------------------------------------- */
/*　ページ内スクロール用　*/
/* ----------------------------------------------------- */
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)){
		$(obj).attr('src', hsrc);
	}
	
	if (sTempSrc.match(re)) {
		sTempSrc = $(obj).attr('src').replace('-o'+ftype, ftype);
		$(obj).attr('src', sTempSrc);
	}
}

/* ----------------------------------------------------- */
/* flatHeights */
/* ----------------------------------------------------- */
var flat = function(obj,flatobj,num){
	var sets = [], temp = [];
	/* numごとで高さ揃える */
		$(obj).find(flatobj).each(function(i) {
				temp.push(this);
				if ((i+1) % num == 0) {
						sets.push(temp);
						temp = [];
				}
		});
		if (temp.length) sets.push(temp);

		/* 各組ごとに高さ揃え */
		$.each(sets, function() {
				$(this).flatHeights();
		});
		sets = [], temp = [];
}

/* ----------------------------------------------------- */
/* 物件名引継ぎ */
/* ----------------------------------------------------- */
var setNum = function(obj){
	$(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 =$(this).attr("href");
		Str = $(this).attr("title");
		Value += Str;
		Set_Url += "?" +Parameter[0]  + "=" + escape(Value);
		URL = URL + Set_Url;
		$(this).attr("href",URL)
	});
}

