var section = [ 0, 0 ];

var Initialization = {
	functions : new Array(),
	addFunction : function(f) {
		Initialization.functions.unshift(f);
	},
	run : function() {
		while (Initialization.functions.length) {
			Initialization.functions.pop()();
		}
	}
};

window.onload = Initialization.run;

var defaultHeight = 20;
var defaultClass = 'container';

var menu = ['mHome','mWorks','mAbout','mContact'];
var active = false;

var mMove = new Movement(8, 'onmouseover', 'onmouseout');
var mFocus = new Movement(200, 'onfocus', 'onblur');
var nMove = false;

function rekFocus(sender, obj) {
	for (var i in sender.childNodes) {
		var child = sender.childNodes[i];
		
		if (child.href) {
			child.onfocus = function() { obj.onfocus(); };
			child.onblur = function() { obj.onblur(); };
		}
		else {
			rekFocus(child, obj);
		}
	}
}

function init () {
	var elem;
	var max;

	// set class for enabled JavaScript
	document.getElementsByTagName('body')[0].className = 'script';

	// configure manu tabs
	for (var i = 0; i < menu.length; i++) {
		elem = document.getElementById(menu[i]);
		if (!elem) {
			continue;
		}

		max = elem.clientHeight;
		menu[i] = new Movable(elem, 'height:px', defaultHeight, defaultHeight, max);

		if (elem.className.indexOf('active') < 0) {
			mMove.add(menu[i]);
			
			mFocus.add(menu[i]);
			rekFocus(elem, elem);
			
			elem.className = defaultClass;
		}
		else {
			menu[i].setValue(max);
		}
	}

	document.getElementsByTagName('body')[0].className = '';	/* only to reset ULs in Opera */
	active = section[0];
	
	// configure navigation tabs
	elem = [ document.getElementById('previous'), document.getElementById('next') ];
	
	if (elem[0] || elem[1]) {
		nMove = new Movement(32, 'onmouseover', 'onmouseout');
		
		if (elem[0]) {
			max = elem[0].clientWidth;
			nMove.add(new Movable(elem[0], 'left:px', -max, -max, 0));
		}

		if (elem[1]) {
			max = elem[1].clientWidth;
			nMove.add(new Movable(elem[1], 'right:px', -max, -max, 0));
		}
	}
}

Initialization.addFunction(init);