function _insert_id(num, id, after)
{
	id += num;
	str = '#' + ids[id] + (after ? ' ' + after : '');

	return str;
}


$(document).ready(function() {
	//Speed of the slideshow
	var speed = 5000;
	
	
	for (var j = 0; j < ids.length; j+=5)
	{
	
	
	//You have to specify width and height in #slider CSS properties
	//After that, the following script will set the width and height accordingly
	$(_insert_id(j, 0, false) + ',' + _insert_id(j, 1, 'li')).width($(_insert_id(j, 2, false)).width());	
	$(_insert_id(j, 1, false)).width($(_insert_id(j, 2, false)).width() * $(_insert_id(j, 1, 'li')).length);
	$(_insert_id(j, 0, false)+', '+_insert_id(j, 1, 'li')).height($(_insert_id(j, 2, false)).height());
	
	//Assign a timer, so it will run periodically
	//run = setInterval('newsscoller(0, '+j+')', speed);	
	
	$(_insert_id(j, 1, 'li:first')).addClass('selected');
	

	//Next Slide by calling the function
	query1='$(_insert_id('+j+', 3)).click(function () {'+
	'	newsscoller(0, '+j+');'+
	'	return false;'+
	'})';

	//Previous slide by passing prev=1
	query2='$(_insert_id('+j+', 4)).click(function () {'+
		'newsscoller(1, '+j+');	'+
		'return false;'+
	'});';
	
	eval(query1);
	eval(query2);
	
	//Mouse over, pause it, on mouse out, resume the slider show
	/*$(_insert_id(j, 2, false)).hover(
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('newsscoller(0, '+j+')', speed);	
		}
	); */	
	
	
	}
});


function newsscoller(prev, j) {
	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $(_insert_id(j, 1, 'li.selected')).length ? $(_insert_id(j, 1, 'li.selected')) : $(_insert_id(j, 1, 'li:first'));

	//if prev is set to 1 (previous item)
	if (prev) {
		
		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $(_insert_id(j, 1, 'li:last'));
	
	//if prev is set to 0 (next item)
	} else {
		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $(_insert_id(j, 1, 'li:first'));
	}

	//clear the selected class
	$(_insert_id(j, 1, 'li')).removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');

	//Scroll the items
	$(_insert_id(j, 0, false)).scrollTo(next_image, 800);			
	
}