function switch_frame(thumbnail){
	var thumbnail = thumbnail;
	document.getElementById("frame_img").src = thumbnail.src;
	document.getElementById("frame_img").title = thumbnail.title;
	document.getElementById("frame_img").alt = thumbnail.alt;
}

var slider;
var slider_width;
var curr_position;
var next_position = 0;
var max_pages;
var curr_page;
var thumbs;

//timers to contorl sliding motion
var timer;
var step = 1;

window.onload = getThumbs;

function getThumbs(){
    thumbs = document.getElementById("slider").title;
    max_pages = Math.ceil(thumbs/4);
    curr_page = 1;
    
}

function move_forward(){
    if(curr_page < max_pages){
        document.getElementById("rightArrow").onclick = "";
        slider = document.getElementById("slider");
        timer = setInterval("slide_forward()","5");
        slider.style.left = next_position + "px";
        curr_page += 1;
    }
}

function move_backward(){
    if(curr_page > 1){
        document.getElementById("leftArrow").onclick = "";
        slider = document.getElementById("slider");
        timer = setInterval("slide_backward()","5");
        slider.style.left = next_position + "px";
        curr_page -= 1;
    }
}

function slide_forward(){
    if(step%74 != 0){
        next_position -= 12;
        slider.style.left = next_position + "px";
        step++;
    }else{
        clearInterval(timer);
        slider.style.left = -1 * 868 * (curr_page - 1) + "px";
        step = 1;
        document.getElementById("rightArrow").onclick = move_forward;
    }
}

function slide_backward(){
    if(step%74 != 0){
        next_position += 12;
        slider.style.left = next_position + "px";
        step++;
    }else{
        clearInterval(timer);
		    slider.style.left = -1 * 868 * (curr_page - 1) + "px";
        step = 1;
        document.getElementById("leftArrow").onclick = move_backward;
    }
} 
