/**
 * Washington Wine JS
 * Primary Javascript for Washington Wine Site
 **/

/* Legacy */

var washingtonwine = {
	makeShowHides: function() {
		/* Loop through animating elements and popuplate array with height style effect for each */
		this.showHides = $$('.extendable').map(function(el){
			el.open = false;
			return new Fx.Style(el, 'height', {
				duration: 100
			}).hide();
		});
		/* Get toggle buttons array, loop though and add event handlers */
		$$('a.toggle').each(function(el, index){
			/* Get associated showHide element */
			var target = this.showHides[index];

			/* Add event handler to toggle button and manipulate associated showHide element */
			el.addEvent('click', function(e) {
				e = new Event(e);
				if (!target.element.open) {
					target.stop();
					target.start(target.element.scrollHeight);
					target.element.open = true;
					el.textContent = "Close Event Details";
					el.innerText = "Close Event Details";
				} else {
					target.stop();
					target.start(0);
					target.element.open = false;
					el.textContent = "Full Event Details";
					el.innerText = "Full Event Details"
				}
				e.stop();
			}.bind(this));
		}, this);
	},
	growShowHide: function(element) {
		/* Loop through animating elements and grow the appropriate one */
		$$('.extendable').each(function(el, index){
			if (element == el) {
				this.showHides[index].start(this.showHides[index].element.scrollHeight);

			}
		}, this);
	},
	init: function() {
		this.makeShowHides();
	}
}