// THe next line enables jQuery IntelliSense in Visual Studio:
/// <reference path="/common/js/IntelliSense/jquery-1.3.1-vsdoc.js" />

$(document).ready(function() {

    Cufon.replace('h1, .flash'); // Requires a selector engine for IE 6-7, see above
    Cufon.now();
	// jQuery Flash Plugin - Flash Text-Replacement (sIFR)
	// http://jquery.lukelutman.com/plugins/flash/example-text-replacement.html

//	$('h1').flash({ src: '/flash/jfr-vinovia.1.1.swf',
//		wmode: 'transparent', // to prevent it from overlaying a modal window like Thickbox
//		flashvars: {
//			css: [
//								'* { color: #cc0000; padding: 0; margin: 0  }'
//							].join(' ')
//		}
//	},
//					{ version: 7 },
//					function(htmlOptions) {
//						htmlOptions.flashvars.txt = this.innerHTML;
//						this.innerHTML = '<div>' + this.innerHTML + '</div>';
//						var $alt = $(this.firstChild);
//						htmlOptions.height = $alt.height();
//						htmlOptions.width = $alt.width();
//						$alt.addClass('alt');
//						$(this)
//							.addClass('flash-replaced')
//							.prepend($.fn.flash.transform(htmlOptions));
//					}
//				);

//	$("form#zoeken").validate({ // Because the 'zoeken' form is on the same page with other forms it needs to have its validation set separately
//		errorClass: "validationerror",
//		errorElement: "div"
//	});

	$("p.login > a").click(function(event) {
		$("#login-form").toggle("slow");
		return false;
	});

	$("input.amount").keydown(function(event) {
		switch (event.keyCode) {
			case 38:
				AddAmount(this.id.replace('aantal_', '')); break;
			case 40:
				SubtractAmount(this.id.replace('aantal_', '')); break;
		}
	});

	$("img.add_amount").click(function() {
		AddAmount(this.id.replace('add_', ''));
	});

	$("img.subtract_amount").click(function() {
		SubtractAmount(this.id.replace('subtract_', ''));
	});

	//	$("a.toggle_wijn_edit_form").click(function(event) {
	//		$("#wijn_edit_form").show("slow");
	//		$(this).hide("slow");
	//	});

	//	$("a.toggle_edit-wijn-foto").click(function(event) {
	//		$("#edit-wijn-foto").show("slow");
	//		$(this).hide("slow");
	//	});

	$("button.removeall").click(function() {
		if (confirm('Weet u zeker dat uw winkelwagen helemaal wilt leegmaken?')) {
			$("input.amount").attr("value", "0");
			// Remove other buttons because IE6 passes ALL <button type="submit"> elements back to the server on submit instead of just the clicked one.
			$("button#herberekenen").remove();
			$("button#naardekassa").remove();
			return true;
		} else {
			return false;
		}
	});

	$("button#herberekenen").click(function() {
		// Remove other buttons because IE6 passes ALL <button type="submit"> elements back to the server on submit instead of just the clicked one.
		$("button#leegmaken").remove();
		$("button#naardekassa").remove();
	});

	$("button.remove").click(function() {
		aantal_id = this.id.replace('remove_', '');
		$("input#aantal_" + aantal_id).attr("value", 0);
	});

	function AddAmount(aantal_id) {
		if ($("input#aantal_" + aantal_id).attr("disabled") != true) {
			var value = $("input#aantal_" + aantal_id).attr("value") * 1;
			if (value + 1 > 0) {
				$("input#aantal_" + aantal_id).attr("value", value + 1);
			} else {
				$("input#aantal_" + aantal_id).attr("value", "1");
			}
			$("input#aantal_" + aantal_id).focus()
		}
	}

	function SubtractAmount(aantal_id) {
		var value = $("input#aantal_" + aantal_id).attr("value") * 1;
		if (value - 1 > 0) {
			$("input#aantal_" + aantal_id).attr("value", value - 1);
		} else {
			$("input#aantal_" + aantal_id).attr("value", "0");
		}
		$("input#aantal_" + aantal_id).focus()
	}
});

function toonAlleSoorten() {
	$(".soorten").toggle();
	$(".soorten.hidden").removeClass("hidden");
}

function toonAlleLanden() {
	$(".landen").toggle();
	$(".landen.hidden").removeClass("hidden");
}

function toonAlleStreken() {
	$(".streken").toggle();
	$(".streken.hidden").removeClass("hidden");
}

function toonAlleDruiven() {
	$(".druiven").toggle();
	$(".druiven.hidden").removeClass("hidden");
}

function addOptionToListBox(name, value, label, selected) {
	var selectedAttribute;
	if (selected) selectedAttribute = "selected=\"selected\""
	$("select[name='" + name + "']").append("<option value=\"" + value + "\" " + selectedAttribute + ">" + label + "</option>")
}
