$(function () {
	$("#searchform").submit(function () {
		var searchTerm = $("#searchTerm").val();
		if (searchTerm == "login") {
			$.get("/Control?master=Ajax", null, function (data) {
				var content = $("<div>" + data + "</div>");
				var title = content.find("h2").html();
				content.find("h2").remove();
				$(content).dialog({
					modal: true,
					title: title,
					resizable: false,
					close: function () {
						$(this).remove();
					}
				});

			}, "html");
			return false;
		}
	});
	$(".productthumbnail > a").click(function () {
		$.get(this.href + "?master=Ajax", null, function (data) {
			var content = $("<div id=\"DialogueHolder\" class=\"Products-Product\">" + data + "</div>");
			var productName = content.find("h2").html();
			content.find("h2").remove();
			content.find(".Slideshow").innerFade({
				speed: 750,
				type: "sequence",
				containerHeight: 316,
				timeout: 4000,
				pauseLink: ".Slideshow img"
			});
			$(content).dialog({
				modal: true,
				title: productName,
				width: 706,
				height: 425,
				resizable: false,
				close: function () {
					$(this).remove();
				}
			});
		});
		return false;
	});
	$("a.NewWindow").click(function () {
		window.open(this.href);
		return false;
	});
	$("#ProductImages .Slideshow").innerFade({
		speed: 750,
		type: "sequence",
		containerHeight: 316,
		timeout: 4000,
		pauseLink: ".Slideshow img"
	});
	$("#PageImage .Slideshow").innerFade({
		speed: 750,
		type: "sequence",
		containerHeight: 400,
		timeout: 4000,
		pauseLink: ".Slideshow img"
	});
	function setUpDialogueForm() {
		$("#DialogueHolder form").submit(function () {
			$.post(this.action, $(this).serialize(), function (data) {
				$("#ProductDetails").html(data);
				setUpDialogueForm();
			});
			return false;
		});
	}
	$("#DialogueHolder #ProductActions a").live("click", function () {
		var url = this.href + "?master=Ajax";
		$("#ProductDetails").load(url, setUpDialogueForm);
		return false;
	});

});
