function replaceLabel(){
	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();
			}
		});
	});
	
	jQuery('#right').each(function(){
		jQuery('#right .textbox .input-text').attr('value', '');
		
		jQuery('#right .textbox .input-text').focus(function(){
			jQuery('#right .textbox label').hide();
		});
		
		jQuery('#right .textbox  .input-text').blur(function(){
			if(jQuery('#right .textbox .input-text').attr('value').length <= 0){
				jQuery('#right .textbox label').show();
			}
		});
	});
}

function replaceRightLabel(){
	jQuery('#right').each(function(){
	
		if(jQuery('#right .textsearch .input-text').size() > 0 && jQuery('#right .textsearch .input-text').attr('value').length != 0){
			jQuery('#right .textsearch label').hide();

			jQuery('#right .textsearch .input-text').focus(function(){
				jQuery('#right .textsearch label').hide();
			});
			
			jQuery('#right .textsearch .input-text').blur(function(){
				if(jQuery('#right .textsearch .input-text').attr('value').length <= 0){
					jQuery('#right .textsearch label').show();
				}
			});
		}
		else{
			jQuery('#right .textsearch .input-text').attr('value', '');
			
			jQuery('#right .textsearch .input-text').focus(function(){
				jQuery('#right .textsearch label').hide();
			});
			
			jQuery('#right .textsearch .input-text').blur(function(){
				if(jQuery('#right .textsearch .input-text').attr('value').length <= 0){
					jQuery('#right .textsearch 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;
}

/* 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, #right .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 changeJoblist(){
    jQuery('.AdvancedJobBoardModule  .radiobutton, .AdvancedJobBoardModule  .checkbox').not(jQuery('.jobreactionblock .radiobutton')).each(function() {
        var t = this;
        var newDiv = jQuery('<div>');
        var children = t.childNodes;
        var fields = new Array;
        var labels = new Array;
        var labelnr = 0;
        
        for (var x=0;x<children.length;x++){
        
            if(children[x].tagName=="LABEL"){
                labelnr++;
                var label1 = children[x];
            }

            if (children[x].tagName=="LABEL" & labelnr>1){
                fields[x] = children[x];
                labels[x] = 'label';
            }
            
            if (children[x].tagName=="INPUT" ){
                fields[x] = children[x];
            }
        }
        
        jQuery(label1).after(jQuery(newDiv));
        
        for (var y=1;y<fields.length;y++){
            if(fields[y]){
                jQuery(newDiv).append(jQuery(fields[y]));
            }
            if(labels[y]=='label'){    
                jQuery(fields[y]).after(jQuery('<br/>'));
            }
        } 
    });
}

function changeForm(){
	jQuery('.surveycontainer .q_multipleresponse').each(
		function(){
			var t = this;
			var newDiv = jQuery('<div class="checkboxes">');
			var spanText = jQuery('.question-text',t);
			var getTables = jQuery('table',t);
			var getSelect = jQuery('select',t);
			var breakIt  = jQuery('br',t);             
			var element = new Array;
			var type = new Array;
			var aantalChilds;
			
			if ((getTables.length+getSelect.length)==0){
				breakIt.remove();
				aantalChilds = t.childNodes.length;
				
				for (var x = 0; x<aantalChilds;x++){
					if (t.childNodes[x].tagName=='INPUT'){    
						element[x] = t.childNodes[x];
						type[x] = t.childNodes[x].tagName;
					}
					
					if (t.childNodes[x].tagName=="LABEL"){
						element[x] = t.childNodes[x];
						type[x] = t.childNodes[x].tagName;
					}
				}
				
				for (var x = 0; x<aantalChilds;x++){
					if(element[x] =='object');                        {
						newDiv.append(element[x]);
					}
					if(type[x] == 'LABEL'){
						newDiv.append(jQuery('<br>'));
					}
				}
					
				spanText.after(newDiv);
			}
		}
	);
}

function titleSize(){
	if(navigator.appName == 'Netscape'){
		jQuery('.citywrapper').each(function(){
			var t = jQuery(this);
			var string = jQuery('span.value', t).text();
			if(string.length > 15){
				jQuery('span.value', t).text(string.substr(0, 15) + '...');
			}
		});
	}
}

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('.Regions select option:eq(0), .CompanyRegions select option:eq(0)');
	s.text('Regio');
	
	var t = jQuery('.branche select option:eq(0)');
	t.text('Vakgebied');
}

function moveArticleHeader(){
	jQuery('.articlelistblock li').each(function(){
		if(jQuery('.articlelist_thumbnail').length > 1){
			var li = jQuery(this).addClass('top');
			var h3 = jQuery('h3', li);
			var thumb = jQuery('.articlelist_thumbnail', li);
			h3.after(thumb);
		}
	});
}

function setZIndex() {
    jQuery('#menu').each(function(){
        var block = this;   
        var listItems = jQuery('ul li', block).not(jQuery('ul li ul li'));
        var counter = listItems.length;
        
        for(var x = 0;x < listItems.length;x++) {
            jQuery(listItems[x]).css('z-index',counter);
			counter++
        }
    });
}

function jobAgent(){
	jQuery('#middle').each(function(){
		var Agent = jQuery('.mailagentblock', this);
		var Detail = jQuery('.searchresultsblock', this);
		Detail.prepend(Agent);
	});
}

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 moveHeader(){
	jQuery('#middle').each(function(){
		var t = jQuery(this);
		var head = jQuery('h2', t);
		
		if(head.length == 0){
			jQuery('#middle .searchresultsblock').addClass('noheader');
		}
	});
}

function activateFormElements() {
	if(jQuery('.zipsearchblock .distanceselect').size() > 0){
		var href = window.location.href;
		
		if(href.indexOf('.distanceselect') == -1)
		{
			var zipDistancesSelect = jQuery('.zipsearchblock .distanceselect');
			if(zipDistancesSelect.val() == 0)
			{
				zipDistancesSelect.val('15');
			}
		}
	}
	if(jQuery('.searchblock .fromzip_maxdist').size() > 0){
		var href = window.location.href;
		
		if(href.indexOf('.fromzip_maxdist') == -1)
		{
			var zipDistancesSelect = jQuery('.fromzip_maxdist .input-select');
			if(zipDistancesSelect.val() == 0)
			{
				zipDistancesSelect.val('15');
			}
		}
	}
}

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(){
	jQuery('#menu .primary-nav>li').each(function(){
		var self = jQuery(this); 
		var width = jQuery('a', self).outerWidth()+8;
		jQuery('span', self).css('left', width).width(229-width); 	
	});
	
	setTimeout( function() {
	jQuery('.tweet_list li').mouseenter(function(){
		jQuery(this).addClass('tweet_grey');
	});
	
	jQuery('.tweet_list li').mouseleave(function(){
		jQuery(this).removeClass('tweet_grey');
	});
}, 1000);

	checkArticle();
	makeButton();
	changeForm();
	changeJoblist();
	titleSize();
	changeFormButtons();
	setZIndex();
	moveHeader();
	setSearchBlockZip();
	activateFormElements();
	jQuery('#menu .subitems').not(jQuery('#menu li.subitems ul li.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');
		}
	});
			
	var sollComp = jQuery('.jobreactionblock');
	if(sollComp.length>0) {
		if(jQuery('.button-container', sollComp).length==0) {
			jQuery('.displayjob').addClass('displayjobdisabled');
		}
	}
	
	jQuery('#menu ul>li:eq(1)').addClass('blue');
	// jQuery('h1, h2').not(jQuery('#footer h2')).each(function(){Cufon.replace(this, {fontFamily: 'TheSansBold-Plain'});});
	// jQuery('#menu ul li a').not(jQuery('#menu ul li li a')).each(function(){Cufon.replace(this,{fontFamily: 'TheSansBold-Plain', hover: true});});
	// jQuery('#header .linkblock .linkbutton').each(function(){ Cufon.replace(this,{fontFamily: 'TheSans', hover: true});});
	// jQuery('.plain-text h4').each(function(){ Cufon.replace(this,{fontFamily: 'TheSans', hover: true});});
	// placeSpan();
});

