var FoxyDomain = "enamoda.foxycart.com/"; // replace this with your store subdomain

function form_fake(link) {
    link_parent = jQuery(link).closest('div.foxycart_form');
    if (link_parent.length < 1) return false;
    // console.info(link);
    // console.info(link_parent);
    href = 'https://' + FoxyDomain + '/cart?' + jQuery(link_parent).find('*').serialize();
    jQuery(link).attr('href', href);
    // console.info(jQuery(link).attr('href'));
    return true;
}

jQuery(document).ready(function ($) {
    // Initialize it on pageload
    form_fake($('div.foxycart_form a.foxycart_submit'));
    // Update it on every change
    $('div.foxycart_form *').change(function () {
        form_fake($(this).closest('div.foxycart_form').find('a.foxycart_submit'));
    });
});

// Ensure it gets run prior to a cart-add request
fcc.events.cart.preprocess.add(function (e) {
    form_fake(e);
});


//var timer = 0;
//// this function hides the cart in a very nice way
//function json_cart_fade_out(){
//if (timer != 0){
//clearTimeout(timer);
//timer = 0;
//}
//$("#fc_cart").animate({
//top: 0 - $("#fc_cart").height(),
//opacity: 0
//}, 1000);
//}
//$(document).ready(function(){
//// shows the cart when the mouse is positioned on an specific link
//$(".fc_link").mouseover(function(){
//if (timer!= 0){
//clearTimeout(timer);
//timer = 0;
//}

//$("#fc_cart").animate({
//opacity: '.99',
//top: '0px'
//}, 1000);
//timer = setTimeout(function(){
//json_cart_fade_out();
//}, 2500);
//// if the user is looking/using the cart don't hide it
//$("#fc_cart").hover(function(){
//clearTimeout(timer);
//timer = 0;
//}, function(){
//timer = setTimeout(function(){
//json_cart_fade_out();
//}, 1000);
//});

//});

//});

//fcc.events.cart.preprocess.add(function() {
//// do something here before opening the cart... maybe some form error checking?
//// if you don't want the cart to open, say for example if there were some data validation problems you
//// want your customer to fix, then return false from this function instead of true.
//return true;
//}

//function minicart_display() {
//fc_FoxyCart = "";
//fc_saFoxyCart = "";
//fc_saFoxyCartQ = "";
//fc_saFoxyCartP = 0;

//fc_FoxyCart += "<tr align='left'>";
//fc_FoxyCart += "<th>item</th>";
//fc_FoxyCart += "<th>qty</th>";
//fc_FoxyCart += "<th>price</th>";
//fc_FoxyCart += "</tr>";

//for (i=0;i<FC.json.products.length;i++) {
//// BEGIN DO NOT EDIT
//fc_BuildFoxyCartRow(FC.json.products[i].name,FC.json.products[i].code,FC.json.products[i].options,FC.json.products[i].quantity,FC.json.products[i].price_each,FC.json.products[i].price);
//// END DO NOT EDIT
//fc_saFoxyCartQ = parseInt(fc_saFoxyCartQ + FC.json.products[i].quantity);
//fc_saFoxyCartP += (100 * parseFloat(FC.json.products[i].price));
//}
//fc_saFoxyCartP /= 100;

//fc_saFoxyCart += "your cart: ";
//fc_saFoxyCart += fc_saFoxyCartQ;
//fc_saFoxyCart += " items $";
//fc_saFoxyCart += fc_saFoxyCartP.toFixed(2);

//// fc_FoxyCart is a javascript variable that now holds your shopping cart data
//// if you have some products in your cart, why not display it?
//if (FC.json.products.length > 0) {
//$("#fc_cart #cart_content").html(fc_FoxyCart);
//$("#fc_sacart #cart_sacontent").html(fc_saFoxyCart);
//$("#fc_cart #fc_edit_txt").html("Edit Cart");
//$("#fc_cart #fc_checkout_txt").html("Check Out");
//} else {
//$("#fc_cart #cart_content").html("Your cart: 0 items $0.00");
//$("#fc_sacart #cart_sacontent").html("your cart: 0 items $0.00");
//$("#fc_cart #fc_edit_txt").html("");
//$("#fc_cart #fc_checkout_txt").html("");
//}
//}
//// This function is called by fc_BuildFoxyCart() for each product in your cart.
//// Feel free to edit this function as needed to display each row of your cart.
//function fc_BuildFoxyCartRow(fc_name,fc_code,fc_options,fc_quantity,fc_price_each,fc_price) {
//fc_FoxyCart += "<tr align='left'>";
//fc_FoxyCart += "<td>" + fc_name + "</td>";
//// fc_FoxyCart += "<td>" + fc_options + "</td>";
//// fc_FoxyCart += "<td>" + fc_code + "</td>";
//fc_FoxyCart += "<td>" + fc_quantity + "</td>";
//// fc_FoxyCart += "<td>" + fc_price_each + "</td>";
//fc_FoxyCart += "<td>" + "$" + fc_price.toFixed(2) + "</td>";
//fc_FoxyCart += "</tr>";

///* fc_saFoxyCart += "your cart:";
//fc_saFoxyCart += "1";
//fc_saFoxyCart += "items ";
//fc_saFoxyCart += "$";*/
//}

//fcc.events.cart.postprocess.add(minicart_display);


//// Just the link to the cart itself
//var cart_request = 'https://'+storedomain+'/cart?'+fcc.session_get();
//// Adding a product
//var cart_request = 'https://'+storedomain+'/cart?name=Test_Product&price=9.99'+fcc.session_get();
//// Retrieving the cart via JSONP
//jQuery.getJSON('https://'+storedomain+'/cart?'+fcc.session_get()+'&output=json&callback=?', function(data) {
//	document.getElementById('prova').value = data;
//});
