function replaceLabel(){
	jQuery('#job').each(function(){
		jQuery('#job .textsearch .input-text').attr('value', '');
		
		jQuery('#job .textsearch .input-text').focus(function(){
			jQuery('#job .textsearch label').hide();
		});
		
		jQuery('#job .textsearch .input-text').blur(function(){
			if(jQuery('#job .textsearch .input-text').attr('value').length <= 0){
				jQuery('#job .textsearch label').show();
			}
		});
		
		jQuery('#job .textbox .input-text').attr('value', '');
		
		jQuery('#job .textbox .input-text').focus(function(){
			jQuery('#job .textbox  label').hide();
		});
		
		jQuery('#job .textbox .input-text').blur(function(){
			if(jQuery('#job .textbox .input-text').attr('value').length <= 0){
				jQuery('#job .textbox label').show();
			}
		});
	});

	jQuery('#contact').each(function(){
		jQuery('#contact .input-text').attr('value', '');
		
		jQuery('#contact .input-text').focus(function(){
			jQuery('#contact label').hide();
		});
		
		jQuery('#contact .input-text').blur(function(){
			if(jQuery('#contact .input-text').attr('value').length <= 0){
				jQuery('#contact label').show();
			}
		});
	});
}

/* Navigation fix */
function mouseOverHandler(element, classname, eventObject){
	var item = element;
	
	if(isParentedBy(item, eventObject.toElement)){
		jQuery(item).addClass(classname);
	}
}

function mouseOutHandler(element, classname, eventObject){
	var item = element;
	
	if(!isParentedBy(item, eventObject.toElement)){
		jQuery(item).removeClass(classname);
	}
}

function isParentedBy(matchElement, startElement){
	if(!matchElement)
		return false;
		
	if(!startElement)
		return false;
		
	if(startElement == matchElement){
		return true;
	}
	
	if(startElement.parentNode != null){
		return isParentedBy(matchElement, startElement.parentNode);
	}
	
	return false;
}

/* Rotator */
var elements = "";
var counter = 0;
var widthElement = -90;
var animateSpeed = 1000;
var timeForNext = 5000;
var timer = "";
var scrollClick = false;

function rotator(){
    elements = jQuery('#carrousel .linklistblock ul li');
    
    if (elements.length > 0){
        timer = setTimeout("moveRotator(false)", timeForNext);
    }
}

function turnIt(position){
    if (scrollClick == false){
        clearTimeout(timer);
		scrollClick = true;

        if (position == 1) {
            moveRotator(true);
        } else {
            moveBackRotator(true);
        }

        timer = setTimeout("moveRotator(false)", timeForNext);
        setTimeout(function() { scrollClick = false; }, 3000);
    }
}

function moveRotator(click){
    scrollClick = true;
    jQuery(elements[counter]).animate({ marginLeft: widthElement }, animateSpeed, function() {
        jQuery(elements[counter].parentNode).append(jQuery(elements[counter]));
        elements = jQuery('#carrousel .linklistblock ul li');
        jQuery(elements[elements.length - 1]).css('marginLeft', '0px');
        if (click == false){
            timer = setTimeout("moveRotator(false)", timeForNext);
        }
        scrollClick = false;
    });
}

function moveBackRotator(click){
    scrollClick = true;
    jQuery(elements[elements.length - 1]).css("marginLeft", widthElement + "px");
    jQuery(elements[counter].parentNode).prepend(jQuery(elements[elements.length - 1]));
    elements = jQuery('#carrousel .linklistblock ul li');

    jQuery(elements[counter]).animate({ marginLeft: '0px' }, animateSpeed, function() {
        if (click == false){
            timer=setTimeout("moveBackRotator(false)", timeForNext);
        }
        scrollClick = false;
    });
}

