window.addEvent("domready", function() {

	$("wrapper").fade("hide").set("tween", { duration: 400 }).fade("in");
	$$("ul#stalkalicous a").fade("hide");
	(function() {
		$$("ul#stalkalicous a").each(function(el, i) {
			(function() {
				el.set("morph", {
					duration: 1000,
					transition: "bounce:out"
				}).morph({
					top: 0
				});
				el.set("tween", { duration: 800 }).fade("in");
			}).delay(100 * i);
			// var releaseFx = new Fx.Morph(el, {
			// 	duration: 800,
			// 	transition: "elastic:out"
			// });
			// new Drag(el, {
			// 	onComplete: function() {
			// 		releaseFx.start({
			// 			top: 0,
			// 			left: 0
			// 		});
			// 	}
			// });
		});

		$$("ul#stalkalicous a").each(function(el) {
			// var siblings = el.getParent().getChildren().erase(el);
			el.addEvents({
				mouseenter: function() {
					// siblings.set("tween", { duration: 300 }).tween("opacity", 0.3);
					var linktext = this.get("text");
					var tooltip = new Element("div", {
						"class": "tooltip",
						html: '<div class="tooltipInner">' + linktext + '</div>'
					}).inject(this, "after");
				},
				mouseleave: function() {
					// siblings.set("tween", { duration: 300 }).tween("opacity", 1);
					$$("div.tooltip").dispose();
				}
			});
		});
	}).delay(600);
	// $$("ul#stalkalicous a").addEvent("click", function(e) {
	// 	e.stop();
	// });

	var clicked = false;
	// $$("li#showWork").addEvents({
	// 	mouseenter: function() {
	// 		this.set("morph", {
	// 			duration: 400,
	// 			transition: "quint:out"
	// 		}).morph({
	// 			paddingLeft: 10,
	// 			backgroundPosition: "0px 7px"
	// 		});
	// 	},
	// 	mouseleave: function() {
	// 		if (!clicked) {
	// 			this.set("morph", {
	// 				duration: 400,
	// 				transition: "quint:out"
	// 			}).morph({
	// 				paddingLeft: 0,
	// 				backgroundPosition: "-10px 7px"
	// 			});
	// 		}
	// 	}
	// });

	$("portfolio").fade("hide");
	$$("li#showWork a").addEvents({
		click: function(e) {
			$("content").set("morph", {
				duration: 500,
				transition: "back:out"
			}).morph({
				marginLeft: 300
			});
			(function() {
				$("portfolio").set("morph", {
					duration: 1000,
					transition: "expo:out"
				}).morph({
					top: 150,
					opacity: 1
				});
			}).delay(500);
			this.getParent().addClass("active");
			clicked = true;
			e.stop();
		}
	});
	
	var pfListWidth = $$("div#portfolio img").length * 280;
	$("pfList").setStyle("width", pfListWidth);
	// $$("div#portfolio img").each(function(el, i) {
	// 	el.addEvent("click", function() {
	// 		var multiplier = i + 1;
	// 		$("pfList").set("morph", {
	// 			duration: 500,
	// 			transition: "cubic:out"
	// 		}).morph({
	// 			left: 280 * multiplier * -1
	// 		});
	// 	});
	// });
	var counter = 0;
	$("prev").addClass("inactive");
	var scrnshots = $$("div#portfolio img");
	$("next").addEvent("click", function(e) {
		$("prev").removeClass("inactive");
		if (counter < scrnshots.length - 1) {
			counter++;
			$("pfList").morph({
				left: 280 * counter * -1
			});
		}
		if (counter == scrnshots.length - 1) { this.addClass("inactive"); }
		e.stop();
	});
	$("prev").addEvent("click", function(e) {
		$("next").removeClass("inactive");
		if (counter > 0) {
			counter--;
			$("pfList").morph({
				left: 280 * counter * -1
			});
		}
		if (counter == 0) { this.addClass("inactive"); }
		e.stop();
	});

});
