// content - submenulayers
Event.observe(window,'load',function(e) {
	menuitems = $$('div.menuitem');
	for(i = 0; i < menuitems.length; i++) {
		var item_a = menuitems[i].down('span');
		Event.observe(item_a,'click',function(e) {
			if(submenudiv = this.next('div.submenu')) {
				if(!this.up(0).hasClassName('menuitem_current')) {
					var down = new Effect.BlindDown(submenudiv,{duration:0.3,afterFinish:stretchElements});
					this.up(0).addClassName('menuitem_current');
				} else {
					var up = new Effect.BlindUp(submenudiv,{duration:0.3});
					this.up(0).removeClassName('menuitem_current');
				}
			}
			return false;
		});
	}
});

// stretch elements to get 100% behaviour
function stretchElements() {
	$$('.stretch').each(function(elem) {
		try {
			var fix_matches = elem.className.match(/fix-([-0-9]+)/);
			var height_fix = parseInt(fix_matches[1]);
		} catch(e) {
			var height_fix = 0;
		}
		var sibcumheight = 0;
		elem.siblings().each(function(s) {
			sibcumheight += s.getHeight();
		});
		var fitheight = $(elem.parentNode).getHeight() - sibcumheight + height_fix;
		elem.style.height = fitheight + 'px';
	});	
}
Event.observe(window,'load',stretchElements);

// preloading
var preloadImages = Array();
function preloader(w,h,name) {
	if(typeof document.preloadImages == 'undefined') {
		document.preloadImages = Array();
	}
	nr = document.preloadImages.length;
	document.preloadImages[nr] = new Image(w,h);
	document.preloadImages[nr].src = name;
}