/* AS220 Main Site Javascript.
 * Shawn Wallace <shawn@as220.org>
 * Brandon Edens <brandon@as220.org>
 * 2009-12-08
 */

/** Loads images into all flickr squares which are defined by class
 * .flickr-square.
 */
function flickering_flickr_load_all_squares()
{
    $('.flickr-square').each(function (i) {
            $(this).load("/random_flickr_image.php");
        });

}

/** Load image into a random flickr squares defined by class .flickr-square.
 */
function flickering_flickr_load_random_square()
{
    var total_squares = $('.flickr-square').size();
    var square_number = Math.ceil(total_squares * Math.random()) - 1;
    var square = $('.flickr-square').get(square_number);
    $(square).load("/random_flickr_image.php");
}

/** Randomly return a number representing seconds between the given min_seconds
 * and max_seconds.
 */
function random_number_of_seconds(min_seconds, max_seconds)
{
    return (1000 * Math.ceil((max_seconds - min_seconds) * Math.random())
            + min_seconds);
}

/** Set the #product_text and #product_image ids to a random product returned
 * by random_product.php
 */
function random_product()
{
    $.getJSON('/random_product.php', function(json){
            $('#product_text').html("<a href='http://as220.org/shop/index.php?main_page=product_info&products_id="+
                                    json.product_id+"'>" + json.product_name + "<br/> $" +  json.product_price+"-</a>");
            $('#product_image').html("<img src='/shop/images/"+json.product_image+"' width=\"160\"/>");
        });
}

/** Set element with id #todays_events to json returned by todaysEvents.json
 */
function todays_events()
{
    $.getJSON('/todaysEvents.json', function(json){
            $('#todays_events').html("<a href='http://as220.org/calendar.html#"+json.todays_id+"'>"+json.todays_events+"</a>");
        });
}


