//console.log(true);
speed = 0;
clips = 0;

offset_x = 0;


disable_show = false;

$(document).ready(function() {
	clips = $("div.filmstrip ul").children().length;
	$("div.filmstrip ul").width((315*clips));
	
	primary_clip = Math.round(clips/2);
	previous_clip = primary_clip-1;
	next_clip = primary_clip+1;
	   
	screen_width = $(window).width();
	filmstrip_width = $("div.filmstrip").width();
	slider_width =  $("div.filmstrip ul").width();
	
	offset_x = -(slider_width-screen_width)/2;
	
	$("div.filmstrip ul").animate({marginLeft: offset_x+"px" }, speed);
	
	speed = 2000;
	
	slide()
});

function slide() {
	var count = 1;
	$("div.filmstrip ul li").each(function() {
		if (count==previous_clip) {
			$(this).append('<div class="previous"></div>');
		} else if (count==next_clip) {
			$(this).append('<div class="next"></div>');
		} else if (count==primary_clip) {
			$("div.content div.column.first").html("<h2>"+$(this).children("img").attr("alt")+"</h2>"+$(this).children("span.caption").html());
			span = $(this).children("span");
			$(this).html($(this).children("img"));
			$(this).append(span);
		} else {
			span = $(this).children("span");
			$(this).html($(this).children("img"));
			$(this).append(span);
		}
		count++;
	});
	
	$("div.filmstrip ul li div.previous").click(function(e) {
		e.preventDefault();
		
		$("div.filmstrip ul li div.previous").fadeOut(100);
		$("div.filmstrip ul li div.next").fadeOut(100);
		offset_x = Math.round(offset_x+310);
		$("div.filmstrip ul").animate({marginLeft: offset_x+"px" }, speed, function() {
			
			primary_clip = primary_clip-1;
			previous_clip = previous_clip-1;
			next_clip = next_clip-1;
			
			slide();
			$("div.filmstrip ul li div.previous").fadeIn(300);
			$("div.filmstrip ul li div.next").fadeIn(300);
		});
	});
	
	$("div.filmstrip ul li div.next").click(function(e) {
		e.preventDefault();
		
		$("div.filmstrip ul li div.previous").fadeOut(100);
		$("div.filmstrip ul li div.next").fadeOut(100);
		offset_x = Math.round(offset_x-310);
		$("div.filmstrip ul").animate({marginLeft: offset_x+"px" }, speed, function() {
			
			primary_clip = primary_clip+1;
			previous_clip = previous_clip+1;
			next_clip = next_clip+1;
			
			slide();
			$("div.filmstrip ul li div.previous").fadeIn(300);
			$("div.filmstrip ul li div.next").fadeIn(300);
		});
	});
		

}




