/////
// Functions
/////

// Equivilant to document.getElementById
function $(id)
{
    return document.getElementById(id);
}

// The onload event handler for the products page
// Pre-caches all product images
function initProductsPage()
{
    var images = new Array();
    var product_count = 16;
    
    for ( var i = 0; i < product_count; i++ )
    {
        images[i] = new Image();
    }
    
    images[0].src = "images/missile_launcher_125.jpg";
    images[1].src = "images/stress_button_125.jpg";
    images[2].src = "images/green_house_125.jpg";
    images[3].src = "images/roll_up_drum_kit_125.jpg";
    images[4].src = "images/beverage_cooler_125.jpg";
    images[5].src = "images/circus_cannon_125.jpg";
    images[6].src = "images/cup_warmer_125.jpg";
    images[7].src = "images/interactive_aquarium_125.jpg";
    images[8].src = "images/pedometer_125.jpg";
    images[9].src = "images/rc_car_125.jpg";
    images[10].src = "images/roll_up_chess_kit_125.jpg";
    images[11].src = "images/roll_up_piano_125.jpg";
    images[12].src = "images/aroma_diffuser_125.jpg";
    images[13].src = "images/vacuum_clearer_125.jpg";
    images[14].src = "images/virtual_girlfriend_125.jpg";
    images[15].src = "images/plasma_ball_125.jpg";
}

// Used when user clicks on a page number link within the products page
// Switches the current products displayed with another based on the page number selected
function changeProductPage(page_number)
{
    ajaxRequest_products(page_number);
    return false;
}

// Handles response from php/ajax_products
function ajaxResponse_products(responseText, responseStatus)
{
    if ( responseStatus == 200 )
    {
        $("products").innerHTML = responseText;
    }
    else
    {
        // alert("Error: " + responseStatus);
    }
}

// Makes an AJAX request to php/ajax_products
function ajaxRequest_products(page_number, items_per_page)
{
    var myRequest = new AjaxRequest("php/ajax_products.php", ajaxResponse_products);
    myRequest.update("page=" + page_number, "POST");
}

// Changes large image and text within the feature products box
function changeFeatureImage(title, image)
{
	$("large_thumb").style.background = "url(" + image + ")";
    $("large_thumb").innerHTML = title;    
}
