// JavaScript Document

// SETTINGS
var item_width = 600; // WIDTH OF PHOTOS
var slideshow = document.getElementById("photo-container"); // FRAME
if(slideshow){
	var slideshow_item = slideshow.getElementsByTagName("img"); // ROTATING ELEMENT
	var btn_left = document.getElementById("photo-arrow-left"); // LEFT ARROW
	var btn_right = document.getElementById("photo-arrow-right"); // RIGHT ARROW 
	var current_num = parseInt(document.getElementById("gallery-num-current").innerHTML);

	// CONTROL SPEED
	var left = 0;
	var current = 0;
	var speed = 600;
	
	
	// NO NEED TO EDIT BELOW THIS LINE
	var slideshow_total = slideshow_item.length;
	var slideshow_loop = '';
	
	btn_left.onclick = function() {
		move_item('left');
	}
	
	btn_right.onclick = function() {
		move_item('right');
	}
	
	slideshow.style.left = 0;
	
	function move_item(value) {
		speed = 5;
		var left = slideshow.style.left;
		current = (value=='left') ? current-1 : current+1;
		if(current>=slideshow_total) {
			current = 0;
			current_num = 2;
			value = 'left';
		}
		if(current<0) {
			current = (slideshow_total-1);
			current_num = (slideshow_total-1);
			value = 'right';
		}
		var target = item_width*current;
		animate(left,target,value);
	}
	
	function animate(left,target,value) {
		left = parseInt(left);
		target = parseInt(target);	
		if(left<0) left = left*-1;
		if(value=='left') {
			slideshow.style.left = "-"+target+"px";
			current_num--;
		}
		if(value=='right') {
			slideshow.style.left = "-"+target+"px";
			current_num++;
		}
		document.getElementById("gallery-num-current").innerHTML = current_num;
	}
	
}
