function slideshowIntervalHandler() {
	$("#previous").removeClass('focus');
	$("#next").addClass('focus');
	$('#articles').stop();

	var currentItem = $('#articlesPages li.selected');
	var newItem = currentItem.next('li');
	if (newItem.length == 0) {
		newItem = $('#articlesPages li:first');
	}

	currentItem.removeClass('selected');
	newItem.addClass('selected');

	var topValue = $("#articles").css('top');
	var value = parseInt(newItem.attr('rel'));

	$("#articles")
		.fadeTo(1000, 0)
		.animate({'top': value }, 0, function() { $("#next").removeClass('focus'); } )
		.fadeTo(1000, 1);
}
	
jQuery(function($){

	/*
		Slideshow
		Homepage
	*/

	$("#next").removeClass('disabled');
	$("#previous").removeClass('disabled');

	function nextRow(evt) {

		$("#previous").removeClass('focus');
		$("#next").addClass('focus');
		$('#articles').stop();

		evt.preventDefault();
		clearInterval(slideshowInterval);

		var currentItem = $('#articlesPages li.selected');
		var newItem = currentItem.next('li');
		if (newItem.length == 0) {
			newItem = $('#articlesPages li:first');
		}

		currentItem.removeClass('selected');
		newItem.addClass('selected');

		var topValue = $("#articles").css('top');
		var value = parseInt(newItem.attr('rel'));

		$("#articles")
			.fadeTo(1000, 0)
			.animate({'top': value }, 0, function() { $("#next").removeClass('focus'); } )
			.fadeTo(1000, 1);

	}

	function previousRow(evt) {

		$("#next").removeClass('focus');
		$("#previous").addClass('focus');
		$('#articles').stop();

		evt.preventDefault();
		clearInterval(slideshowInterval);

		var currentItem = $('#articlesPages li.selected');
		var newItem = currentItem.prev('li');
		if (newItem.length == 0) {
			newItem = $('#articlesPages li:last');
		}

		currentItem.removeClass('selected');
		newItem.addClass('selected');

		var topValue = $("#articles").css('top');
		var value = parseInt(newItem.attr('rel'));
		
		$("#articles")
			.fadeTo(1000, 0)
			.animate({'top': value }, 0, function() { $("#previous").removeClass('focus'); } )
			.fadeTo(1000, 1);

	}

	// Bind events to click (no keyboard input since shortcut script was seriously broken)
	$("#next").bind('click', function(evt) { nextRow(evt); });

	// Bind events to click
	$("#previous").bind('click', function(evt) { previousRow(evt); });

	// Set slideshow interval in ms
	var slideshowInterval = setInterval("slideshowIntervalHandler()", 5000);

	
 	/**
 	 * This function well add an onclick event for every <a class="button">
 	 * element within the form tag which will submit the form.
	 */ 	
  	function formInit(){
		// init vars
		var buttonHtml = '<p class="buttonHolder"><a href="#" class="button"> <span>{innerText}</span> </a></p>';

		$('form').each(function(){
  			// init vars
			var formId = $(this).attr('id');
			
			// formId is valid
			if(formId != '') {
				// loop every button to be replaced
				$('#' + formId + ' .replaceWithLink').each(function(){
					// get the value of the button - this will become the inner html of the link
					var innerText = $(this).children('input:submit').val();
	
					// replace everything in this element with the above html
					$(this).html(JS_NETLASH.utils.string.replaceAll(buttonHtml, '{innerText}', innerText));
				});
	
				// add onclick event for button
				$('#' + formId + ' p.buttonHolder a.button').each(function () {
					$(this).bind("click", function(e) {
						e.preventDefault();
						$('#'+formId).submit();
					});
				});
			}
		});
	}

	// call form init
  	formInit();

});