/* Image map */
function mouseOver(){
	jQuery('ul.map li.administratief').hover(function(){
		jQuery(this).css({'z-index' : '10'});
		jQuery(this).addClass('hover');
		jQuery(this).find('img').attr('src', '/29094').addClass("hover").stop()
		.animate({
			marginTop: '-192px',
			marginLeft: '-86px',
			bottom: '5%',
			left: '49%',
			width: '145px',
			height: '230px'
		}, 200);
	}, function(){
		jQuery(this).css({'z-index' : '0'});
		jQuery(this).removeClass('hover');
		if(jQuery.browser.msie){
			jQuery(this).find('img').attr('src', '/29100').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '5%',
				left: '0',
				width: '117px',
				height: '186px'
			}, 400);
		}
		else{
			jQuery(this).find('img').attr('src', '/29100').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '5%',
				left: '0%',
				width: '117px',
				height: '186px'
			}, 400);
		}
	});
	
	jQuery('ul.map li.callcenter').hover(function(){
		jQuery(this).css({'z-index' : '10'});
		jQuery(this).addClass('hover');
		jQuery(this).find('img').attr('src', '/29095').addClass("hover").stop()
		.animate({
			marginTop: '-192px',
			marginLeft: '-86px',
			bottom: '5%',
			left: '49%',
			width: '145px',
			height: '230px'
		}, 200);
	}, function(){
		jQuery(this).css({'z-index' : '0'});
		jQuery(this).removeClass('hover');
		if(jQuery.browser.msie){
			jQuery(this).find('img').attr('src', '/29101').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '5%',
				left: '0',
				width: '117px',
				height: '186px'
			}, 400);
		}
		else{
			jQuery(this).find('img').attr('src', '/29101').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '5%',
				left: '0%',
				width: '117px',
				height: '186px'
			}, 400);
		}
	});
	
	
	jQuery('ul.map li.productie').hover(function(){
		jQuery(this).css({'z-index' : '10'});
		jQuery(this).addClass('hover');
		jQuery(this).find('img').attr('src', '/29093').addClass("hover").stop()
		.animate({
			marginTop: '-192px',
			marginLeft: '-86px',
			bottom: '0%',
			left: '49%',
			width: '145px',
			height: '230px'
		}, 200);
	}, function(){
		jQuery(this).css({'z-index' : '0'});
		jQuery(this).removeClass('hover');
		
		if(jQuery.browser.msie){
			jQuery(this).find('img').attr('src', '/29099').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '0',
				left: '0',
				width: '117px',
				height: '186px'
			}, 400);
		}
		else{
			jQuery(this).find('img').attr('src', '/29099').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '0%',
				left: '0%',
				width: '117px',
				height: '186px'
			}, 400);
		}
	});
	
	jQuery('ul.map li.thuiszorg').hover(function(){
		jQuery(this).css({'z-index' : '10'});
		jQuery(this).addClass('hover');
		jQuery(this).find('img').attr('src', '/29092').addClass("hover").stop()
		.animate({
			marginTop: '-192px',
			marginLeft: '-86px',
			bottom: '0%',
			left: '49%',
			width: '145px',
			height: '230px'
		}, 200);
	}, function(){
		jQuery(this).css({'z-index' : '0'});
		jQuery(this).removeClass('hover');
		if(jQuery.browser.msie){
			jQuery(this).find('img').attr('src', '/29098').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '0%',
				left: '0',
				width: '117px',
				height: '186px'
			}, 400);
		}
		else{
			jQuery(this).find('img').attr('src', '/29098').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '0%',
				left: '0%',
				width: '117px',
				height: '186px'
			}, 400);
		}
	});
	
	jQuery('ul.map li.logistiek').hover(function(){
		jQuery(this).css({'z-index' : '10'});
		jQuery(this).addClass('hover');
		jQuery(this).find('img').attr('src', '/29096').addClass("hover").stop()
		.animate({
			marginTop: '-192px',
			marginLeft: '-86px',
			bottom: '10%',
			left: '49%',
			width: '145px',
			height: '230px'
		}, 200);
	}, function(){
		jQuery(this).css({'z-index' : '0'});
		jQuery(this).removeClass('hover');
		if(jQuery.browser.msie){
			jQuery(this).find('img').attr('src', '/29102').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '10%',
				left: '0',
				width: '117px',
				height: '186px'
			}, 400);
		}
		else{
			jQuery(this).find('img').attr('src', '/29102').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '10%',
				left: '0%',
				width: '117px',
				height: '186px'
			}, 400);
		}
	});
	
	jQuery('ul.map li.schoonmaak').hover(function(){
		jQuery(this).css({'z-index' : '10'});
		jQuery(this).addClass('hover');
		jQuery(this).find('img').attr('src', '/29097').addClass("hover").stop()
		.animate({
			marginTop: '-192px',
			marginLeft: '-86px',
			bottom: '10%',
			left: '49%',
			width: '145px',
			height: '230px'
		}, 200);
	}, function(){
		jQuery(this).css({'z-index' : '0'});
		jQuery(this).removeClass('hover');
		if(jQuery.browser.msie){
			jQuery(this).find('img').attr('src', '/29103').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '10%',
				left: '0',
				width: '117px',
				height: '186px'
			}, 400);
		}
		else{
			jQuery(this).find('img').attr('src', '/29103').removeClass("hover").stop()		
			.animate({
				marginTop: '0',
				marginLeft: '0',
				bottom: '10%',
				left: '0%',
				width: '117px',
				height: '186px'
			}, 400);		
		}
	});
}


/* De rest */
function makeButton(){
	jQuery('.print, .jobreactionblock a, .button-container input, .button-container a, .button-container ul li a, .categorybutton, .clearbasket a, .basketaddblock a, .button-container .button, .gallerygoback a, .mailafriendblock a').not(jQuery('.mailafriendblock  .preview a, .searchresultsblock ul li a, #header .button-container input, #article .searchblock .button-container input, #column .searchblock .button-container input')).each(function(){
		var button = this;
		if(button.type != 'hidden'){
		    jQuery(button).wrap('<span class="candywrapper"></span>');
		} else {
			jQuery(button).css('display','none');
		}
	});
}

