/**
 * @author Administrator
 */
window.addEvent('domready', function() {
	fixOpacity();
	setupNavigation();
	setupDimensions();
	replaceHeaders();
	setupInputFields();
});
window.addEvent('resize', function() {
	setupDimensions();
});

/* fix opacity */
fixOpacity = function() {
	var objects = [{id:'menuOpacity',opacity:'0.2'}];
	objects.each( function(ob) {
		if($(ob.id)) $(ob.id).setStyle('opacity',ob.opacity);
	});
}

/* dimensions */
setupDimensions = function() {
	var graphic = $('graphicContainer');
	var content = $('contentContainer');
	var contentleft = $('contentLeft');
	var contentright = $('contentRight');
	var footer = $('footerContainer');
	
	var winpos = window.getSize();
	var totalheight = ((winpos.y - graphic.getCoordinates().height) - footer.getCoordinates().height);

	var leftcolumn = contentleft.getCoordinates().height + contentleft.getStyle('margin-top').toInt() + contentleft.getStyle('margin-bottom').toInt();	
	var rightcolumn = contentright.getCoordinates().height + contentright.getStyle('margin-top').toInt() + contentright.getStyle('margin-bottom').toInt();
	
	var highestcolumn = (leftcolumn > rightcolumn?leftcolumn:rightcolumn) + 25;
	if(totalheight>highestcolumn) {
		var newheight = totalheight;
	} else {
		var newheight = highestcolumn;
	}
	content.setStyles({height: newheight+'px'});
}


/* navigatie */
setupNavigation = function() {
	var navigation = $('navigation');
	navigation.getChildren('li[class!=logo]').each( function(el) {
		el.addEvents({
			mouseenter: function(){
				this.addClass('hover');
				if (this.getNext()) 
					this.getNext().addClass('hovernext');
				$('navigation').getChildren('li[class!=logo]').each(function(el){
					if (!el.hasClass('hover')) 
						el.setStyles({
							opacity: '0.5'
						});
				});
			},
			mouseleave: function(){
				optimer = new Array();
				$('navigation').getChildren('li[class!=logo]').each(function(el){
					if (!el.hasClass('hover')) 
						el.setStyles({
							opacity: '1'
						});
				});
				if (this.getNext()) 
					this.getNext().removeClass('hovernext');
				this.removeClass('hover');
				
			}
		});
		el.getElements('ul').each( function(ul) {
			ul.getElements('li').each( function(li) {
				var div = new Element('div').setStyle('opacity','0.8');
				if (li.getElement('a')) {
					div.injectBefore(li.getElement('a'));
				} else {
					div.injectInside(li);
				}
			});
		});
		if(typeof(last)!='undefined') delete(last);
	});
	/* place last class */
	navigation.getChildren('li').each( function(el ) {
		if(!el.getNext('li')) {
			el.addClass('last');
		}
		checkForSubLast(el);
	});
}
checkForSubLast = function(obj) {
	var ul = obj.getElements('ul');
	if(ul.length>0) {
		ul.each( function (el) {
			var li = el.getChildren('li');
			li.each( function(ei) {
				if(!ei.getNext('li')) {
					ei.addClass('last');
				}
				checkForSubLast(ei);
			});
		});
	}
}
replaceHeaders = function() {
	$$('div#textContainer h1',
		'div#textContainer h2',
		'div#textContainer h3',
		'div#textContainer h4',
		'div#textContainer h5',
		'div#textContainer h6').each( function(el,i) {
		var div = new Element('div').addClass('header_'+el.get('tag'));
		div.injectAfter(el);
		el.injectInside(div);
		el.set('id','header'+i);
		var height = 0;
		switch(el.get('tag')) {
			case 'h1': height = 50; break;
			case 'h2': height = 25; break;
			case 'h3': height = 35; break;
			case 'h4': height = 20; break;
			case 'h5': height = 25; break;
			case 'h6': height = 20; break;
		}
		new Swiff('/img/swf/' + el.get('tag') + '.swf', {
		    id: 'header'+i,
		    width: 450,
		    height: height,
		    params: {
		        wmode: 'transparent'
		    },
		    vars: {
		        color: el.get('rel'),
		        txt: el.get('html')
		    }
		}).replaces(el);
		

	});
}
setupInputFields = function() {
	var objects = [{id: 'input', value:'zoekfunctie'}];
	objects.each( function(obj) {
		if($(obj.id)) {
			$(obj.id).set('rel',obj.value);
			$(obj.id).addEvents({focus: function() {
				if(this.get('value')==this.get('rel')) this.set('value','');		
			}});
			if($(obj.id).get('value')=='') $(obj.id).set('value',obj.value);
		}
	});
}

