var margins = 100; // top, bottom

//var stripIndex = Math.floor(Math.random()*strips.length)
window.strip = window.strips[window.stripIndex];

function writePhoto(photoName, number) {
	document.write("<td><img class='photo' id='photo" + number + "' src='photos/");
	document.write(photoName);
	document.write("'></td>");
}

function writeNextLink() {
    var nextItem = window.stripIndex + 1;
    if (nextItem >= window.strips.length - 1) nextItem = 0;
    document.write("<a href='set" + (nextItem + 1) + "'>Next Strip</a>");
}

var resizeImages = function () {
	var images = $(".photo");//document.getElementsByTagName("img");

	window.imageHeight = window.innerHeight - 18 - margins;
	window.imageWidth = window.imageHeight * 1.49;
	window.numImages = images.length;

    images.height(window.imageHeight);
    images.width(window.imageWidth);
}

var scrollWindowToLeft = function () {
	window.setTimeout(function () { 
		$.scrollTo($('#photoTable'), 1000, {});
	}, 800);
}

function scrollToPhoto(photoNum) {
    leftOffset = (window.innerWidth - window.imageWidth) / -2;
    photoID = '#photo' + photoNum;
    if (photoNum >= window.numImages - 1) {
        // We're at the right
        $("#rightArrow").fadeOut("slow");
    } else {
        $("#rightArrow").fadeIn("slow");
    }
    
    if (photoNum == 0) {
        // We're at the left
        $("#leftArrow").fadeOut("slow");
    } else {
        $("#leftArrow").fadeIn("slow");
    }
        
	$.scrollTo(photoID, 1000, {offset: {left: leftOffset}});    
}

var photoNum = 0;

//resizeImages();
if ($.browser.msie) {
    alert("Its IE");
} else {
    $(document).ready(resizeImages);    
}

$(window).resize(resizeImages);
//$(window).scroll(hideArrow);

$(document).ready(function () {     
    $("#leftArrow").click( function () {
        photoNum--;
        if (photoNum < 0) photoNum = 0;
        scrollToPhoto(photoNum);
    });
    $("#rightArrow").click( function () {
        photoNum++;
        if (photoNum > window.numImages - 1) photoNum = window.numImages;
        scrollToPhoto(photoNum);
    });


    $("#otherSetLink").toggle( 
        function () {
            $("#otherSetBox").fadeIn("slow");
        },
        function () {
            $("#otherSetBox").fadeOut("slow");
        }        
    );
    
    $("#aboutLink").click(function () {
        $("#aboutBox").slideToggle("normal");
    });
    
    $("#closeAboutBox").click(function () {
        $("#aboutBox").slideToggle("normal");
    })

});

//scrollWindowToLeft();