$(document).ready(function() {

	//Speed of the slideshow
	var speed = 5000;
	
	//You have to specify width and height in #slider CSS properties
	//After that, the following script will set the width and height accordingly
	$('#mask-gallery, #gallery li').width($('#scrollnews').width());	
	$('#gallery').width($('#scrollnews').width() * $('#gallery li').length);
	$('#mask-gallery, #gallery li,').height($('#scrollnews').height());
	
	/*Seconde news slider*/
	$('#mask-gallery1, #gallery1 li').width($('#scrollnews1').width());	
	$('#gallery1').width($('#scrollnews1').width() * $('#gallery1 li').length);
	$('#mask-gallery1, #gallery1 li,').height($('#scrollnews1').height());
	
	//Assign a timer, so it will run periodically
	var run = setInterval('newsscoller(0)', speed);	
	
	$('#gallery li:first').addClass('selected');
	$('#gallery1 li:first').addClass('selected');

	
	//Mouse over, pause it, on mouse out, resume the slider show
	$('#scrollnews').hover(
	
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('newsscoller(0)', speed);	
		}
	);
	
	$('#scrollnews1').hover(
	
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('newsscoller(0)', speed);	
		}
	); 	
	
});


function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
	var current_image1 = $('#gallery1 li.selected').length ? $('#gallery1 li.selected') : $('#gallery1 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() : $('#gallery li:last');
		var next_image1 = (current_image1.prev().length) ? current_image1.prev() : $('#gallery1 li:last');
		
	//if prev is set to 0 (next item)
	} else {
		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
		var next_image1 = (current_image1.next().length) ? current_image1.next() : $('#gallery1 li:first');
		
	}

	//clear the selected class
	$('#gallery li').removeClass('selected');
	$('#gallery1 li').removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');
	next_image1.addClass('selected');
	

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);
	$('#mask-gallery1').scrollTo(next_image1, 800);		
	
	
}