var AnimatedMenu = Class.create({
	initialize: function(name, channel, pos)
	{
		this.name = name;
		this.channel = channel;
		this.pos = pos;

		for (var i = 0; i < this.pos.length; i++)
		{
			if (this.pos[i].channel != this.channel)
			{
				$(this.pos[i].name).observe("mouseover", this.over.bindAsEventListener(this, i));
				$(this.pos[i].name).observe("mouseout", this.out.bindAsEventListener(this, i));
			}
		}
	},

	over: function(e, i)
	{
		var obj = $(this.pos[i].name);

		Effect.Queues.get("animatedmenu-" + this.name + "-" + this.pos[i].name).invoke("cancel");

		obj.setStyle({backgroundPosition: this.pos[i].from[0] + "px " + this.pos[i].from[1] + "px"});
		new Effect.Morph(obj, {
			style: "background-position: " + this.pos[i].to[0] + "px " + this.pos[i].to[1] + "px",
			duration: .4,
			queue: {
				position: "end",
				scope: "animatedmenu-" + this.name + "-" + this.pos[i].name,
				limit: 1
			}
		});
	},

	out: function(e, i)
	{
		var obj = $(this.pos[i].name);

		Effect.Queues.get("animatedmenu-" + this.name + "-" + this.pos[i].name).invoke("cancel");

		obj.setStyle({backgroundPosition: this.pos[i].to[0] + "px " + this.pos[i].to[1] + "px"});
		new Effect.Morph(obj, {
			style: "background-position: " + this.pos[i].from[0] + "px " + this.pos[i].from[1] + "px",
			duration: .2,
			queue: {
				position: "end",
				scope: "animatedmenu-" + this.name + "-" + this.pos[i].name,
				limit: 1
			}
		});
	}
});

var StyledButton = Class.create({
	initialize: function(id, formID)
	{
		this.formID = formID;
		
		if ($(id + "_alternative"))
		{
			$(id + "_alternative").hide();
		}
		
		if ($(id))
		{
			$(id).show();
			
			$(id).observe("click", this.submit.bindAsEventListener(this));
		}
	},
	
	submit: function(e)
	{
		$(this.formID).submit();
	}
});

document.observe("dom:loaded", function()
{
	var menuPositions = [
	 	{
	 		name:		"menu_home_link",
	 		channel:	"home",
	 		from:		[0, 0],
	 		to: 		[-220, 0]
	 	},
	 	{
	 		name: 		"menu_menu_link",
	 		channel: 	"menu",
	 		from: 		[0, -40],
	 		to: 		[-220, -40]
	 	},
	 	{
	 		name: 		"menu_takeout_link",
	 		channel: 	"takeout",
	 		from: 		[0, -80],
	 		to:			[-220, -80]
	 	},
	 	{
	 		name: 		"menu_reservations_link",
	 		channel: 	"reservations",
	 		from: 		[0, -120],
	 		to:			[-220, -120]
	 	},
	 	{
	 		name: 		"menu_photos_link",
	 		channel: 	"photos",
	 		from: 		[0, -160],
	 		to:			[-220, -160]
	 	},
	 	{
	 		name: 		"menu_catering_link",
	 		channel: 	"catering",
	 		from: 		[0, -200],
	 		to:			[-220, -200]
	 	},
	 	{
	 		name: 		"menu_about_link",
	 		channel: 	"about",
	 		from: 		[0, -240],
	 		to:			[-220, -240]
	 	},
	 	{
	 		name: 		"menu_contact_link",
	 		channel: 	"contact",
	 		from: 		[0, -280],
	 		to:			[-220, -280]
	 	}
	];
	
	//new AnimatedMenu("main", DT.channel, menuPositions);	
});

$j(function()
{
	$j.get("/process/newsletter/get_latest", function(data)
	{
		if (data.url != undefined)
		{
			$j(".latest-newsletter-link a").attr("href", data.url);
			$j(".latest-newsletter-link").show();
		}
	}, "json");
});
