// JavaScript Document

Element.extend({
	smoothHide: function(effectOptions){
		/*var styles = this.getStyles('padding-top', 'padding-bottom', 'margin-top', 
			'margin-bottom', 'border-top-width', 'border-bottom-width');*/
		var styles = {'padding-top': this.getStyle('padding-top'), 'padding-bottom': this.getStyle('padding-bottom'),
			'margin-top': this.getStyle('margin-top'), 'margin-bottom': this.getStyle('margin-bottom'),
			'border-top-width': this.getStyle('border-top-width'), 'border-bottom-width': this.getStyle('border-bottom-width')};
		styles.height = this.offsetHeight-styles['padding-top'].toInt()-styles['padding-bottom'].toInt()+"px";
		var zero = {height: '0px', opacity: 0};
		$each(styles, function(style, index, name){ zero[name] = 0; });
		this.effects(effectOptions||{}).start(zero).chain(function(){
			this.setStyles(styles).setStyle('display','none');
		}.bind(this));
                Cookie.set(this.id, 'none');
     	},

	smoothShow: function(effectOptions, heightOverride){
		if(this.getStyle('display') == "none" || 
			 this.getStyle('visiblity') == "hidden" || 
			 this.getStyle('opacity')==0){
			//toggle display, but hide it
			this.setStyles({ 'display':'block', 'opacity':0 });
			var h = heightOverride || this.offsetHeight;
			var styles = Object.extend({opacity: 1},
				{'padding-top': this.getStyle('padding-top'), 'padding-bottom': this.getStyle('padding-bottom'),
			'margin-top': this.getStyle('margin-top'), 'margin-bottom': this.getStyle('margin-bottom'),
			'border-top-width': this.getStyle('border-top-width'), 'border-bottom-width': this.getStyle('border-bottom-width')});
				/*this.getStyles('padding-top', 'padding-bottom', 'margin-top', 
					'margin-bottom', 'border-top-width', 'border-bottom-width'));*/
			styles.height = h-styles['padding-top'].toInt()-styles['padding-bottom'].toInt()+"px";
			var zero = { height: '0px', opacity: 0 };
			$each(styles, function(style, index, name){ zero[name] = 0; });
			this.setStyles(zero).effects(effectOptions||{}).start(styles);
			Cookie.set(this.id, 'block');
		}
	},
	
	toggle: function() {
		if (this.getStyle('display') == "none") {
			this.smoothShow();
		 } else {
			this.smoothHide();
		}
	}

});

window.addEvent('domready', function(){
  var scls = ['link-Verein', 'link-Angebote', 'training', 'contact', 'links'];
  
  scls.each(function(id){
    var cookie = Cookie.get(id);
    if (cookie && $chk($(id))) {
       $(id).setStyles({'display': cookie}); }
  });
  

});
