// ============================================================ 
// jQuery と prototype コンフリクト対策
// ============================================================ 
jQuery.noConflict();
var $j = jQuery;

// ============================================================ 
// ロールオーバー
// ============================================================ 
var rollover = {
	swap:function(){
		$j("img.swap").each(function(i) {
			var imgsrc = this.src;
			var dot = imgsrc.lastIndexOf(".");
			var imgsrc_on = imgsrc.substr(0, dot) + '_on' + imgsrc.substr(dot, 4);
			$j("<img>").attr("src", imgsrc_on);
			
			$j(this).hover(
				function() { this.src = imgsrc_on; },
				function() { this.src = imgsrc; }
			);
		});
	},
	
	bright:function(){
		$j("img.bright").mouseover(function(){
			$j(this).css({opacity: 0.25}).fadeTo(300, 1);
		});
	},
	
	alpha:function(){
		$j("img.alpha").hover(
			function() { $j(this).fadeTo(250, 0.6); },
			function() { $j(this).fadeTo(250, 1); }
		);
	}
}

$j(document).ready(function(){
	rollover.swap();
	rollover.bright();
	rollover.alpha();
});

// ============================================================ 
// スムーズスクロール
// ============================================================ 
$j(function() {
		
	$j('.pagetop').click(function(){
		if($j.browser.safari && $j.browser.version.charAt(0)<5) {
			location.href = "#header";
		} else {
			$j(this).blur();
			$j('html,body').animate({scrollTop: 0}, 'slow');
			return false;
		}
	});
});

function pageScroll(id) {
	if($j.browser.safari && $j.browser.version.charAt(0)<5) {
		location.href = id;
	} else {
		var targetOffset = $j(id).offset().top;
		$j('html,body').animate({ scrollTop: targetOffset }, 'slow');
	}
}

// ============================================================ 
// フォーム入力フィールドにあらかじめテキストを表示
// ============================================================ 
$j(function () {
	var supportsInputAttribute = function (attr) {
		var input = document.createElement('input');
		return attr in input;
	};
	if (!supportsInputAttribute('placeholder')) {
		$j('[placeholder]').each(function () {
		var
			input = $j(this),
			placeholderText = input.attr('placeholder'),
			placeholderColor = 'GrayText',
			defaultColor = input.css('color');
		input.
			focus(function () {
				if (input.val() === placeholderText) {
					input.val('').css('color', defaultColor);
				}
			}).
			blur(function () {
				if (input.val() === '') {
					input.val(placeholderText).css('color', placeholderColor);
				} else if (input.val() === placeholderText) {
					input.css('color', placeholderColor);
				}
			}).
			blur().
			parents('form').
				submit(function () {
					if (input.val() === placeholderText) {
						input.val('');
					}
				});
		});
	}
});

// ============================================================ 
// このサイト用に定義
// ============================================================ 
var azito = {
	init:function() {
	},
	
	// コーナー角丸
	corner:function() {
		setting1 = {
			tl: { radius: 5 },
			tr: { radius: 5 },
			bl: { radius: 5 },
			br: { radius: 5 },
			antiAlias: true,
			autoPad: true,
			validTags: ["div"]
		}
		if($j(".corner1, .link, .box-type1, .box-type2, .gallery ul li.link a, .gallery2 ul li.link a").length) {
			$j(".corner1, .link, .box-type1, .box-type2, .gallery ul li.link a, .gallery2 ul li.link a").corner(setting1);
		}
	}
}

$j(document).ready(function(){
	azito.init();
	azito.corner();
});

