$(function ()
{
    $("#izishop-searchresults input[type=image], #izishop-cartDetails input[type=image], #izishop-cartDetails img").hover(
        function () { this.src = this.src.replace(/\-off\.([jnp]{2}g)$/, "-on.$1"); },
        function () { this.src = this.src.replace(/\-on\.([jnp]{2}g)$/, "-off.$1"); }
    );
    $("#btnCart").hover(
        function () { this.src = this.src.replace(/\-off\.([jnp]{2}g)$/, "-hover.$1"); },
        function () { this.src = this.src.replace(/\-hover\.([jnp]{2}g)$/, "-off.$1"); }
    );
});

/**
 * @param int ID
 * @param int quantity
 */
function addToCart()
{
    iID       = (arguments.length > 0) ? parseInt(arguments[0]) : parseInt($("#id").val());
    iQuantity = (arguments.length > 1) ? parseInt(arguments[1]) : parseInt($("#quantity").val());
    
    $.post("actions/" , { action: "addToCart", id: iID, quantity: iQuantity }, function (sMessage)
    {
        alert(sMessage);
    });
}


function emptyCart()
{
    $.post("actions/" , { action: "emptyCart" }, function ()
    {
        location.reload();
    });
}


/**
 * @param int ID
 * @param int quantity
 */
function removeFromCart()
{
    iID       = (arguments.length > 0) ? parseInt(arguments[0]) : parseInt($("#id").val());
    iQuantity = (arguments.length > 1) ? parseInt(arguments[1]) : parseInt($("#quantity").val());
    
    $.post("actions/" , { action: "removeFromCart", id: iID, quantity: iQuantity }, function ()
    {
        location.reload();
    });
}