
	function test ()
	{
	    var requestUrl = 'ajax/test';
	    var keyword = $F('keyword');
	    try
	    {
	        var request = new Ajax.Request(
	            requestUrl,
	            {
	                method: 'get',
	                parameters: 'keyword=' + encodeURIComponent(keyword),
	                onComplete: handleTest
	            }
	        );
	    }
	    catch (e)
	    {
	        alert('Error: ' + e.toString());
	    }
	}
	
	
	
	function handleTest (reply)
	{
	    $('keyword').value = '';
	    var items = eval('(' + reply.responseText + ')');

	    var itemCount = items.length;
	    $('itemResults').innerHTML = "";
	    for (var i=0; i<itemCount; i++) {
	    	$('itemResults').innerHTML = $('itemResults').innerHTML + '<p>' + items[i].author + '</p>';
	    }
	}
	
	
	/*
	 *	Ajax: Add product amount to cart
	 */
	function ajaxAddProductAmount(sProductIdElem, sAmountElem)
	{
		nProductId = $(sProductIdElem).value;
		nAmount = $(sAmountElem).value;
		
		if(nAmount <= 0)
			return;
			
		showLoadingMessage('shopCart');
	    try
	    {
	        var request = new Ajax.Request(
	            '/ajax/shopAddAmount',
	            {
	                method: 'get',
	                parameters: $H({ productId:nProductId, amount:nAmount }), 
	                onComplete: updateShopCart
	            }
	        );
	    }
	    catch (e)
	    {
	        alert('Error: ' + e.toString());
	    }
	}	



	/*
	 *	Ajax: Set product amount to cart
	 */
	function ajaxSetProductAmount(sProductIdElem, sAmountElem)
	{
		nProductId = $(sProductIdElem).value;
		nAmount = $(sAmountElem).value;
		
		showLoadingMessage('shopCart');
	    try
	    {
	        var request = new Ajax.Request(
	            '/ajax/shopSetAmount',
	            {
	                method: 'get',
	                parameters: $H({ productId:nProductId, amount:nAmount }), 
	                onComplete: updateShopCart
	            }
	        );
	    }
	    catch (e)
	    {
	        alert('Error: ' + e.toString());
	    }
	}	
	
	
	
	/*
	 *	Ajax: Refresh content of shopping cart div.
	 */
	function updateShopCart ()
	{
		showLoadingMessage('shopCart');

	    var requestUrl = '/ajax/shopCartHtml';
	    try
	    {
	        var request = new Ajax.Request(
	            requestUrl,
	            {
	                method: 'get',
	                onComplete: handleUpdateShopCart
	            }
	        );
	    }
	    catch (e)
	    {
	        alert('Error: ' + e.toString());
	    }
	}
	
	
	/*
	 *	AJAX callback to refresh content of shopping cart div.
	 */
	function handleUpdateShopCart (reply)
	{
	    $('shopCart').innerHTML = "";
	    
	    var responseData = eval('(' + reply.responseText + ')');
	    $('shopCart').innerHTML = responseData.html;
	}
	
	
	
	
	/*
	 *
	 */
	function showLoadingMessage(sElementId)
	{
	    $(sElementId).innerHTML = "<p><img src='/assets/images/loading.gif' alt=''/></p>";
	}	
	
	
	
	
	/*
	 * Swaps the class of the element with the given id between 'visible' and
	 * 'invisible'
	 */
	function toggleNewsItemLink(id) {
		element = document.getElementById(id);
		if(element != null) {
			if(element.className == "itemOpen") {
				element.className = "itemClosed";
				element.innerHTML = "more";
			}
			else {
				element.className = "itemOpen";
				element.innerHTML = "close";
			}
		}
	}
	



	function imageFadeInBeforeStartCallback(obj)
	{
		alert(obj.element.id);
		obj.element.className = 'invisible';
	}

	
	function imageFadeIn(elementId) 
	{
		new Effect.Opacity(
			elementId,
			{	duration: 1.5, 
				transition: Effect.Transitions.linear, 
				from: 0.0, 
				to: 1.0
			}
		);
	}
	
	function imageFadeOut(elementId) 
	{
		new Effect.Opacity(
			elementId,
			{ duration: 1.0, transition: Effect.Transitions.linear, from: 1.0, to: 0.0 }
		);
	}
	