/*
* Base Overlay Object
*
* This object is not meant to be used on its own.  This object
* should be extended by another object.
* Functionality that is shared by all Modals should be part of this
* object in order to reduce duplicated code.  A specific Modal
* may override functions from this class if necessary.
*/
(function($){

    
    PS.ExpandCollapse = {

        o:{
        },
        /*
	    * The configure function needs to be called after the constructor so that the attributes
	    * of the extended classes are available.
	    */
        configure:function(settings){
			
            var defaultSettings = {

            };
            
            this.o = $.extend({}, defaultSettings, settings);
            this.o.inTransition = false;
            this.attachEvents();
        },

        attachEvents:function(){
            $('#credit-card-wrapper').delegate('#myRadio1', 'mousedown', $.proxy(this, 'expand'));
            $('#credit-card-wrapper').delegate('#myRadio0', 'mousedown', $.proxy(this, 'collapse'));
            $('#credit-card-wrapper').delegate('#label-card', 'mousedown', $.proxy(this, 'expand'));
            $('#credit-card-wrapper').delegate('#label-paypal', 'mousedown', $.proxy(this, 'collapse'));

            $('#credit-card-wrapper').delegate('#different-billing-address', 'mousedown', $.proxy(this, 'expandCollapse'));
            $('#credit-card-wrapper').delegate('#myCheckbox0', 'mousedown', $.proxy(this, 'expandCollapse'));
        },

        expand: function(e){
            if(!$('#card').attr('checked')){
                this.expandContent($(this.o.collapsibleContent));
            }
        },
        collapse: function(e){
            if(!$('#paypal').attr('checked')){
                this.collapseContent($(this.o.collapsibleContent));
            }
        },
        
        expandCollapse: function(e){

            if(!this.o.inTransition){
                this.o.inTransition = true;
                if(!$('#different-billing-address').attr('checked')){
                    
                    $(this.o.collapsibleContent2).slideDown(200, $.proxy(function(){
                        $('#different-billing-address').attr('checked', true);
                        this.o.inTransition = false;
                    }, this));
                
                }else{
                    
                    $(this.o.collapsibleContent2).slideUp(200, $.proxy(function(){
                        $('#different-billing-address').attr('checked', false);
                        this.o.inTransition = false;
                    }, this));
                
                }
            }
            
        },

        
        expandContent: function($target){
            
            if(!this.o.inTransition){
                this.o.inTransition = true;
                $target.toggle(200, $.proxy(function(){
                    this.o.inTransition = false;
                }, this));
            }
            
        },
        collapseContent: function($target){
            
            if(!this.o.inTransition){
                this.o.inTransition = true;
                $target.toggle(200, $.proxy(function(){
                    this.o.inTransition = false;
                }, this));
            }
            
        },

        
        toggleContent: function($target){
            if(!this.o.inTransition){
                this.o.inTransition = true;
                $target.toggle(200, $.proxy(function(){
                    this.o.inTransition = false;
                }, this));
            }
        }
    };
})(jQuery);

