var current_productid = 0;

function handleFlashProductSelected(productid) {

    var current_product = $('#nutrition-' + current_productid + ', #product-' + current_productid);
        
    if ( current_productid != productid ) {
        var new_product = $('#nutrition-' + productid + ', #product-' + productid);
        
        // Set our product to our new id
        // We do this here because it makes the Flash/JavaScript communication easier
        current_productid = productid;
        
        // Fade out our current product info and fade in our new items
        // And just do display none and block for stupid IE
       if ( $.browser.msie ) {
           current_product.css('display', 'none');
           new_product.css('display', 'block');
        } else {
            current_product.fadeOut(300, function() {
                new_product.fadeIn(500);
            });
        }
    
    }
    
}


function initProductOverlay(event) {

    // toggles visibility of the product nutritions overlay
    function onClick(event) {
        var overlayid = $(this).attr('rel');
        $('#product-overlay-' + overlayid).toggle();
        return false;
    };
    
    // add the click handler
	$('a.product-detail, a.overlay-close').click(onClick);
    
};

$(document).ready(initProductOverlay);
