// Preload images
for (n = 1; n <= 12; n++)
{			
	imageNo = n;
	
	Image1 = new Image(10, 10);
	Image1.src = "images/" + imageNo + ".jpg";
}

function submenuSlideIn(newWidth, submenuToShow)
{			
	// Hide all other submenu's than the specified one
	$(".submenuinnercontainer").not(".submenuinnercontainer" + submenuToShow).hide();

	// Start the new animation
	$("#submenucontainer").animate( { width: newWidth }, "fast" );
	
	// Fade-in the specified submenu
	$(".submenuinnercontainer" + submenuToShow).fadeIn(500);
	$(".submenuinnercontainer" + submenuToShow).dequeue();
	
	// And register the "hide" events
	$("#menumousoutregionleft").mouseover(function() { hideSubmenu(); } );
	$("#menumousoutregionbottom").mouseover(function() { hideSubmenu(); } );
}

function hideSubmenu()
{
	$(".submenuinnercontainer").hide();
	$("#submenucontainer").animate( { width: 0 }, "fast", '', function()
	{
		$("#menumousoutregionleft").unbind("mouseover");
		$("#menumousoutregionbottom").unbind("mouseover");
	});
}

function switchBackground()
{		
	var newBackgroundNo = Math.ceil(Math.random() * 12);
	loadBackground(newBackgroundNo);
}

function switchImage(identifier, newImage)
{
		$(identifier).prepend('<img>')
		.find(':first-child')
		.attr('src', newImage)
		.css( {
			'left' : 0,
			'top' : 0,
			'z-index': 0
			} )
		.next()
		.stop()
		.animate( {	opacity: 0 }, 500, function() {
			$(identifier)
			.find(':first-child')
			.next()
			.remove();
		} );
}

function loadBackground(backgroundNo)
{
	var newImageFoto = "usrimages/tekstachtergrond_" + backgroundNo + ".jpg";

	// Crossfade background
	switchImage("#fotocontainer", newImageFoto);
	
	//setTimeout("switchBackground()", 10000);
}

// Called after click on a menu item
function MenuItemClick(categoryId)
{
	hideSubmenu();
	showText(categoryId);
}	

function showText(key)
{
	contentAreaFadeOut(key);
}

function contentAreaFadeOut(key)
{
	var artikelid = key;

	$("div.innercontent").fadeOut("normal", function()
	{
		$.ajax(
		{
			type: "POST",
			url: "getdocumenttext.php",
			dataType: "html",
			data: "key=" + artikelid,
			success: function(msg)
			{
				$("div.innercontent")[0].innerHTML = msg;
				contentAreaFadeIn(artikelid);

				// Google Analytics
				registerHit('<?=$oSelectedArtikel->artikeltitel?>');
			}
		});
	});
}

function contentAreaFadeIn(artikelid)
{
	$("div.innercontent").fadeIn("normal");
	loadBackground(artikelid);
}

function processContactForm(key)
{
	var inputs = $("input").serialize();
	var textareas = $("textarea").serialize();
	var combined = inputs + '&' + textareas;
	
	var artikelid = key;
	
	$("div.innercontent").fadeOut("normal", function()
	{	
		$.ajax({
			type: "POST",
			url: "contact.frm.php",
			data: combined,
			success: function(msg) {
				$("div.innercontent")[0].innerHTML = msg;
				contentAreaFadeIn(artikelid);			
			}
		});
	});
}

function unsubscribe(key)
{
	var inputs = $("input[name = 'Emailadres']").serialize();	
	var combined = inputs + '&unsubscribe=1&formSent=1';	
	var artikelid = key;
	
	$("div.innercontent").fadeOut("normal", function()
	{	
		$.ajax({
			type: "POST",
			url: "contact.frm.php",
			data: combined,
			success: function(msg) {
				$("div.innercontent")[0].innerHTML = msg;
				contentAreaFadeIn(artikelid);
			}
		});
	});
}
