var Biotekforum = { };

Biotekforum.equalizeHeight = function(elements) {
	var maxHeight = 0;
	elements.each(function(e) {
		if (e.getHeight() > maxHeight)
			maxHeight = e.getHeight();
	}).each(function(e) {
		if (e.setStyle) e.setStyle({ height : maxHeight + 'px'});
	});
}

/* dette funker ikke spesielt bra med den flytende høyrespalten i .full-articledisplay,
 * så jeg har tatt den bort foreløpig...
 */
if (false) {	
	Element.observe(window, 'load', function() {
		var toEqualize = $$('#placeholder-left:not(.frontpage) .tile-content, ' +
		                    '#placeholder-content:not(.frontpage) .tile-content');
		if (toEqualize) {
			Biotekforum.equalizeHeight(toEqualize);
			var menu = $$('#placeholder-left:not(.frontpage) .tile-content');
			var ADDITIONAL_HEIGHT = Prototype.Browser.IE ? 35 : 50;
			if (menu) menu = menu[0];
			menu.setStyle({ height: menu.getHeight() + ADDITIONAL_HEIGHT + 'px'})
		}
		
	})
}

Biotekforum.SCROLL_VELOCITY = 0.08;
Biotekforum.scrollTimer = null;

Biotekforum.scrollElement = function(element) {
	var top = element.positionedOffset().top;
	if (Math.abs(top)  > element.up().getHeight() + 40)
		top = 1;
		
	element.setStyle({ 'top' : top - 1  + 'px' });
}

Biotekforum.startScrolling = function(element) {
	Biotekforum.scrollTimer = new PeriodicalExecuter(function(pe) {
		Biotekforum.scrollElement(element)
	}, Biotekforum.SCROLL_VELOCITY);
}

Biotekforum.endScrolling = function() {
	Biotekforum.scrollTimer.stop();
}

Biotekforum.initializeScroller = function(element) {
	element.makePositioned();
	var container = element.up();
	
	container.observe('mouseover', function(e) {	
		Biotekforum.endScrolling();
	}).observe('mouseout', function(e) {
		Biotekforum.startScrolling(element);
	});
	
	Biotekforum.startScrolling(element);
}

Biotekforum.addInputObservers = function(element) {
	if (!element.value)
		return;
	
	var initialValue = element.value;
		
	element.observe('focus', function(e) {
		if (element.value == initialValue) {
			element.value = '';
		}		
	}).observe('blur', function(e) {
		if (!element.value)
			element.value = initialValue;
	});
}
	
Element.observe(window, 'load', function(e) {

	$$('.small-rsslist ul').each(Biotekforum.initializeScroller);
//	$$('.suggestionform input[type="text"], .suggestionform textarea').each(Biotekforum.addInputObservers);
});