// *** BUSINESS BLOCK OPEN/CLOSE
var append_css_path = '/products/catalog/common/css/with_js.css';
//var append_css_path = '../common/css/with_js.css';	// for Test
if (window.Asset && Asset.css) {
	Asset.css(append_css_path);
} else {
	new Element('link', {
		rel: 'stylesheet',
		media: 'screen',
		type: 'text/css',
		href: append_css_path
	}).inject(document.head);
}
window.addEvent('domready', function () {
	$$('.btn_toggle_layer').each(function (link) {
		var id = link.href.replace(/^.*#([^#]+)$/, "$1");
		var target = $(id);
		if (!target)	return;
		link.addEvent('click', function (evt) {
			evt.stop();
			target.setStyle('display', ((target.getSize().y == 0) ? 'block' : 'none'));
		});
	});
});

//
if (!Fx.Elements) {
// Fx.Elements ** By MooTools_More
Fx.Elements = new Class({

	Extends: Fx.CSS,

	initialize: function(elements, options){
		this.elements = this.subject = $$(elements);
		this.parent(options);
	},

	compute: function(from, to, delta){
		var now = {};
		for (var i in from){
			var iFrom = from[i], iTo = to[i], iNow = now[i] = {};
			for (var p in iFrom) iNow[p] = this.parent(iFrom[p], iTo[p], delta);
		}
		return now;
	},

	set: function(now){
		for (var i in now){
			var iNow = now[i];
			for (var p in iNow) this.render(this.elements[i], p, iNow[p], this.options.unit);
		}
		return this;
	},

	start: function(obj){
		if (!this.check(obj)) return this;
		var from = {}, to = {};
		for (var i in obj){
			var iProps = obj[i], iFrom = from[i] = {}, iTo = to[i] = {};
			for (var p in iProps){
				var parsed = this.prepare(this.elements[i], p, iProps[p]);
				iFrom[p] = parsed.from;
				iTo[p] = parsed.to;
			}
		}
		return this.parent(from, to);
	}

});
}
window.addEvent('domready', function () {
	var visuals = $$('.pr-visual');
	if (!visuals.length)	return;
	var panel = $('pr-indicator');
	var imgPath = $$('#cat-pr-area #pr-indicator ul.menu li')[0].getStyle('background-image').replace(/^url\(["']?(.+\/)bg-pr-indicator\.png.*['"]?\)$/, "$1");
	// for IE6
	if (Browser.Engine.trident4) {
		$$('#cat-pr-area #pr-indicator ul.menu li').setStyle('background-image', 'url(' + imgPath + 'tranceparent.gif)');
		var bgimg_base = new Image;
		bgimg_base.src = imgPath + 'bg-pr-indicator.gif';
		$$('#cat-pr-area #pr-indicator ul.menu li').each(function (li) {
			var coordinates = li.getCoordinates(panel);
			new Element('img', {
				"src": bgimg_base.src,
				"width": 150,
				"height": 25,
				"alt": "",
				"styles": {
					"position": "absolute",
					"top": coordinates.top,
					"left": coordinates.left,
					"opacity": 0.8
				}
			}).inject(panel);
		});
	}
	//
	var fx = new Fx.Elements(visuals, {
		fps: 75,
		transition: 'sine:in:out',
		link: 'cancel'
	});
	var interval = 6000;	// 自動スライド時間間隔
	var propSlideIn = {
		left: [520, 0]
	};
	var propSlideOut = {
		left: [0, -520]
	};
	var length = visuals.length;
	var current = 0;
	var opt_init = {};
	for (var i = 0; i < length; i++) {
		opt_init[i] = {
			left: ((i == current) ? 0 : 520),
			'z-index': (length - i)
		}
	}
	fx.set(opt_init);
	//
	var beforeSlideNext = [];
	var slideQueue = [];
	slideQueue.pop_n_push = function () {
		var val = this.pop();
		Array.prototype.push.apply(this, arguments);
		return val;
	};
	var slide = function (next, chain) {
		var fnself = arguments.callee;
		if (fx.timer) {
			if (chain) {
				var pop = slideQueue.pop_n_push(next);
				if (!pop && pop !== 0) {
					fx.chain(function () {
						fnself(slideQueue.pop());
					});
				}
				return
			} else {
				return;
			}
		}
		var org = current;
		next = next || (next === 0 ? 0 : (current + 1));
		if (next < 0 || next >= length)	next = 0;
		if (current == next)	return;
		beforeSlideNext.each(function (fn) {
			fn(next);
		});
		//
		var opt = {};
		opt[org] = propSlideOut;
		opt[next] = propSlideIn;
		fx.start(opt);
		current = next;
	};
	var slideTimer = false;
	var slideNext = function (chain) {
		var fnself = arguments.callee;

		slideTimer = $clear(slideTimer);
		if (fx.timer) {
			if (chain) {
				return fx.chain(fnself);
			} else {
				return fx.chain(function () {
					slideTimer = fnself.delay(interval - fx.options.duration);
				});
			}
		}
		slide(current + 1, chain);
		slideTimer = fnself.delay(interval);
	};
	//
	var indicatorImg = new Image;
	indicatorImg.src = imgPath + 'icon-pr-indicator.gif';
	var indicator = new Element('img', {
		"src": indicatorImg.src,
		"width": 6,
		"height": 9,
		"alt": "",
		"styles": {
			"position": "absolute",
			"left": 9,
			"top": 24,
			"z-index": 50
		}
	}).inject(panel);
	beforeSlideNext.push(function (next) {
		indicator.setStyles({
			"top": (24 + next * 42)
		});
	});
	//
	window.slideNext = slideNext;	// for Debug
	slideTimer = slideNext.delay(interval);
	visuals.addEvent('mouseenter', function (evt) {
		slideTimer = $clear(slideTimer);
	}).addEvent('mouseleave', function (evt) {
		slideTimer = slideNext.delay(interval);
	});
	//
	$$('#cat-pr-area #pr-indicator ul.menu li a').each(function (link, idx) {
		link.mouse_over = null;
		link.addEvent('mouseenter', function (evt) {
			evt.stop();
			if (current == idx) {
				slideTimer = $clear(slideTimer);
				link.mouse_over = true;
			} else {
				link.mouse_over = (function () {
					if (link.mouse_over) {
						link.mouse_over = $clear(link.mouse_over);
						slideTimer = $clear(slideTimer);
						if (current == idx) {
						} else {
							slide(idx, true);
						}
					}
				}).delay(200);
			}
		}).addEvent('mouseleave', function (evt) {
			evt.stop();
			link.mouse_over = $clear(link.mouse_over);
			slideTimer = $clear(slideTimer);
			slideTimer = slideNext.delay(interval);
//		}).addEvent('click', function (evt) {
//			evt.stop();
//			var realLink = visuals[idx].getElement('a');
//			if (realLink) {
//				window.location.href = realLink.href;
//			}
		});
	});
});
// for IE6
if (Browser.Engine.trident4) {
	window.addEvent('domready', function () {
		$$('#footer-pr-area ul#footer-pr-list li').addEvent('mouseenter', function () {
			this.addClass('hover');
		}).addEvent('mouseleave', function () {
			this.removeClass('hover');
		});
	});
}
// for IE6/7
if (Browser.Engine.trident4 || Browser.Engine.trident5) {
	window.addEvent('domready', function () {
		$$('.ruleoff').each(function (el) {
			var prev = el.getPrevious();
			if (!prev || !prev.hasClass('ruleoff')) {
				el.addClass('ruleoff0');
			}
		});
	});
}

