WS = {};

WS.Purchase = {
    TASTY_UNLIMITED: {
        id: 277598,
        price: 9.99
    },
    
    get_ejunkie: function(type) {
        var type = type.toUpperCase();
        return WS.Purchase["TASTY_"+type];
    },
    
    get_paypal_link: function(type) {
        var purchase = this,
            ejunkie = purchase.get_ejunkie(type);
        return '<a class="btn gateway" href="https://www.e-junkie.com/ecom/gb.php?i='+ejunkie.id+'&c=single&cl=2342" target="_blank"><span>Pay $'+ejunkie.price+' with PayPal</span></a>'
    },
    
    get_google_link: function(type) {
        var purchase = this,
            ejunkie = purchase.get_ejunkie(type);
        return '<a class="btn gateway" href="https://www.e-junkie.com/ecom/gb.php?i='+ejunkie.id+'&c=gc&cl=2342&ejc=4" target="_blank"><span>Pay $'+ejunkie.price+' with Google Checkout</span></a>'
    },
    
    init: function() {
        var purchase = this;
        
        purchase.themeChosen('unlimited')
        
        // var purchase = this,
        //             chooseDialog = [
        //             '<div class="chooseVariant">',
        //                 '<p>Select the version of Tasty you would like to purchase:</p>',
        //                 '<ul class="variantChoices">',
        //                     '<li><label>',
        //                         '<input type="radio" name="themeChoice" value="unlimited" checked="checked" />',
        //                         '<span class="name">Unlimited &mdash; $'+this.TASTY_UNLIMITED.price+'</span>',
        //                         '<span class="description">Purchase the unlimited license to install Tasty on as many blogs as you\'d like.</span>',
        //                     '</label></li>',
        //                 '</ul>',
        //             '</div>'
        //             ];
        //         
        //         $(chooseDialog.join('')).dialog({
        //             modal: true,
        //             title: 'Choose Single or Unlimited',
        //             width: 500,
        //             height: 300,
        //             buttons: {
        //                 "Continue": function() {
        //                     // first step, calculate the chosen theme
        //                     var theme = $('.chooseVariant').find('input:checked').val();
        //                     purchase.themeChosen(theme, this);
        //                     mpmetrics.track("Chose a version");
        //                 }
        //             }
        //         });
        //         
        //         mpmetrics.track("Purchase dialog opened");
        
    },
    
    themeChosen: function(theme, oldDialog) {
        var purchase = this,
            payDialog = [
                '<div class="payDialog">',
                    '<p><strong>Simply choose one of the methods below to pay for your '+theme+' copy of Tasty.</strong></p>',
                    '<div class="buttons top bottom center">'];
            
            // Add google and paypal buttons
            payDialog.push(purchase.get_paypal_link(theme));
            payDialog.push(purchase.get_google_link(theme));
            
            payDialog.push('</div><p>You\'ll receive a download link immediately after the payment has been made.</p>');
            payDialog.push('</div>');
            
            // $(oldDialog).dialog('destroy');

            $(payDialog.join('')).dialog({
                modal: true,
                title: 'Choose your Payment Method',
                width: 500,
                height: 200,
                focus: function() {
                    var _dialog = $(this);
                    $('a.gateway').bind('click', function(event) {
                        var href = $(this).attr('href');
                        
                        event.stopPropagation();
                        _dialog.dialog('destroy');
                        mpmetrics.track("Went to gateway", {
                            'button_text': $(this).text()
                        });
                    });
                }
            });
    }
}

