var wall = {
	init: function (button, formBox) {
		this.wBtn 		= $(button);
		this.formBox 	= $(formBox);
		
		this.wBtn.addEvent('click', this.formToggle.bind(this));
	},
	shown: false,
	formToggle: function () {
		//this.formBox.toggleClass('active-form');
		if (this.shown) {
			this.formBox.setStyle('display', 'none');
			this.wBtn.getElement('span').set('html', '&darr;');
		} else {
			this.formBox.setStyle('display', 'block');
			this.wBtn.getElement('span').set('html', '&uarr;');
		}
		this.shown = !this.shown;
		return false;
	}
}

		
var blockSlide = new Class({
	big: true,
	
	initialize: function(box, title){
		this.title 	= $(title);
		this.box 	= $(box);
		this.height 	= this.box.getStyle('height');
		this.heightMin 	= this.title.getStyle('height').toInt() + 5;
		this.title.addEvent('click', this.toggle.bind(this));
		
		var big = Cookie.read('slide_' + this.box.id);
		if(box.hasClass('nodisplay')) big = false;
		if(box.hasClass('nohide')) {
			big = 'true';
		}
		
		if (big == null) {
			this.big = true;
		} else if (big != 'true') {
			this.big = false;
			this.title.addClass('blockheader-close');
			this.box.setStyle('height', this.heightMin);
		}
	},
	
	toggle: function () {
		if (this.big) {
			this.hide();
		} else {
			this.show();
		}
		this.big = !this.big;
	},
	
	show: function () {
		this.title.removeClass('blockheader-close');
		this.setAutoHeight.bind(this).delay(700);
		this.box.morph({'height': this.height});
		Cookie.write('slide_' + this.box.id, true);
				
		if(this.title.id == 'selectHeader') {
			$('originalCont').show();
		}
		if(this.title.id == 'picturesHeader') {
			$('pictures_container').show();
			bgScroll = new imagesList($('slider_container'), $('bgs-box'), $('bgi_in'), 500, 252, 'vertical', 5, 5);
			//initScroll($('slider_container'), $('bgs-box'), $('bgi_in'), 500);
		}
		if(this.title.id == 'designsHeader') {
			$('designs_container').show();
			//initScroll($('eff_slider_container'), $('design-box'), $('design_in'), 500);
			desScroll = new imagesList($('eff_slider_container'), $('design-box'), $('design_in'), 500, 252, 'vertical', 6, 6);
		}
	},
	
	hide: function () {
		this.box.setStyle('height', this.box.getSize().y);
		this.height = this.box.getSize().y;
		
		this.title.addClass('blockheader-close');
		this.box.morph({'height': this.heightMin});
		Cookie.write('slide_' + this.box.id, false);
		if(this.title.id == 'selectHeader') {
			$('originalCont').hide();
		}
		if(this.title.id == 'picturesHeader') {
			$('pictures_container').hide();
		}
		if(this.title.id == 'designsHeader') {
			$('designs_container').hide();
		}
	},
	
	setAutoHeight: function () {
		if(this.box.id == 'design') {
			this.box.setStyle('height', this.height);
		} else {
			this.box.setStyle('height', 'auto');
		}
	}
});


// автораздвигающийся textarea
var autoText = new Class({
	initialize: function(textarea){
		this.el = $(textarea);
		this.width = this.el.getStyle('width');
		
		this.el.addEvent('keyup', this.check.bind(this));
		this.check(this.el);
	},
	
	check: function (ev) {
		var newText = this.el.value.replace('<', '1').replace('>', '1').replace(new RegExp("\n", "g"), '<br/>') + ' 123';
		//newText = newText.replace('<', '1').replace('>', '1');
		var a = new Element('div', {'style': {'width': this.width}, 'html': newText}).inject(document.body);
		this.el.setStyle('height', a.getStyle('height').toInt() * 1.2 + 15);
		if (a.getStyle('height').toInt() < 15) {
			this.el.setStyle('height', 19);
		}
		a.destroy();
	}
});

