/*
    requires jquery 1.2.6+

    Cycle thru a photo and it's caption on a page using
    ajax call to the backend.

    start the loader at the onload point:

    $(function(){
        cycle_photo( album_category_name, photo_size, div_id, delay);
    });
    <div id="pic">
      <img src="" />
      <p>Caption goes here<p>

*/

var _key = 0;
var _sel = "";

/*
    Ajax call to load next image.
*/
function load_next_photo(data, textStatus) {
    url = data['photo_url'];
    caption = data['photo_title'];
    _key = data['key'];
    $(_sel + " > img").attr("src",url);
    $(_sel + " > p").text(caption);
};

function cycle_photo(category, size, id, delay)
{
    _sel = "div" + id;
    $.getJSON("/random_photo/" + category + "/" +
	      size + "/" + _key + "/", load_next_photo);
    window.setTimeout(function(){cycle_photo(category, size, id, delay);}, delay);
};

