Cufon.replace('h1, h2, #splash p, a, label, #email_text p, #fake_button', {hover: true});

$(document).ready(function() {
	$("#products, .wineoverlay").append("<div id=\"submenu_cds\" class=\"overlay_sub\" style=\"left: 0;\"><a href=\"#\" rel=\"#cds_0\">Château de Seguin</a></div><div id=\"submenu_vbt\" class=\"overlay_sub\" style=\"right: 0;\"><a href=\"#\" rel=\"#vbt_0\">Villa Bona Terra</a></div>");
	
	var winH = document.documentElement.clientHeight;
	(winH<681) ? $("#container").css("height","681px") : $("#container").css("height",winH+"px");
	//($("#container").width()<960) ? $("#container").css("width","960px") : $("#container").css("width","100%");
	w=$("#container").width();

	$("a:not(.submenu, #level2 a)").click(function() {
		hideLevel2();
		$("a").removeClass("selected");
		$(this).addClass("selected");
	});
	
	/* Generate Prev and Next links in overlays */
	$(".overlay").each(function() {
		var shownext = ($(this).attr("id"));
		if (shownext.lastIndexOf('_') >= 0) {
			var thisPagenr = parseInt(shownext.charAt(shownext.lastIndexOf('_')+1));
			var nextId = "#"+shownext.substring(0,shownext.lastIndexOf('_')+1)+String(thisPagenr+1);
			var prevId = "#"+shownext.substring(0,shownext.lastIndexOf('_')+1)+String(thisPagenr-1);

			if ($(nextId).length) {
				var nextLink = "<a rel='"+nextId+"' href='' class='nextlink'><img src='images/nextpage.png' alt='Next Page' /></a>";
				$(this).append(nextLink);
				}
			if ($(prevId).length) {
				var prevLink = "<a rel='"+prevId+"' href='' class='prevlink'><img src='images/prevpage.png' alt='Prev page' /></a>";
				$(this).prepend(prevLink);
			}
		}

	});

	/* Initialize overlay */
	$('#slides').cycle({
		speed:   1000
	});
	
	/* Initialize overlay */
	$("a[rel]").overlay({
		absolute: true,
		top: "10px",
		left: (w/2)-480 + "px",
		closeOnClick: true
	});
	

	/* Menu Slide up/down */
	$("#menu").hover(
		function() {menu_slideUp();}, function() {menu_slideDown();}
	);
	
	//Send form
	$("#fake_button").click(function() {
		$.post("send_email.php", $("#email").serialize());
		$("#email_text").append("<br /><br /><p style='border: 1px solid gray; padding: 10px; margin-right: 20px;'>We have received your information.<br />Thank you!</p>");
	});
	
});

function toggle_splash() {
	if ($("#menu").is(":hidden")) {
		$("#menu").bind('mouseenter mouseleave', function() {
			$(this).hover(
				function() {menu_slideUp();}, function() {menu_slideDown();}
			);	
		});
		$("#splash").fadeOut();
		$("#menu").fadeIn("slow");
		} else {
			$("#menu").unbind('mouseenter mouseleave').hide();
			$(".overlay").fadeOut();
			$("#splash").fadeIn();		
		}
}

function showLevel2() {
$("#level2").fadeIn();
}

function hideLevel2() {
$("#level2").fadeOut();
}


function menu_slideUp() {
	$("#menu").stop().animate({
	height: "140px"
	}, 500);
}

function menu_slideDown() {
	$("#menu").stop().animate({
	height: "80px"
	}, 500);
}
