ImagesFade = new Class({
	"images" : [],
	"initialize" : function (images_list, interval) {
		this.images = $$(images_list);
		this.interval = interval || 2000;

		this.max = (this.images.length - 1);
		this.idx = this.max;

		this.images.each(function (el, idx) { //opacity di dafault
			if (idx != this.idx) {el.fade("out");}
		}, this);

		if (this.images[1]){
			this.shiftFadeLong.periodical(this.interval, this);
		}

	},

	"shiftFadeLong" : function () {
		(new Fx.Tween(this.images[this.idx], {
			"property" : "opacity",
			"duration" : "long",
			"onComplete" : this.nextFadeIn.bind(this)
		})).start(0);
	},

	"nextIdx" : function () {
		this.idx--;
		this.idx = (this.idx < 0) ? this.max : this.idx;
	},

	"nextFadeIn" : function () {
		this.nextIdx();
		this.images[this.idx].setStyle("display", "block");
		this.images[this.idx].fade("in");
	},

	"shiftFadeBase" : function () {
		this.images[this.idx].fade("out");
		this.nextFadeIn();
	}
});


showSplashColl = function (imgSrc) {
	if (imgSrc) {
		var img = $("collectionSplash");
		img.fade("out");
		img.src = imgSrc;
		img.fade("in");
	}
};

showSplashColl.out = function () {
	$("collectionSplash").fade("out");
};


var subCollAnimInit = function () {
	$$("ul.collMenu li.subColl").each(function (el) {
		var ul_subcoll = el.getElement("ul.subColl"),
			h = ul_subcoll.getCoordinates()["height"],
			b = el.getCoordinates()["height"];
				
		el.addEvents({
			"mouseenter" : function (ev) {
				ev.stop();
				this.tween("height", h + b + 4);
			},
			"mouseleave" : function (ev) {
				ev.stop();
				this.tween("height", b);
			}
		});
	});
};


var splashAnimInit = function () {
	$$("ul.collMenu [splash_src]").each(function (el) {
		var imgSrc = el.getAttribute("splash_src");

		if (imgSrc) {
			el.addEvents({
				"mouseenter" : function (ev) {
					// ev.stop();
					showSplashColl(imgSrc);
				},
				"mouseleave" : function (ev) {
					// ev.stop();
					showSplashColl.out();
				}
			
			});
		}
	});
};

window.addEvent("domready", function () {
//	alert(document.body.getStyle("width"))

	$("collMenu").set("tween", {
		"onComplete" : function () {
			this.element.setStyle("display", "block");
			subCollAnimInit();
		}
	}).fade("out");

// 	$("collectionSplash").set("tween", {
// 		"onComplete" : function () {
// 			this.element.setStyle("display", "block");
// 			splashAnimInit();
// 		}
// 	}).fade("out");

// 	img_splash_list = $$("ul.collMenu [splash_src]").get("splash_src").filter(function (v) {return !!v});
// 
// 	Asset.images(img_splash_list, {
// 		"onComplete" : function () {
// 			new ImagesFade("div.bodyWrapper img.splash", 4000);	
// 		}
// 	});

	new ImagesFade("div.bodyWrapper img.splash", 4000);	

});

function MenuOnOff() {
	$("collMenu").fade("toggle");
}

/*
showSplashColl = function (imgSrc) {
	if (imgSrc) {
		var img = $("collectionSplash");
		(new Fx.Tween(img, {
			"property" : "opacity",
			"onComplete" : function () {
				img.src = imgSrc;
				img.onload = function () {
					(new Fx.Tween(img, {
						"property" : "opacity",
						"duration" : "long"
					})).start(1);
				};
			}
		})).start(0);
		

	}
};

showSplashColl.out = function () {
	$("collectionSplash").fade("out");

};

*/
