var $ = jQuery;

function createDelegate(func, aThis) {
	var ret = function () {
		return func.apply(aThis, arguments);
	}
	return ret;
}
function preload(src) {
	var self = arguments.callee;
	if (!self.cache) {
		self.cache = {};
	}

	var image = self.cache[src];
	if (!image) {
		image = self.cache[src] = new Image;
		setTimeout(
			function(){
				image.src = src;
			},
			0
		);
	}

	return { src : src };
}
function sanitize(str) {
	return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

function EventDispatcher() {
}
EventDispatcher.prototype.hasEventListener = function (type, listener) {
	if (!this._listeners || !this._listeners[type]) {
		return false;
	}
	if (!listener) {
		return true;
	}
	var listeners = this._listeners[type];
	for (var i = 0, n = listeners.length; i < n; i++) {
		if (listeners[i] === listener) {
			return true;
		}
	}
	return false;
}
EventDispatcher.prototype.addEventListener = function (type, listener) {
	if (!this._listeners) {
		this._listeners = {};
	}
	if (!this._listeners[type]) {
		this._listeners[type] = [];
	}
	this._listeners[type].push(listener);
}
EventDispatcher.prototype.removeEventListener = function (type, listener) {
	if (!this._listeners || !this._listeners[type]) {
		return;
	}
	var listeners = this._listeners[type];
	for (var i = 0, n = listeners.length; i < n; i++) {
		if (listeners[i] === listener) {
			listeners.splice(i, 1);
			return;
		}
	}
}
EventDispatcher.prototype.dispatchEvent = function (event) {
	if (!this._listeners || !this._listeners[event.type]) {
		return;
	}
	var listeners = this._listeners[event.type];
	for (var i = 0, n = listeners.length; i < n; i++) {
		listeners[i](event);
		if (event._stoped) {
			return;
		}
	}
}

function Slideshow(type, node, duration, interval, autoPlay, useFilter) {
	this.type          = "scroll";
	this.node          = null;
	this.items         = [];
	this.imageItems    = [];
	this.selectedIndex = -1;
	this.loop          = true;
	this.scrollLeft    = 0;
	this.scrollTop     = 0;
	this.duration      = 1000;
	this.interval      = 1000;
	this.animateTimer  = null;
	this.rotationTimer = null;
	this.opacity       = 100;
	this.autoPlay      = false;
	this.stoped        = false;

	this.init(type, node, duration, interval, autoPlay, useFilter);
}
Slideshow.prototype = new EventDispatcher;
Slideshow.prototype.init = function (type, node, duration, interval, autoPlay, useFilter) {
	this.type     = type || "";
	this.duration = !isNaN(duration) ? Math.max(duration, 0) : this.duration;
	this.interval = !isNaN(interval) ? Math.max(interval, 0) : this.interval;
	this.autoPlay = autoPlay ? true : false;

	if (node) {
		this.node       = node;
		this.scrollLeft = node.scrollLeft;
		this.scrollTop  = node.scrollTop;
		$(node).addClass("slideshow-enabled");

		var itemNode = $("li", node).each(createDelegate(function(index, node){
			this.append(new Slide(node, this.duration, useFilter));
		}, this));
	}

	if (this.autoPlay) {
		this.addEventListener("animationComplete", createDelegate(function (e) {
			if (!this.stoped) {
				this.startRotation();
			}
		}, this));
	}

	this.addEventListener("change", createDelegate(this.animate, this));
}
Slideshow.prototype.dispose = function () {
	if (this.items) {
		var items       = this.items;
		for (var i = 0, n = items.length; i < n; i++) {
			items[i].dispose();
		}
		this.items      = [];
	}
	this.node       = null;
	this._listeners = null;
	this.clearTimer();
}
Slideshow.prototype.append = function (item) {
	item.deactivate();
	var node = item.node;
	if (this.type == "scroll") {
		var offset = 0;
		var items = this.imageItems;
		for (var i = 0, n = items.length; i < n; i++) {
			offset += items[i].width;
		}
		item.moveTo(offset, 0);
	} else if (this.type == "slideIn") {
		item.moveTo(item.width * -1, 0);
		item.addEventListener("change", createDelegate(function(){
			if (this.isActive) {
				this.fadeIn();
				this.moveTo(this.width * -1, 0);
			} else {
				this.fadeOut();
			}
		}, item));
	} else if (this.type == "fade") {
	}
	this.items.push(item);
	if ($("img", node).length) {
		this.imageItems.push(item);
	}
	return item;
}
Slideshow.prototype.remove = function (item) {
	var ret = null;
	var items = this.items;
	for (var i = 0, n = items.length; i < n; i++) {
		if (item === items[i]) {
			ret = items.splice(i, 1);
			if (i == this.selectedIndex) {
				this.selectedIndex = -1;
			} else if (i <= this.selectedIndex) {
				this.selectedIndex--;
			}
			return ret;
		}
	}
	return ret;
}
Slideshow.prototype.select = function (index) {
	if (this.selectedIndex != index) {
		var oldItem = this.getCurrentItem();
		if (oldItem) {
			oldItem.deactivate();
			this.selectedIndex = -1;
		}
		var newItem = this.getItem(index);
		if (newItem) {
			newItem.activate();
			this.selectedIndex = index;
		}
		this.dispatchEvent({ type: "change", target : this, detail : { oldItem : oldItem, newItem : newItem } });
	}
}
Slideshow.prototype.unselect = function () {
	this.select();
}
Slideshow.prototype.getItem = function (index) {
	return (!isNaN(index) && index >= 0) ? this.items[index] : null;
}
Slideshow.prototype.getCurrentItem = function () {
	return this.items[this.selectedIndex] || null;
}
Slideshow.prototype.scrollTo = function (x, y) {
	this.scrollLeft      = parseInt(x);
	this.node.scrollLeft = parseInt(x);
	this.scrollTop       = parseInt(y);
	this.node.scrollTop  = parseInt(y);
}
Slideshow.prototype.scrollBy = function (x, y) {
	this.scrollLeft      += parseInt(x);
	this.node.scrollLeft += parseInt(x);
	this.scrollTop       += parseInt(y);
	this.node.scrollTop  += parseInt(y);
}
Slideshow.prototype.scrollAnimation = function (startX, endX, dispatch) {
	this.clearAnimateTimer();
	var startAt = new Date;
	this.animateTimer = setInterval(createDelegate(function(){
		var currentTime = Math.min(((new Date) - startAt), this.duration);
		this.scrollTo(this.easing(currentTime, startX, endX - startX, this.duration), 0);
		if (currentTime >= this.duration) {
			this.clearTimer();
			if (dispatch) {
				this.dispatchEvent({ type: "animationComplete", target : this });
			}
			this.dispatchEvent({ type: "scroll", target : this });
		}
	}, this), 1);
}
Slideshow.prototype.prev = function () {
	var index = this.selectedIndex - 1;
	if (index < 0) {
		if (this.loop) {
			index = this.items.length - 1;
		} else {
			index = 0;
		}
	}
	this.select(index);
}
Slideshow.prototype.next = function () {
	var index = this.selectedIndex + 1;
	if (index > this.items.length - 1) {
		if (this.loop) {
			index = 0;
		} else {
			index = this.items.length - 1;
		}
	}
	this.select(index);
}
Slideshow.prototype.animate = function (e) {
	if (this.type == "scroll") {
		this.clearTimer();
		if (e.detail.newItem) {
			var startX = this.scrollLeft;
			var endX   = 0;
			for (var i = 0, n = this.selectedIndex; i < n; i++) {
				endX += this.getItem(i).width;
			}
			this.scrollAnimation(startX, endX, true);
		} else {
			this.scrollTo(0, 0);
			this.dispatchEvent({ type: "animationComplete", target : this });
		}
	} else if (this.type == "slideIn") {
		this.clearTimer();

		if (this.getCurrentItem()) {
			var startX  = this.getCurrentItem().width * -1;
			var endX    = 0;
			var startAt = new Date;

			this.animateTimer = setInterval(createDelegate(function(){
				var currentTime = Math.min(((new Date) - startAt), this.duration);
				this.getCurrentItem().moveTo(this.easing(currentTime, startX, endX - startX, this.duration), 0);
				if (currentTime >= this.duration) {
					this.clearTimer();
					this.dispatchEvent({ type: "animationComplete", target : this });
				}
			}, this), 1);
		}
	} else if (this.type == "fade") {
		this.clearTimer();

		if (e && e.detail) {
			if (!this._fadeEvent) {
				this._fadeEvent = createDelegate(function(){
					this.dispatchEvent({ type: "animationComplete", target : this });
				}, this);
			}
			if (e.detail.oldItem) {
				e.detail.oldItem.removeEventListener("animationComplete", this._fadeEvent);
				e.detail.oldItem.fadeOut();
				if (e.detail.newItem) {
					e.detail.newItem.addEventListener("animationComplete", this._fadeEvent);
					e.detail.newItem.fadeIn();
				}
			} else {
				this.animateTimer = setInterval(createDelegate(function(){
					this.clearTimer();
					this.dispatchEvent({ type: "animationComplete", target : this });
				}, this), this.duration);
			}
		} else {
			this.setOpacity(0);
			var startOpacity  = 0;
			var endOpacity    = 100;
			var startAt       = new Date;

			this.animateTimer = setInterval(createDelegate(function(){
				var currentTime = Math.min(((new Date) - startAt), this.duration);
				this.setOpacity(this.easing(currentTime, startOpacity, endOpacity - startOpacity, this.duration));
				if (endOpacity == 100 && currentTime >= this.duration) {
					this.clearTimer();
					this.dispatchEvent({ type: "animationComplete", target : this });
				}
			}, this), 1);
		}
	} else {
		this.dispatchEvent({ type: "animationComplete", target : this });
	}
}
Slideshow.prototype.easing = function (t, b, c, d) {
	// cubic easing in/out - acceleration until halfway, then deceleration
	if (t >= d) {
		return b + c;
	}
	if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
	return c / 2 *((t -= 2) * t * t + 2) + b;
}
Slideshow.prototype.startRotation = function () {
	this.clearRotationTimer();
	this.stoped = false;
	this.rotationTimer = setTimeout(createDelegate(this.next, this), this.interval);
}
Slideshow.prototype.stopRotation = function () {
	this.stoped = true;
	this.clearRotationTimer();
}
Slideshow.prototype.clearTimer = function () {
	this.clearAnimateTimer();
	this.clearRotationTimer();
}
Slideshow.prototype.clearAnimateTimer = function () {
	if (this.animateTimer) {
		clearInterval(this.animateTimer);
		this.animateTimer = null;
	}
}
Slideshow.prototype.clearRotationTimer = function () {
	if (this.rotationTimer) {
		clearTimeout(this.rotationTimer);
		this.rotationTimer = null;
	}
}
Slideshow.prototype.setOpacity = function (opacity) {
	this.opacity = opacity;
	opacity = parseInt(opacity * 100) / 100;
	this.node.style.opacity = opacity/100;
	this.node.style.filter = "alpha(opacity="+opacity+")";
}

function Slide(node, duration, useFilter) {
	this.node         = null;
	this.width        = 0;
	this.height       = 0;
	this.isActive     = false;
	this.opacity      = 100;
	this.animateTimer = null;
	this.duration     = 1000;

	this.init(node, duration, useFilter);
}
Slide.prototype = new EventDispatcher;
Slide.prototype.init = function (node, duration, useFilter) {
	if (node) {
		this.node   = node;
		this.width  = node.offsetWidth;
		this.height = node.offsetHeight;

		if ($.browser.msie && $.browser.version < 8 && useFilter) {
			$("img", node).each(function(index, node){
				var src = $(node).attr("src");
				if (src.indexOf(".png") != -1) {
					$(node).attr("src", "/img/shared/bg_slide-controller_02.gif");
					node.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '",sizingMethod="image")';
					var alternate = $('<img src="'+src+'" alt="" />')[0];
					var parent = $(node).parent();
					$(window)
						.bind("beforeprint", function(){
							parent[0].insertBefore(alternate, node);
							parent[0].removeChild(node);
						})
						.bind("afterprint", function(){
							parent[0].insertBefore(node, alternate);
							parent[0].removeChild(alternate);
						});
				}
			});
		}

	}
	this.duration = !isNaN(duration) ? Math.max(duration, 0) : this.duration;
}
Slide.prototype.dispose = function () {
	this.node       = null;
	this._listeners = null;
	this.clearTimer();
}
Slide.prototype.activate = function () {
	this.isActive = true;
	$(this.node).addClass("pseudo-active");
	this.dispatchEvent({ type: "change", target : this });
}
Slide.prototype.deactivate = function () {
	this.isActive = false;
	$(this.node).removeClass("pseudo-active");
	this.dispatchEvent({ type: "change", target : this });
}
Slide.prototype.show = function () {
	this.node.style.visibility = "visible";
}
Slide.prototype.hide = function () {
	this.node.style.visibility = "hidden";
}
Slide.prototype.fadeIn = function () {
	this.clearTimer();

	this.setOpacity(0);
	var startOpacity  = 0;
	var endOpacity    = 100;
	var startAt       = new Date;

	this.animateTimer = setInterval(createDelegate(function(){
		var currentTime = Math.min(((new Date) - startAt), this.duration);
		this.setOpacity(this.easing(currentTime, startOpacity, endOpacity - startOpacity, this.duration));
		if (currentTime >= this.duration) {
			this.clearTimer();
			this.dispatchEvent({ type: "animationComplete", target : this });
		}
	}, this), 1);
}
Slide.prototype.fadeOut = function () {
	this.clearTimer();

	this.setOpacity(100);
	var startOpacity  = 100;
	var endOpacity    = 0;
	var startAt       = new Date;

	this.animateTimer = setInterval(createDelegate(function(){
		var currentTime = Math.min(((new Date) - startAt), this.duration);
		this.setOpacity(this.easing(currentTime, startOpacity, endOpacity - startOpacity, this.duration));
		if (currentTime >= this.duration) {
			this.clearTimer();
			this.dispatchEvent({ type: "animationComplete", target : this });
		}
	}, this), 1);
}
Slide.prototype.easing = function (t, b, c, d) {
	// cubic easing in/out - acceleration until halfway, then deceleration
	if (t >= d) {
		return b + c;
	}
	if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
	return c / 2 *((t -= 2) * t * t + 2) + b;
}
Slide.prototype.clearTimer = function () {
	if (this.animateTimer) {
		clearInterval(this.animateTimer);
		this.animateTimer = null;
	}
}
Slide.prototype.moveTo = function (x, y) {
	this.node.style.left = x + "px";
	this.node.style.top  = y + "px";
}
Slide.prototype.setOpacity = function (opacity) {
	this.opacity = opacity;
	opacity = parseInt(opacity * 100) / 100;
	this.node.style.opacity = opacity/100;
	this.node.style.filter = "alpha(opacity="+opacity+")";
}


function SlideshowController(type, node, slideshow, duration, interval, autoPlay, useFilter) {
	this.type          = "scroll";
	this.container     = null;
	this.node          = null;
	this.items         = [];
	this.imageItems    = [];
	this.selectedIndex = -1;
	this.loop          = true;
	this.scrollLeft    = 0;
	this.scrollTop     = 0;
	this.duration      = 800;
	this.interval      = 1000;
	this.animateTimer  = null;
	this.rotationTimer = null;
	this.opacity       = 100;
	this.autoPlay      = false;
	this.slideshow     = null;
	this.prevButton    = null;
	this.nextButton    = null;
	this.stoped        = false;
	this.shownItem     = 4;
	this.scrollIndex   = 0;

	this.init(type, node, slideshow, duration, interval, autoPlay, useFilter);
}
SlideshowController.prototype = new Slideshow;
SlideshowController.prototype.init = function (type, node, slideshow, duration, interval, autoPlay, useFilter) {
	var itemNode = null;
	if (node) {
		this.container = node;
		if ($(node).parents("div.featurePanelA05, div.featurePanelA06").length) {
			this.shownItem = 5;
		}

		this.prevButton = $("li.slide-prev", node)[0] || null;
		if (this.prevButton) {
			$("img", this.prevButton).each(function(index, node){
				var img = $(node);
				var src = img.attr("src");
				img.data("normalSrc", src);
				img.data("hoverSrc",  preload(src.replace(/\.png$/, "_o.png")).src);
				if ($.browser.msie && $.browser.version < 7 && useFilter) {
					img.each(function(index, node){
						$(node).attr("src", "/img/shared/bg_slide-controller_02.gif");
						node.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '",sizingMethod="image")';
					});
				}
			});

			$(this.prevButton)
				.bind("click.slideshow", createDelegate(function () {
					if (!this.animateTimer) {
						this.prev();
					}
					return false;
				}, this))
				.bind("mouseenter.slideshow", createDelegate(function (e) {
					$("img", this.prevButton).each(function(index, node){
						var img = $(node);
						if ($.browser.msie && $.browser.version < 7 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
							img.each(function(index, node){
								node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("hoverSrc");
							});
						} else {
							img.attr("src", img.data("hoverSrc"));
						}
					});
				}, this))
				.bind("mouseleave.slideshow", createDelegate(function (e) {
					$("img", this.prevButton).each(function(index, node){
						var img = $(node);
						if ($.browser.msie && $.browser.version < 7 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
							img.each(function(index, node){
								node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("normalSrc");
							});
						} else {
							img.attr("src", img.data("normalSrc"));
						}
					});
				}, this))
			this.prevButton.parentNode.removeChild(this.prevButton);
		}

		this.nextButton = $("li.slide-next", node)[0] || null;
		if (this.nextButton) {
			$("img", this.nextButton).each(function(index, node){
				var img = $(node);
				var src = img.attr("src");
				img.data("normalSrc", src);
				img.data("hoverSrc",  preload(src.replace(/\.png$/, "_o.png")).src);
				if ($.browser.msie && $.browser.version < 7 && useFilter) {
					img.each(function(index, node){
						$(node).attr("src", "/img/shared/bg_slide-controller_02.gif");
						node.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '",sizingMethod="image")';
					});
				}
			});
			$(this.nextButton)
				.bind("click.slideshow", createDelegate(function () {
					if (!this.animateTimer) {
						this.next();
					}
					return false;
				}, this))
				.bind("mouseenter.slideshow", createDelegate(function (e) {
					$("img", this.nextButton).each(function(index, node){
						var img = $(node);
						if ($.browser.msie && $.browser.version < 7 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
							node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("hoverSrc");
						} else {
							img.attr("src", img.data("hoverSrc"));
						}
					});
				}, this))
				.bind("mouseleave.slideshow", createDelegate(function (e) {
					$("img", this.nextButton).each(function(index, node){
						var img = $(node);
						if ($.browser.msie && $.browser.version < 7 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
							node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("normalSrc");
						} else {
							img.attr("src", img.data("normalSrc"));
						}
					});
				}, this))
			this.nextButton.parentNode.removeChild(this.nextButton);
		}

		itemNode = $("ul.slide-items", node)[0] || null;

		$(node).addClass("slideshow-enabled");
	}
	this.slideshow = slideshow;
	this.addEventListener("change", createDelegate(function (e) {
		if (this.slideshow) {
			this.slideshow.select(this.selectedIndex);
		}
		if (this.imageItems.length > 1 && this.getCurrentItem()) {
			var imageItems = $(this.getCurrentItem().node).prevAll().andSelf().filter(":has(img)");
			if (this.selectedIndex >= 0 && !this.animateTimer) {
				if (imageItems.length) {
					if (imageItems.length - 1 < this.scrollIndex) {
						this.scrollToIndex(imageItems.length - 1, true);
					} else if ((imageItems.length - 1) >= this.scrollIndex + this.shownItem) {
						this.scrollToIndex((imageItems.length - 1) - this.shownItem + 1, true);
					}
				}
			}
			if (this.prevButton) {
				if (imageItems.length - 1 > 0) {
					$(this.container).prepend(this.prevButton);
					$("img", this.prevButton).each(function(index, node){
						var img = $(node);
						if ($.browser.msie && $.browser.version < 7 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
							node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("normalSrc");
						} else {
							img.attr("src", img.data("normalSrc"));
						}
					});
					$(this.prevButton).fadeIn(100);
				} else {
					$(this.prevButton).fadeOut(100, function(){
						if (this.parentNode) {
							this.parentNode.removeChild(this);
						}
					});
				}
			}
			if (this.nextButton) {
				if (imageItems.length - 1 < this.imageItems.length - 1) {
					$(this.container).append(this.nextButton);
					$("img", this.nextButton).each(function(index, node){
						var img = $(node);
						if ($.browser.msie && $.browser.version < 7 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
							node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("normalSrc");
						} else {
							img.attr("src", img.data("normalSrc"));
						}
					});
					$(this.nextButton).fadeIn(100);
				} else {
					$(this.nextButton).fadeOut(100, function(){
						if (this.parentNode) {
							this.parentNode.removeChild(this);
						}
					});
				}
			}
		}
	}, this));
	Slideshow.prototype.init.apply(this, [type, itemNode, duration, interval, autoPlay, useFilter]);

	if (this.imageItems.length > 1) {
		if (this.prevButton && this.scrollIndex > 0) {
			$(this.container).prepend(this.prevButton);
		}
		if (this.nextButton && this.scrollIndex < this.items.length - 1) {
			$(this.container).append(this.nextButton);
		}
	}
}
SlideshowController.prototype.scrollToIndex = function (index, dispatch) {
	this.scrollIndex = Math.max(0, Math.min(index, this.items.length - this.shownItem));
	var startX = this.scrollLeft;
	var endX   = 0;
	for (var i = 0, n = this.scrollIndex; i < n; i++) {
		endX += this.getItem(i).width;
	}
	this.scrollAnimation(startX, endX, dispatch);
}
SlideshowController.prototype.dispose = function () {
	if (this.slideshow) {
		this.slideshow.dispose();
		this.slideshow = null;
	}

	if (this.prevButton) {
		$(this.prevButton)
			.unbind("click.slideshow")
			.unbind("mouseenter.slideshow")
			.unbind("mouseleave.slideshow");
		this.prevButton = null;
	}

	if (this.nextButton) {
		$(this.nextButton)
			.unbind("click.slideshow")
			.unbind("mouseenter.slideshow")
			.unbind("mouseleave.slideshow");
		this.nextButton = null;
	}

	if (this.items) {
		var items = this.items;
		for (var i = 0, n = items.length; i < n; i++) {
			$(items[i].node)
				.unbind("mouseenter.slideshow")
				.unbind("mouseleave.slideshow");
			$("a", items[i].node).unbind("click.slideshow");
		}
	}

	Slideshow.prototype.dispose.apply(this, []);
}
SlideshowController.prototype.append = function (item) {
	Slideshow.prototype.append.apply(this, arguments);

	$("a", item.node).bind("click.slideshow", createDelegate(function () {
		if (!this.controller.animateTimer) {
			this.controller.select(this.index);
		}
		return false;
	}, { controller : this, index : this.items.length - 1 }));

	if ($("img", item.node).length) {
		$("img", item.node).each(function(index, node){
			var img = $(node);
			var src = img.attr("src");
			if ($.browser.msie && $.browser.version < 8 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
				src = node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src;
			}
			img.data("normalSrc", src);
			img.data("hoverSrc",  preload(src.replace(/\.png$/, "_o.png")).src);
			img.data("staySrc",   preload(src.replace(/\.png$/, "_s.png")).src);
		});

		$(item.node)
			.bind("mouseenter.slideshow", createDelegate(function (e) {
				if ($(this.item.node).data("status") != "stay") {
					$("img", this.item.node).each(function(index, node){
						var img = $(node);
						if ($.browser.msie && $.browser.version < 8 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
							node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("hoverSrc");
						} else {
							img.attr("src", img.data("hoverSrc"));
						}
					});
				}
			}, { controller : this, item : item }))
			.bind("mouseleave.slideshow", createDelegate(function (e) {
				if ($(this.item.node).data("status") != "stay") {
					$("img", this.item.node).each(function(index, node){
						var img = $(node);
						if ($.browser.msie && $.browser.version < 8 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
							node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("normalSrc");
						} else {
							img.attr("src", img.data("normalSrc"));
						}
					});
				}
			}, { controller : this, item : item }));

		item.addEventListener("change", createDelegate(function(){
			if (this.isActive) {
				$(this.node).data("status", "stay");
				$("img", this.node).each(function(index, node){
					var img = $(node);
					if ($.browser.msie && $.browser.version < 8 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
						node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("staySrc");
					} else {
						img.attr("src", img.data("staySrc"));
					}
				});
			} else {
				$(this.node).data("status", "normal");
				$("img", this.node).each(function(index, node){
					var img = $(node);
					if ($.browser.msie && $.browser.version < 8 && node.filters && node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader")) {
						node.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img.data("normalSrc");
					} else {
						img.attr("src", img.data("normalSrc"));
					}
				});
			}
		}, item));
	}
}
