﻿LM.Index = {
	InitAccordian: function() {
		$$('.noticeLink').each(function(item) {
			if (item.getPrevious().scrollHeight > 58) {
				item.setStyles({
					display: 'block'
				})
			}
		});
		$$('.noticeBody').setStyles({
			height: '58px',
			overflow: 'hidden'
		});
		$$('.noticeLink').addEvent('click', function(e) {
			e.stop();
			var elem = this.getPrevious();
			LM.Index.MorphOut(elem, this);
			pageTracker._trackPageview('/notice_board/' + this.getPrevious('h5').get('text') + '/more');
		});
		if (location.hash) {
			var elem = $('n_' + location.hash.replace("#", ""));
			LM.Index.MorphOut(elem.getPrevious(), elem);
		}
	},
	MorphOut: function(elem, link) {
		$$('.noticeLink').each(function(item) {
			var elem = item.getPrevious();
			if (elem.getHeight() != 58)
				LM.Index.MorphIn(elem, item);
		})
		var eff = new Fx.Morph(elem, { duration: elem.scrollHeight * 3, transition: Fx.Transitions.Quad.easeIn });
		eff.start({
			'height': elem.scrollHeight
		}).chain(function() {
			link.innerHTML = 'Close';
		});
		link.removeEvents('click');
		link.addEvent('click', function(e) {
			e.stop();
			LM.Index.MorphIn(elem, link);
		});
	},
	MorphIn: function(elem, link) {
		var eff = new Fx.Morph(elem, { duration: elem.scrollHeight * 2, transition: Fx.Transitions.Quad.easeIn });
		eff.start({
			'height': '58px'
		}).chain(function() {
			link.innerHTML = 'Read More';
		});
		link.removeEvents('click');
		link.addEvent('click', function(e) {
			e.stop();
			LM.Index.MorphOut(elem, link);
		});
	}
};
