/*  
*  Common Javascript File
*
*/

var GiftgirlAccordion = new Class({

        initialize: function(){
         
            this.trigger = 'h2.accordian';
            this.content = 'div.accordian';
            this.openedClass = 'opened';
            this.disabledClass = 'disabled';
            this.container = $('right-scroll');
            this.el = new Accordion(this.trigger, this.content, { 
                    show: selectedAccordion,
                    alwaysHide: true, 
                    duration: 200,
                    onActive: function(item,e){
                        item.getParent().addClass(this.openedClass); 
                    }.bind(this),
                    onBackground:  function(item){  
                        item.getParent().removeClass(this.openedClass); 
                    }.bind(this)
                }, this.container );
            this.defaultOpenedIndex = 100;
        },
        
        open: function(index){
            this.el.display(index);
        },
        
        closeAll: function(index){
            this.el.display(100);
        },
        
        disable: function(){
            // Store the open state
            selectedAccordion = this.getOpenedIndex();
            this.closeAll();
            this.container.addClass(this.disabledClass);
            this.container.getElements(this.openedClass).each( function(opened){
                    opened.removeClass(this.openedClass);
            });
        },
        
        enable: function(){
            this.container.removeClass(this.disabledClass);
        },
        
        getOpenedIndex: function(){
            var i = 0;
 	    var selected_index = this.defaultOpenedIndex;
            this.container.getElements(this.trigger).each( function(item){
                    if(item.getParent().hasClass(this.openedClass)){
                        selected_index = i;
                    }
                    i++;
            }.bind(this));
            return selected_index;
        }   
        
}); 




function showReminderFields(){
	q = $('reminders').getElements('select.new-reminder');
	v = $('reminders').getElements('div.reveal-fields');
	q.addEvent('click', function (){
		v.removeClass('hide');
	});
}

// Commenting out show reminder fields code
// window.addEvent('domready', showReminderFields);
