$(function() {

    var baseURL = '/photos/',
        fileExt = '.jpg',
        curPhoto = 0,
        bigWidth = 586,
        bigHeight = 396,
        ids = new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27); 
        $photoArea = $("#photoLand"),
        firstBGImagePath = "url(" + baseURL + ids[0] + fileExt + ")";
        
    var numPhotos = ids.length;
    for ( var i=0, len=numPhotos; i<len; i++ ) {
      $photoArea.append('<img src="' + baseURL + "t_" + ids[i] + fileExt + '" alt="" id="photo-' + i + '" class="photo-thumb" />');
    }

    $photoArea.append("<div id='bigPhoto'> </div>");
    var $bigPhoto = $("#bigPhoto"),
        $photoThumbs = $(".photo-thumb"),
        $firstThumb = $(".photo-thumb:first-child");
        
    $firstThumb.addClass("current");
    
    $bigPhoto.css({
        width: bigWidth,
        height: bigHeight,
        "background-image": firstBGImagePath
    });
    
    $photoThumbs.live("click", function() {
                
        goToPhoto($(this).attr("id"));
        
        clearInterval(int);
    
    });
    
    function goToPhoto(photo) {
    
        curPhoto = photo.replace("photo-", "");
        
        if (curPhoto == 28) {
            curPhoto = 1;
        };
        
        $photoThumbs.removeClass("current");
        $("#"+photo).addClass("current");
                
        $bigPhoto.css({
            "background-image": "url(" + baseURL + curPhoto + fileExt + ")"
        });
    
    };

    function nextPhoto() {
        curPhoto++;
        sendString = "photo-" + curPhoto;
        goToPhoto(sendString);
    };

    var int = setInterval(nextPhoto, 2500);

});