/* スムーズスクロール ######################################################## */
function util_scroll(){
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			
		   if ($target.length) {
		   		var targetOffset = $target.offset().top;
		   		
		   		$('html,body').animate({scrollTop: targetOffset},500);
				return false;
			}
		}
	});
}

/* ロールオーバー */
function util_rollover(){
	// gif
	$('img.rollover[src$=".gif"]').hover(
		function() {
			this.src = this.src.replace(".gif","_o.gif");
		},
		function() {
			this.src = this.src.replace("_o.gif",".gif");
		}
	);
	// png
	$('img.rollover[src$=".png"]').hover(
			function() {
				this.src = this.src.replace(".png","_o.png");
			},
			function() {
				this.src = this.src.replace("_o.png",".png");
			}
		);
	
}

// 古いIEへmin-heightを適用させる
$.fn.set_minHeight = function(){
	return this.each(function(){
		var minHeight = $(this).css('min-height');
		if(minHeight != 'auto') $(this).css('height',minHeight);
	});
}

// 古いIEへclearfixを適用させる
var set_clearfix = function(){
	//$('.clearfix,.layoutWrapper').css('min-height','24px').next().addClass('clear');
	$('.clearfix,.layoutWrapper').css("zoom","1")
}

// プレースホルダー(inputにplaceholder=""を設定する)
var placeHolder = function(){
	$("input:text[placeholder]").each(function(){
		var t = $(this),
			text = t.attr("placeholder");
		
		t.val(text).css("color","#999");
		
		t.focus(function(){
			if($(this).val() == text) $(this).val("").removeAttr("style");
		}).blur(function(){
			if($(this).val() == "") $(this).val(text).css("color","#999");
		})
	});
}

/* pageTop関連 */
pageTop = function(){
	$(window).scroll(function(){
		if($(document).scrollTop() > 0){
			if($("#pageTop:hidden").length)$("#pageTop").fadeTo("fast",0.33);
		}else{
			$("#pageTop").hide();
		}
	})
	$("#pageTop").hover(function(){
		$(this).fadeTo("fast",1);
	},function(){
		if($(document).scrollTop() > 0){
			$("#pageTop").fadeTo("fast",0.33);
		}else{
			$("#pageTop").hide();
		}
	})
	
	if($(window).width() < 1022) $("#pageTop").css("right","12px")
	$(window).resize(function(){
		if($(window).width() < 1022){
			$("#pageTop").css("right","12px")
		}else{
			$("#pageTop").css("right","")
		}
	})
}
/* 読み込み完了後に実行 ######################################################## */
$(document).ready(function(){
	util_scroll();
	util_rollover();
	
	pageTop();
	/* IE対策 */
	if($.browser.msie){
		if($.browser.version < 8) set_clearfix();
	}
	if ($.browser.msie && $.browser.version < 9 ) $("html").addClass("ie");
	if ($.browser.msie && $.browser.version <= 7 ) $("html").addClass("ie7");
	if ($.browser.msie && $.browser.version <= 8 ) $("html").addClass("ie8");
	if ($.browser.msie && $.browser.version == 9 ) $("html").addClass("ie9");
});
