/* Accordion functions */

Accordion.implement({
    showAll: function() {
        var obj = {};
        this.previous = -1;                  //  Added this line
        this.elements.each(function(el, i){
            obj[i] = {};
            this.fireEvent('onActive', [this.togglers[i], el]);
            for (var fx in this.effects) obj[i][fx] = el[this.effects[fx]];
        }, this);
        return this.start(obj);
    },
    hideAll: function() {
        var obj = {};
        this.previous = -1;                  //  Added this line
        this.elements.each(function(el, i){
            obj[i] = {};
            this.fireEvent('onBackground', [this.togglers[i], el]);
            for (var fx in this.effects) obj[i][fx] = 0;
        }, this);
        return this.start(obj);
    },
    hidePlan: function(index) {
        var obj = {};
        this.previous = -1;                  //  Added this line
        this.elements.each(function(el, i){
            obj[i] = {};
	    if (index == i) {
		obj[i].Height -= 25;
		for (var fx in this.effects) obj[i][fx] = el[this.effects[fx]];
	    }
        }, this);
        return this.start(obj);
    },
    showPlan: function(index) {
        var obj = {};
        this.previous = -1;                  //  Added this line
        this.elements.each(function(el, i){
            obj[i] = {};
	    if (index == i) {
		obj[i].Height += 25;
		for (var fx in this.effects) obj[i][fx] = el[this.effects[fx]];
	    }
        }, this);
        return this.start(obj);
    },
    Start: function(index) {
	    var obj = {};
	    this.previous = -1;		//TM: added this
	    this.elements.each(function(el, i){
		obj[i] = {};
		if (index == i) {
		    this.fireEvent('onActive', [this.togglers[i], el]);
		    for (var fx in this.effects) obj[i][fx] = el[this.effects[fx]];
		}
	    }, this);
	    return this.start(obj);
    },
    showThis: function() {
	    var obj = {};
	    this.previous = -1;		//TM: added this
	    this.elements.each(function(el, i) {
		obj[i] = {};
		var mysel = document.getElementById('plannum1');
		    //show first accordion, and second one ("General" section) if we have a plan preselected;
		    //  this code requires that the "Select" prompts (below) have null value (<option value="">)
		//if ( document.myform.res_state.value != "" ) {	//got state of residence yet?
		    if (i == 0 || (i == 1 && mysel && mysel.value != "")) {
			this.fireEvent('onActive', [this.togglers[i], el]);
			for (var fx in this.effects)
			     obj[i][fx] = el[this.effects[fx]];
			swapImage(0);
		   // }
		}
	    }, this);
	    return this.start(obj);
	}

});

window.addEvent('domready', function() {
    myaccordion = new Accordion('h3.atStart', 'div.atStart', {
    	opacity: true,duration: 600,
    	onActive: function(toggler) {
    									var pos = this.togglers.indexOf(toggler);
    									var div = "arrow" + pos;
    									var element = document.getElementById(div);
    									element.className = "openclosebutton button-open-hover";
    								},
    	onBackground: function(toggler) {
    										var pos = this.togglers.indexOf(toggler);
    										var div = "arrow" + pos;
    										var element = document.getElementById(div);
    										element.className = "openclosebutton button-closed-hover";
    									}   
    }, $('accordion'));
    myaccordion.showThis();
}, this);


function expandall() {
	myaccordion.showAll();
	loadImages(null,1);
}

function collapseall() {
    myaccordion.hideAll();
    loadImages();
}

function showPlan() {
    myaccordion.showPlan(0);
}
