// #require MooTools 1.2.x
if (window.addEvent) {

// Fix Opacity Treatment
Element.Properties.opacity.set = function (opacity, novisibility) {
	if (!novisibility){
		if (opacity == 0) {
			if (this.style.visibility != 'hidden') this.style.visibility = 'hidden';
		} else {
			if (this.style.visibility != 'visible') this.style.visibility = 'visible';
		}
	}
	if (!this.currentStyle || !this.currentStyle.hasLayout) this.style.zoom = 1;
	if (Browser.Engine.trident) {
		if (opacity == 1) {
			this.style.filter = this.style.filter.replace(/alpha\(opacity=[0-9\.]+\)/, '').clean();
		} else {
			try {
				if (this.filters && this.filters['alpha']) {
					this.filters['alpha'].opacity = opacity * 100;
				} else {
					this.style.filter = (this.style.filter + ' alpha(opacity=' + opacity * 100 + ')').clean();
				}
			} catch (ex) {
				// When this element is not injected inside DOM.
				this.style.filter = (this.style.filter + ' alpha(opacity=' + opacity * 100 + ')').clean();
			}
		}
	}
	this.style.opacity = opacity;
	this.store('opacity', opacity);

};
// Adjust Transitions.Expo
Fx.Transitions.extend({
	Expo: function(p){
//		return Math.pow(2, 8 * (p - 1));	// original
		return Math.pow(2, 8 * (p - 1)) - 1/256;	// result is exactly 0 when p := 0
//		return (Math.pow(2, 8 * p) - 1) / 255;	// result is exactly 0 when p := 0, and exactly 1 when p := 1
	}
});



//Simple Rollover
window.addEvent('domready', function(){
//		var selectors = [
//			"a.rollover",	// 一般A
//			"img.rollover",	// 一般B
//			"input.rollover"	// 一般C
//		];
	// 画像の切り替え表示
	var fn_mover_factory = function(theObj) {
		return function () {
			theObj.target.src = theObj.sw_img.src;
		};
	};
	var fn_mout_factory = function(theObj) {
		return function () {
			theObj.target.src = theObj.or_img.src;
		};
	};
	$$('a.rollover, img.rollover, input.rollover').each(function (elm) {
		var imgs = [elm];
		if (!elm.src) {
			imgs = elm.getElements('img');
		}
		imgs.each(function (img) {
			if (img.src.test(/^.+-(act|on)\.(gif|jpg|jpeg|xbm|png)(\?.*)?$/))	return;
			var or_img = new Image;
			var sw_img = new Image;
			if (window.IEPNGFIX && (img.filters[IEPNGFIX.filter] || (/\.png(\?.*)?$/i).test(img.src))) {
				IEPNGFIX.fix(img);
				or_img.src = img.filters[IEPNGFIX.filter].src;
				sw_img.src = or_img.src.replace(
					/^(.+)(?:-on)?(\.(gif|jpg|jpeg|xbm|png)(\?.*)?)$/,
					"$1-on$2");
				var obj = {
					"target": img.filters[IEPNGFIX.filter],
					"or_img": or_img,
					"sw_img": sw_img
				};
			} else {
				or_img.src = img.src;
				sw_img.src = img.src.replace(
					/^(.+)(?:-on)?(\.(gif|jpg|jpeg|xbm|png)(\?.*)?)$/,
					"$1-on$2");
				var obj = {
					"target": img,
					"or_img": or_img,
					"sw_img": sw_img
				};
			}
			this.addEvent('mouseenter', fn_mover_factory(obj));
			this.addEvent('mouseleave', fn_mout_factory(obj));
		}, elm);
	});
	// imageMap-rollover
	$$('map').each(function (map) {
//		var img = $$('img[usemap$=' + map.id + ']')[0];
		var img = $$('img[usemap]').filter(function (img) {
			return (img.getAttribute('usemap') == '#' + map.id);
		})[0];
		if (!img)	return;
		var areas = map.getElements('area.rollover');
		if (!areas.length)	return;
		var orImg = new Image;
		orImg.src = img.src;
		var re = new RegExp("^" + map.id + "-(.+)$");
		areas.each(function (area) {
			var id = area.id.match(re)[1];
			if (!id)	return;
			var roImg = new Image;
			roImg.src = img.src.replace(
				/^(.+)(\.(gif|jpg|jpeg|xbm|png))$/,
				"$1-" + id + "$2"
			);
			area.addEvent('mouseenter', function () {
				img.src = roImg.src;
			});
			area.addEvent('mouseleave', function () {
				img.src = orImg.src;
			});
		});
	});
});

}

// Smooth Scroll
if (window.MooTools && window.SmoothScroll) {
	window.addEvent('domready', function () {
		new SmoothScroll({
			transition: Fx.Transitions.Expo.easeOut,
			links: $$('a.inn-link, area.inn-link')
		});
	});
}
