// animates a series of div:s as slides, delay can be "slow", "normal", "fast" or a number
// type can be 0 for random animation type, 1 for sliding up-to-down, 2 sliding-down-up
function AnimateSlides(args, type, delay) {
	if (args.length < 2)
		return;

	// check for defaults
	switch (delay) {
		case "slow":
			delay = 10000;
			break;
		case "fast":
			delay = 2000;
			break;
		default:
			delay = 5000;
			break;
	}
	
	// chain items with the .nextanim attribute
	var x;
	for (x = 0; x < args.length; x++) {
		$(args[x]).data("nextanim", args[(x + 1) % args.length]);
	}

	// start chain of animation!
	var e = 'easeOutCubic';
	if ((!type) || (type == 0) || (type > 5)) {
		type = Math.floor(Math.random()*5+1);
		switch (Math.floor(Math.random()*2+1)) {
			case 1:
				e = 'easeOutCubic';
				break;
			case 2:
				e = 'easeOutBounce';
				break;
		}
	}
	var o3 = { duration: 1500, easing: e };
	setTimeout(AnimateSlidesWorker($(args[0]), 5, o3, delay), delay);
}
function AnimateSlidesWorker(o, type, options, delay) {
	return function() {
		var o1 = { duration: options.duration, easing: options.easing };
		var o2 = { duration: options.duration, easing: options.easing };
		var o3 = { duration: options.duration, easing: options.easing };
		var n = $(o.data("nextanim"));		
		if (type == 1) {
			// left
			n.css("left", o.outerWidth());
			n.show();
			o.animate({ left: -o.outerWidth() }, o1);
			n.animate({ left: 0 }, o2);
		} else if (type == 2) {
			// top
			n.css("top", -o.outerHeight());
			n.show();
			o.animate({ top: o.outerHeight() }, o1);
			n.animate({ top: 0 }, o2);
		} else if (type == 3) {
			// right
			n.css("left", -o.outerWidth());
			n.show();
			o.animate({ left: o.outerWidth() }, o1);
			n.animate({ left: 0 }, o2);
		} else if (type == 4) {
			// bottom
			n.css("top", o.outerHeight());
			n.show();
			o.animate({ top: -o.outerHeight() }, o1);
			n.animate({ top: 0 }, o2);
		} else if (type == 5) {
			// fade
			n.fadeIn();
			o.fadeOut();
		}
		setTimeout(AnimateSlidesWorker(n, type, o3, delay), delay);
	};
}

$(document).ready(function(event) {
	$("#nav1>li").hover(function() { 
		$(this).children("ul:first").css("visibility", "visible");
	}, function() {
		$(this).children("ul:first").css("visibility", "hidden");
	});
	AnimateSlides($(".header>.logo>div"));
});
