var subjectsBlock = {

	currentHeight : 0,      // current list height
	addHeight     : 0,
	maxHeight     : 0,
	show      	  : false, // new state

	clickEvent: function(e) {

		if ((eId('subjectsExpanded').getElementsByTagName('li').length <= 0)
				|| (subjectsBlock.addHeight != 0)) {
			return;
		}

		var action = pDomApi.hasClassName(eId('subjectsExpanded'), 'collapse')
							? 'expand' : 'collapse';
		var replace = (action == 'expand') ? 'collapse' : 'expand';

		pDomApi.setClassName( eId('subjectsExpanded'), action, replace);

		subjectsBlock.showHide = (action == 'expand') ? true : false;

		subjectsBlock.animate(action);
	},

	animate: function(action) {

		var element = eId('subjectsExpanded');

		if (action == 'expand') {
			this.currentHeight = 0;
			var elements = element.getElementsByTagName('li');

			this.maxHeight = elements.length * 17;
			this.addHeight = 16;
			element.style.height = '0px';
		} else {
			this.addHeight = -16;
		}
		setTimeout(subjectsBlock.scroll, 250);
	},

	scroll: function() {

		var element = eId('subjectsExpanded');
		var height = parseInt(element.style.height.replace('px',''));

		height = height + subjectsBlock.addHeight;
		if (height < 0) {
			height = 0;
		}

		element.style.height = height + 'px';
		if ((height <= subjectsBlock.maxHeight) && (height > 0)) {
			setTimeout(subjectsBlock.scroll, 1);
			return;
		}

		subjectsBlock.addHeight = 0;
		subjectsBlock.switchButtons();
	},

	switchButtons: function() {

		var show = subjectsBlock.show ? 'hide' : 'show';
		var hide = subjectsBlock.show ? 'show' : 'hide';

		pDomApi.showHide( eId('btnCollapseSubjects'), hide, show);
		pDomApi.showHide( eId('btnExpandSubjects'), hide, show);
	}
}

pDomApi.addEvent(window, 'domload', function() {

	if ( eId('subjectsBlock')) {
		pDomApi.addEvent( eId('btnSubjectsExpand'), 'click', subjectsBlock.clickEvent);
	}

});