	    

$(document).ready(function() {
	
	// Expand Panel
	$("#open").click(function(){
		$("div#panelContact").slideDown("slow");
	
	});	
	
	
	// use close button to close 
	
	$("#close").click(function(){
		$("div#panelContact").slideUp("slow");	
	});	
		

	// hide #back-top first
	$("#back-top").hide();
	
	// fade in #back-top
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#back-top').fadeIn();
			} else {
				$('#back-top').fadeOut();
			}
		});

		// scroll body to 0px on click
		$('#back-top a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
		
		// scroll body to services on click
		$('#services a').click(function () {
			$('body,html').animate({
				scrollTop: 700
			}, 800);
			return false;
		});
		
		// scroll body to contact on click
		$('#contact a').click(function () {
			$('body,html').animate({
				scrollTop: 20000
			}, 800);
			return false;
		});
		
		// scroll body to work on click
		$('#work a').click(function () {
			$('body,html').animate({
				scrollTop: 1000
			}, 800);
			return false;
		});
		
	
	});
	
			$('.jsixrollover').hover(function(){
				$(this).find('img').fadeTo("slow", 0.2);
				$(this).find('p').animate({top:'20px'},{queue:true,duration:500});
			}, function(){
				$(this).find('img').fadeTo("slow", 1);
				$(this).find('p').animate({top:'-140px'},{queue:false,duration:500});
			});
		
		
		
});

// 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
		$(".workImg img").fadeIn(500);
		
		// clone image
		$('.workImg 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 = grayscale(this.src);
		});
		
		// Fade image 
		$('.workImg img').mouseover(function(){
			$(this).parent().find('img:first').stop().animate({opacity:1}, 1000);
		})
		$('.img_grayscale').mouseout(function(){
			$(this).stop().animate({opacity:0}, 1000);
		});		
	});
	
	// Grayscale w canvas method
	function grayscale(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]) / 3;
				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();
    }

