var load_next = true;
var x_target = 0;
var animation_interval = null;
var n=0;



function load_next_image()
{

	if (load_next)
	{
		//console.log("line 60, length", $("#scroll-images div div:has(a.loaded):last").next().length);
		if ($("#scroll-news-items div div:has(a.loaded):last").next().length > 0)
		{
					//console.log("line 64");

			$("#scroll-new-items div div:has(a.loaded):last")
				.next()
				.children("a")
				.each(
					function(i)
					{		//console.log("i=", i);

						var image_url = $(this).attr("href");
						$(this)
							.children("img")
							.attr("src", image_url)
							.load(load_next_image);
						$(this)
							.addClass("loaded");
					}
				);
				
			if ($("#scroll-images div div:has(a.loaded):first").prevAll().length > 0) load_next = false;
					//console.log("line 84");

		}
		else
		{
			load_next = false;
			load_next_image();
		}
	}
	else
	{
		//console.log("line 95");

		$("#scroll-news-items div div:has(a.loaded):first")

			.prev()
			.children("a")
			.each(
				function(i)
				{
					var image_url = $(this).attr("href");
					$(this)
						.children("img")
						.attr("src", image_url)
						.load(load_next_image);
					$(this)
						.addClass("loaded");
									//console.log(" image loaded", this);

				}
			);
		
		if ($("#scroll-news-items div div:has(a.loaded):last").nextAll().length > 0) load_next = true;
	}

}

function rollover_image()
{
	//$(this).addClass("opacity50");
	//console.log("mouseover", this);
}

function rollout_image()
{
	// $(this).removeClass("opacity50");
		//console.log("rollout", this);

}



function slideview()
	{
		n = (location.hash) ? parseInt(location.hash.replace("#","")) : 1;

//		$("#thumbnails").css('display','none');
		//$("#text").css('display','none');
		
		$("#scroll-news-items").fadeIn(500);	
			
		  // $(".item span")
			// 	.hover(rollover_image, rollout_image)
			//	.mousemove(rollover_image);
				
					
		$("#js-"+n).each(
				function(i)
						{
		
						var image_url = $(this).attr("href");
						//console.log("first this ", this);
		
						//$(this).children("img") .attr("src",image_url).load(load_next_image);
		
				
						}
				) //each	
				
		

	
		
	} //init()
	


$(document).ready(function(){

	slideview();}

  

);