function placeSpan(){
	jQuery("h1, h2, .displayjob .detailinfo li.companycity span.value").each(function(){
		var t = jQuery(this);
		var cufon = jQuery(".cufon canvas, .cufon cufoncanvas", t);
		cufon.wrap('<span class="wrapper"></span>')
	});
}

function insertLabel(){
	var s = jQuery('.fromzip_maxdist select option:eq(0)');
	s.text('Afstand');
}

function moveHeader(){
	jQuery('#references').each(function(){
		var t = jQuery(this);
		var head = jQuery('h2', t);
		var car = jQuery('#carrousel', t);
		
		if(head.length == 1){
			head.insertBefore(car);		
		}
		else{
			jQuery('#carrousel').addClass('noheader');
		}
	});
}

function hide(){
    if(jQuery('.mm_wysiwyg_container').length == 0) {
		jQuery('#references').each(function() {
			var t=this;
			
			var aantal = jQuery('.block-output', t).length;
			if(aantal==0) {
				jQuery(t).hide();
			}
		});
	} 
}

function checkArticle(){
    jQuery('.plain-text ul').each(function() {
        var list = this;
        if (jQuery('a', list).length > 0) {
            jQuery(list).addClass('linklist');
        }
    });
}

function changeFormButtons(){
	jQuery('.surveycontainer .button-container input').each(function(){
		var t = this;

		if(t.value == "Wissen"){
			jQuery('.button-container input[value="Wissen"]').parent().hide();
		}
	});
}

function addClass(){
	jQuery('#column').each(function(){
		var t = jQuery(this);
		var output = jQuery('.block-output', t);
		
		if(output.length == 2){
			jQuery('#column .block-output:first').addClass('firstChild');
			jQuery('#column .block-output:last').addClass('last');
		}
		else{
			jQuery('#column .block-output:first').addClass('first');
			jQuery('#column .block-output:last').addClass('last');		
		}
	});
}

var component = "";
var liElements = "";
var currentItem = 0;
var timer = "";
var speed = 5000; 

function getLinkListblock() {
	var blocks = jQuery('#column .block-output');
	if(blocks.length == 3) {
		if(blocks[1].className.indexOf('linklistblock')>0) {
			component = blocks[1];
			jQuery(component).removeClass('linklistblock').removeClass('navigationmodule').addClass('linkcarrouselblock');
			liElements = jQuery('li', component);
			initCarrousel();
			timer = setTimeout("moveAuto()",speed);
		}
	}
}

function initCarrousel() {
	if(liElements.length>1) {
		var bannerNav = jQuery('<div class="bannernav">');
		jQuery(component).append(bannerNav);

		for(var x = 0; x<liElements.length;x++)
		{
			if(x==0) {
				bannerNav.append('<div class="navitem navselected" onclick="moveTo(' + x + ')">');
			} else {
				bannerNav.append('<div class="navitem" onclick="moveTo(' + x + ')">');
			}
		}
	}
}

function moveTo(item) {
	clearTimeout(timer);
	if(item != currentItem) {
		jQuery(liElements[currentItem]).fadeOut();
		jQuery(liElements[item]).fadeIn();
		jQuery('.navselected').removeClass('navselected');
		jQuery(jQuery('.navitem')[item]).addClass('navselected');
		currentItem = item;
	}
	timer = setTimeout("moveAuto()",speed);
}

function moveAuto() {
	var item = currentItem;
	
	item++;
	if(item==liElements.length) {
		item=0;
	}
	
	moveTo(item);
}

function setSearchBlockZip() {
	if(jQuery('.searchblock .fromzip_maxdist').size() > 0){
		var href = window.location.href;
		
		if(href.indexOf('fromzip.maxdist') == -1)
		{
			var zipDistancesSelect = jQuery('.searchblock .fromzip_maxdist .input-select');
			if(zipDistancesSelect.val() == 0)
			{
				zipDistancesSelect.val('15');
			}
		}
	}
}

jQuery(document).ready(function(){
	mouseOver();
	checkArticle();
	makeButton();
	hide();
	changeFormButtons();
	getLinkListblock();
	setSearchBlockZip();
	jQuery('#menu .primary-nav>li').each(function(){
		var self = jQuery(this); 
		var width = jQuery('a', self).outerWidth()+ 8;
		if(self.hasClass('lc')){
			jQuery('span', self).css('left', width+3).width(229-width);
		}else{
			jQuery('span', self).css('left', width).width(229-width); 	
		}
	});
	
	jQuery('#job .dropdown:eq(1)').addClass('branche');
	
	jQuery('#menu .subitems').not(jQuery('#menu .subitems ul .subitems')).mouseenter(function(){
		if(jQuery(this).hasClass('fc')){
			jQuery(this).addClass('extrafchover');
		}
		else{
			jQuery(this).addClass('extrahover');
		}
	}).mouseleave(function(){
		if(jQuery(this).hasClass('fc')){
			jQuery(this).removeClass('extrafchover');
		}
		else{
			jQuery(this).removeClass('extrahover');
		}
	});
	
	jQuery(window).load(function(){
		jQuery('#pos').fadeIn(3000);
	});
});
