

jQuery(document).ready(function() {

	 $('#slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		pause:   1,      // true to enable "pause on hover"
		timeout: 8000
	});

	$('#apply').click(function() {
		$('.entry-content').hide();
		$('#application, #backRole').show();	  
	  $(this).hide();
	  return false;
});
	 $('#backRole').click(function() {
		$('#application').hide();
		$('.entry-content, #apply').show();			  
	  $(this).hide();
	  return false;
});

$('.wpcf7-file').attr('size', 25);

if (!Modernizr.input.placeholder) {
	// adds a placeholder text if the browser doesnt support it
	$("input[placeholder]").each(
	   function () {
			   var term = $(this).attr("placeholder");
			$(this).val(term); 
	   }).focus(
	   function() { 
			$(this).val(""); 
	   }).blur( 
			   function(){ 
				if (this.value == '') { 
					var term = $(this).attr("placeholder");
					$(this).val(term); 
				};     
	   });
}
	   // removes all alt tags from images
	   $('img').removeAttr('alt').removeAttr('title');
	   
	   
	// on search jobs form changes the visibility of the salary boxes depending on the job type
	// hide the contact select box
	$('#contractSalaryList').hide();
	$('#contractSalaryList').attr("disabled", "disabled");
	$('#permanentSalaryList').show();
	$('#permanentSalaryList').removeAttr("disabled");
	
	$('#jobtype').change(function(){
		if ($(this).val() == "contract")
		{
			// display the contact salary options
			$('#contractSalaryList').show();
			$('#contractSalaryList').removeAttr("disabled");
			
			$('#permanentSalaryList').hide();
			$('#permanentSalaryList').attr("disabled", "disabled");
		}
		else {
			// display the permanent salary options
			$('#permanentSalaryList').show();
			$('#permanentSalaryList').removeAttr("disabled");
			
			$('#contractSalaryList').hide();
			$('#contractSalaryList').attr("disabled", "disabled");
		}
	
	});
	
	$('#searchsubmit').click(function(){
	
		$("input[placeholder]").each(
	   function () {
			var term = $(this).attr("placeholder");
			if($(this).val() == term){
				$(this).val('');
			}
	   })
	
		/*var isValidTerm = false;
		
		if ($("#s2").val() != "")
		{
			isValidTerm = true;
		}
		
		if($("#s2").val() != $("#s2").attr("placeholder")){
			isValidTerm = true;
		}
		else {
			isValidTerm = false;
		}
		
		
		
	
		
		if(isValidTerm)
		{*/
			$("#searchform-advanced").submit();
		/*	$('#errorMsg').hide();
		}
		else {
			$('#errorMsg').html("Please enter a keyword");
			$('#errorMsg').show();
		}*/
		
	});
		
	   

	
});

// On window load. This waits until images have loaded which is essential
	$(window).load(function(){

		
		// Fade in images so there isn't a color "pop" document load and then on window load
		$(".canvas .clientLinkContain img").show();
		
		// clone image
		$('.canvas .desaturate img').each(function(){
			var el = $(this);
			el.css({"position":"absolute"}).wrap("<div class='img_wrapper' style='display: inline-block'>").clone().addClass('img_grayscale').css({"position":"absolute","z-index":"998","opacity":"0"}).insertBefore(el).queue(function(){
				var el = $(this);
				el.parent().css({"width":this.width,"height":this.height});
				el.dequeue();
			});
			this.src = grayscale2(this.src);
			
		});
		
		// Fade image 
		$('.canvas .desaturate img').mouseover(function(){
			$(this).parent().find('img:first').stop().animate({opacity:1}, 400);
		})
		$('.canvas .desaturate img').mouseout(function(){
			$(this).stop().animate({opacity:0}, 400);
		});	

			
		
	});
	
	// Grayscale w canvas method
	function grayscale2(src){
		var canvas = document.createElement('canvas');
		var ctx = canvas.getContext('2d');
		var imgObj = new Image();
		imgObj.src = src;
		canvas.width = imgObj.width;
		canvas.height = imgObj.height; 
		ctx.drawImage(imgObj, 0, 0); 
		var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
		for(var y = 0; y < imgPixels.height; y++){
			for(var x = 0; x < imgPixels.width; x++){
				var i = (y * 4) * imgPixels.width + x * 4;
				var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 4;
				imgPixels.data[i] = avg; 
				imgPixels.data[i + 1] = avg; 
				imgPixels.data[i + 2] = avg;
			}
		}
		ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
		return canvas.toDataURL();
    }
	
	
