﻿$(document).ready(function () {


    //Button --> Add To Cart
    $(".buttonspec").live('click', function () {

        $(".spec-on").hide();

        //Get Cart 
        var cart = $.parseJSON($.cookie("json_cart"));
        if (cart == null) { cart = []; }

        //Add the new Item
        cart.push({ id: $("#hiddenid").attr("value"), quantity: $(".txtquantity").val(), format: $(".ddlFormats").val() });

        //Set Cart
        $.cookie("json_cart", JSON.stringify(cart), { expires: 30 });

        $(".spec-off").fadeIn(500);
        return false;
    });


    //Button --> Delete Item
    $(".delete-cart-item").live('click', function () {

        //Get Cart into array
        var json = $.parseJSON($.cookie("json_cart"));

        //Delete Item
        json.splice($(".delete-cart-item").index(this), 1);

        //Set Cart in json
        $.cookie("json_cart", JSON.stringify(json), { expires: 30 });

        //Fade out Row and delete it.
        $(this).parent().parent().fadeOut(500, function () { $(this).html("") });
    });


    //Show the Registration/Edit Form
    $(".show-profile-details").live('click', function () {
        $(".profile-details").slideDown('slow');
        $(".profile-login-choices").slideUp('slow');
    });


    //When pressing Login
    $(".login-button").live('click', function () {

        $.get('/UserControls/LoginPopup.ashx?u=' + $("#txtUsername").val() + "&p=" + $("#txtPassword").val(), function (data) {

            //If login failed, flash box in red;
            if (data == "0") { $("#osx-container").stop(true, true).animate({ backgroundColor: "#B53333" }, 1000).animate({ backgroundColor: "#eee" }, 1000); }
            else { window.location.reload(true); }

        });
    });

    //Make the ".login-button" the default button in the login form.
    $("#osx-modal-content input").keyup(function (e) { if (e.keyCode == 13) { $(".login-button").click(); } });

});



