var txt1 = 'Weet u zeker dat u de bestelling wilt plaatsen? Het totaal bedrag is \u20AC ';
var txt2 = 'Er ging iets mis bij het versturen.\nProbeert u het later opnieuw a.u.b.\n';

if (window.lang) {
	if (window.lang.txt_order_confirm_show_total) {
		txt1 = window.lang.txt_order_confirm_show_total;
	}
	if (window.lang.txt_order_send_error) {
		txt2 = window.lang.txt_order_send_error;
	}
}

$(function() {
	
	//$("div.menu").replaceWith($("#menu_placeholder").html());
	//$("#menu_placeholder").empty();

	$("div.menu > div.menu_box > ul > li > ul > li > ul").hide();
	$("div.menu > div.menu_box > ul > li").hover( function() {
		$(this).addClass("menu_hover");
	}, function() {
		$(this).removeClass("menu_hover");
	});
	$("div.menu > div.menu_box > ul > li > ul > li").hover( function() {
		$("ul", this).slideDown("fast");
	}, function() {
		$("ul", this).slideUp("fast");
	});
	
//	var total = $("#txt_order_total").val() || $("#total2").text();
//	if (!parseFloat(total)) {
//		$("#total").hide();
//		$("#btn_place_order").hide();		
//	}
	
	$("#btn_place_order").live("click", function() {
		var total = $("#txt_order_total").val() || $("#total2").text();
		if (confirm(txt1 + ' ' + total + '.')) {
			this.disabled = true;
			lang_code = lang_code ? lang_code : "nl";
			$.ajax({url: '/' + lang_code + '/order?action=place&' + $("textarea").serialize(), 
				success: function(data, status, xhr) {
					if (data && data.ok) {
						alert("Bestelling verzonden");
						location.reload();
					} else {
						if (data && data.redirect) {
							location.href = data.redirect;
						} else {
							alert(txt2);
						}
					}
					this.disabled = false;
				}, 
				error: function(xhr, status, erm) {
					alert(txt2);
					this.disabled = false;
				},
				dataType: "json"
			});	
		}
	});	
	
	var fotoWin = window.fotoWin = $('<img>'); 				
	fotoWin.css({ top: '0', left: '0', position: 'absolute', 'z-index': 1001, display: 'none', cursor: 'pointer' });
	fotoWin.appendTo('body');
	fotoWin.click(function(){
		fotoWin.hide();
		modal.hide();
	});
	fotoWin.load(function(){
		window.fotoWin.css("margin-top", ($(window).height() - window.fotoWin.height()) / 2);
		window.fotoWin.css("margin-left", ($(window).width() - window.fotoWin.width()) / 2);
		window.fotoWin.fadeIn();
	});
	
	var modal = window.modal = $('<div></div>');
	modal.appendTo('body');
	modal.css({ 'background-color': 'black', opacity: .7, width: '100%', height: '100%', top: 0, left: 0, position: 'fixed', 'z-index': 1000, display: 'none' });
	
});

function updateFoto(f, sel) {
	$(sel + " img").each(function() {
		this.src = f;
	})
	return false;
}

var w;

function popupPhoto (url) {
	window.modal.show();
	window.fotoWin.get(0).src = url;
//	window.fotoWin.css("margin-top", ($(window).height() - window.fotoWin.height()) / 2);
//	window.fotoWin.css("margin-left", ($(window).width() - window.fotoWin.width()) / 2);
//	window.fotoWin.fadeIn();	
	return false;
}



