function getFirstImageIndex() 
{
	var index = -1;
	for(var i=0;i<numImages;i++)
	{
		var targetOffset = $('#img'+(i+1)).offset().left ;
		if (targetOffset+10 >= $(window).scrollLeft())
		{ 
			index = i;
			break;
		}	
			
	}
	//if (index==0)
	//	index = 1;
	return index;
}


$(document).ready(function() {
	
   	$('#menu li.menu-parent-collapsible > a').mouseenter( function() {	
		$(this).next().show(650);
	} );
	
	$('#menu li.menu-parent-collapsible').mouseleave( function() {
		$(this).find("ul").hide(650);
	} );
	
	$('#prev_image').click( function(event) {
		
		var index = getFirstImageIndex();
		
		if (index==1 && $(window).scrollLeft()>0)
		{
			$('html,body').animate({scrollLeft: 0}, 1000);
		} else if (index>0)
		{
			index--;
			var targetOffset = $('#img'+(index+1)).offset().left - 90 ;
			
	    	$('html,body').animate({scrollLeft: targetOffset - 10}, 1000);
		    return false;
		}
	
	} );
	
	$('#next_image').click( function(event) {
		
		var index = getFirstImageIndex();
		
		if (index==0 && $(window).scrollLeft()==0)
			index = 0;
		if (index<numImages)
		{
			index++;
			var targetOffset = $('#img'+(index+1)).offset().left - 90 ;
			
	    	$('html,body').animate({scrollLeft: targetOffset - 10}, 1000);
		    return false;
		}
	
	} );
	
	
	
	$('#goto_menu').click( function(event) {
		
		$('html,body').animate({scrollLeft: 0}, 1000);
	    return false;
		
	} );
	
 });


