Details = Class.create(); /**/

Object.extend(Details.prototype, 

{

	initialize: function(el) {

		this.container = $(el);

		
                if (this.container == undefined){
                    return 0
                }
                else{
                }                

		this.elements = [];

		var u = this.container.down("ul");		

		this.maxHeigth = 0;

		this.tabs = this.container.select("div.detailsitem");


		this.tabs.each((function(fl) {


			fl.observe("click", this.handleClick.bind(this), false);

			

			var sl = $(fl.id+"_content");

			sl.controller = fl;

			

			this.elements.push({fl:fl, sl:sl, accordion:undefined});

			sl.setStyle({display:"none"});


		}).bind(this));


		Event.observe(window, 'load', this.loadAccordions.bind(this), false);			

	},

	handleClick: function(e) {

		this.selectContent(e.element());

	},

	loadAccordions: function(e) {

		this.selectContent(this.elements[0].fl);		

	},

	checkMaxHeight: function(tab) {	
		var th = 0;
		var HH = 0;
                var tmp = 0;
		var slll = tab.select("div.detailscontent");
		if(slll.length > 0){
			slll.each((function(hl) {
				if(HH< hl.getHeight()){
					HH = hl.getHeight();
				}
				th += 50;
			}).bind(this));
		}
                if(slll.length > 0){
                        if(tab.getHeight() > 210){
                                var nHCont = tab.getHeight()-slll.length*40;
                        }else{
                                var nHCont = 220;
                        }
                }
                else{
                    if(tab.getHeight() > 210){    
                                    var nHCont = tab.getHeight();    
                            }else{    
                                    var nHCont = 220;    
                            }           
                }    
                if(th <= 0){
                    tmp = nHCont+20;
                    if(tmp > 0){
                        return tmp;
                    }else
                    {
                        return 240;
                    }
                }else{    
                        return nHCont+this.hederH+th;    
                }
    
        },

	selectContent: function(div) {

		div.addClassName("detailsitemselected");

		this.elements.each((function(e) {

			if (div.id+"_content" == e.sl.id) {

				if (e.sl.style.display == "none") {
					var HtoSet = this.checkMaxHeight(e.sl);
					this.container.setStyle({height:HtoSet+"px"});
					e.sl.setStyle({opacity:0});
					e.sl.show();
					e.sleffect = new Effect.Opacity(e.sl, {from: 0, to: 1.0, duration: 0.5}); 
				} else {
					e.sl.show();
					e.sl.setStyle({opacity:1.0});
				}

				

				var ac = e.sl.down("div.detailstab");				

				if (ac != undefined && e.accordion == undefined) {
					e.accordion = new Accordion(ac, 1, null ,this.container);

				}

				

				var HF = this.checkMaxHeight(e.sl);

				this.container.setStyle({height:HF+"px"});	

				

			} else {

				e.sl.controller.removeClassName("detailsitemselected");

				e.sl.hide();

			}

		}).bind(this));

	}

});
new Details('details');

