// JavaScript Document

var LunaProducts = {

	start: function() {
		if ($('splashIntro')) {
			LunaProducts.initIntroAnimation();
		}
		/*if ($('xpnd')) {
			LunaProducts.initProdMenu();
		}*/
		if ($('pdtmn')) {
			LunaProducts.initFadingProdMenu();
		}
	},

	initIntroAnimation: function() {
		//var goy = $('goy');
		var cloud = $('cloud');
		var moon = $('moon');
		var sun = $('sun');
		var lf = $('lunafaerie');
		var ltxt = $('ls-title');
		var rdfl = $('redflr');
		var prfl = $('purpleflr');
		var orfl = $('orangeflr');
		var lchr = $('char');
		var splt = $('splotz');
		/*goyin = new Fx.Styles(goy, {'duration': 1500,
									'wait': true,
									'transition': Fx.Transitions.sineInOut,
									'onComplete': function() {
										setTimeout("goyout.start({'opacity': [1, 0]})", 100);
										}
									});
		goyout = new Fx.Styles(goy, {'duration': 1000,
									'wait': true,
									'transition': Fx.Transitions.sineInOut,
									'onComplete': function() {
										setTimeout("lcin.start({'opacity': [0, 1]})", 50);
										}
									});*/
		mnin =  new Fx.Styles(moon, {'duration': 1400,
										'wait': true,
										'transition': Fx.Transitions.elasticOut,
										'onComplete': function() {
											txtin.start({'opacity': [0, 1]});
										}});
		snin =  new Fx.Styles(sun, {'duration': 1500,
										'wait': true,
										'transition': Fx.Transitions.elasticOut,
										'onComplete': function() {
											cloudout.start({'top': [-50]});
										}});
		cloudout = new Fx.Styles(cloud, {'duration': 800,
										'wait': true,
										'transition': Fx.Transitions.linear
										});
		txtin =  new Fx.Styles(ltxt, {'duration': 800,
										'wait': true,
										'transition': Fx.Transitions.sineInOut,
										'onComplete': function() {
											//cloud.setStyle('display', 'none');
											lfin.start({'opacity': [0, 1]});}});
		lfin = new Fx.Styles(lf, {'duration': 300,
										'wait': true,
										'transition': Fx.Transitions.quadOut,
										'onComplete': function() {
											rdflin.start({'opacity': [0, 1]});
											setTimeout("prflin.start({'opacity': [0, 1]})", 125);
											setTimeout("orflin.start({'opacity': [0, 1]})", 275);
										}});
		rdflin = new Fx.Styles(rdfl, {'duration': 400,
										'wait': true,
										'transition': Fx.Transitions.sineInOut
										});
		prflin = new Fx.Styles(prfl, {'duration': 400,
										'wait': true,
										'transition': Fx.Transitions.sineInOut
										});
		orflin = new Fx.Styles(orfl, {'duration': 400,
										'wait': true,
										'transition': Fx.Transitions.sineInOut,
										'onComplete': function() {
											lchrin.start({'opacity': [0, 1]});
											spltin.start({'opacity': [0, 1]});
											}});
		lchrin = new Fx.Styles(lchr, {'duration': 1100,
										'wait': true,
										'transition': Fx.Transitions.sineInOut,
										'onComplete': function() {
											
										}
										});
		spltin = new Fx.Styles(splt, {'duration': 1100,
										'wait': true,
										'transition': Fx.Transitions.sineInOut,
										'onComplete': function() {
											
										}
										});

		$$('.invis').each(function(invis) {
			invis.setOpacity(0);
		});
		$$('.nosee').each(function(nosee) {
			nosee.setStyle('top', '-150px');
		});
		mnin.start({'top': [166]});
		setTimeout("snin.start({'top': [105]});", 150);
	},

	initProdMenu: function() {
		var lunas = $$('.luna-item');
		var fx = new Fx.Elements(lunas, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		lunas.each(function(litm, i) {
			litm.addEvent('mouseover', function(e) {
				e = new Event(e).stop();
				var obj = {};
				obj[i] = {
					'width': [litm.getStyle('width').toInt(), 220]
				};
				lunas.each(function(other, j) {
					if (other != litm) {
						var otherWidth = other.getStyle('width').toInt();
						if (otherWidth != 85) {
							obj[j] = {
								'width': [otherWidth, 85]
							}
						}
					}
				});
				fx.start(obj);
			});
		});

		document.addEvent('mouseover', function(e) {
			e = new Event(e);
			rel = e.relatedTarget;
			if (!rel) {
				return;
			}
			if (rel.hasClass && (rel.hasClass('luna-item') || rel.hasClass('lunamenu') || rel.hasClass('lunaxpnd'))) {
				var obj = {};
				lunas.each(function(other, j) {
					obj[j] = {
						'width': [other.getStyle('width').toInt(), 107]
					}
				});
				fx.start(obj);
			}
		});

	},

	initFadingProdMenu: function() {
		var lunas = $$('.fader');
		var fx = new Fx.Elements(lunas, {wait: false, duration: 250, transition: Fx.Transitions.sineInOut});
		lunas.each( function(fdr) {
			fdr.setOpacity(.001);
		});
		lunas.each(function(litm, i) {
			litm.addEvent('mouseover', function(e) {
				e = new Event(e).stop();
				var obj = {};
				obj[i] = {
					'opacity': [litm.getStyle('opacity'), 1]
				};
				lunas.each(function(other, j) {
					if (other != litm) {
						var otherOpac = other.getStyle('opacity');
						if (otherOpac != .001) {
							obj[j] = {
								'opacity': [otherOpac, .001]
							}
						}
					}
				});
				fx.start(obj);
			});
		});

		document.addEvent('mouseover', function(e) {
			e = new Event(e);
			rel = e.relatedTarget;
			if (!rel) {
				return;
			}
			if (rel.hasClass && (rel.hasClass('fader') || rel.hasClass('faderlnk') || rel.hasClass('menubloc'))) {
				var obj = {};
				lunas.each(function(other, j) {
					obj[j] = {
						'opacity': [other.getStyle('opacity'), .001]
					}
				});
				fx.start(obj);
			}
		});

	}



};

window.addEvent('domready', LunaProducts.start);