Event.observe(window, 'load', function() {
	NewGroup.init();
	NewGallery.init();
	Resize.init(720);
});


var Resize = {
	init: function(bodyHeight) {
		this.bodyObj = $('body');
		this.bodyHeight = bodyHeight;
		Event.observe(window, 'resize', this.checkHeight.bind(this));
		this.checkHeight();
	},
	checkHeight: function() {
		this.bodyObj.setStyle({
			'padding-top': Math.min(90, Math.max(25,(90 - (this.bodyHeight-document.viewport.getHeight()-10)*0.7))) + 'px'
		});
	}
}


var NewGroup = {
	init: function() {
		if ($('newGroup')) {
			this.showFormObj = $('newGroup').select('.showForm')[0];
			this.hideFormObj = $('newGroup').select('.hideForm')[0];
			this.formObj = $('newGroup').select('.form')[0];

			this.formObj.hide();
			this.showFormObj.observe('click', this.showForm.bind(this))
			this.hideFormObj.observe('click', this.hideForm.bind(this))
		}
	},
	showForm: function() {
		this.showFormObj.hide();
		this.formObj.show();
	},
	hideForm: function() {
		this.showFormObj.show();
		this.formObj.hide();
		this.formObj.select('form').each(function(f){f.enable();f.reset();});
	},
	disable: function() {
		this.formObj.select('form').invoke('disable');
	}
}

var NewGallery = {
	init: function() {
		if ($('newGallery')) {
			this.showFormObj = $('newGallery').select('.showForm')[0];
			this.hideFormObj = $('newGallery').select('.hideForm')[0];
			this.formObj = $('newGallery').select('.form')[0];

			this.formObj.hide();
			this.showFormObj.observe('click', this.showForm.bind(this))
			this.hideFormObj.observe('click', this.hideForm.bind(this))
		}
	},
	showForm: function() {
		this.showFormObj.hide();
		this.formObj.show();
	},
	hideForm: function() {
		this.showFormObj.show();
		this.formObj.hide();
		this.formObj.select('form').each(function(f){f.enable();f.reset();});
	},
	disable: function() {
		this.formObj.select('form').invoke('disable');
	}
}