jQuery(window).ready(function($){
	
	jQuery(function($){
		$(".tweet").tweet({
			avatar_size: 0,
			username: "candelaconsult",
			count: 1,
			loading_text: "loading tweets...",
			refresh_interval: 60
		});
	});
		    
	$('#a').click(function() {
		$.smoothScroll({
			scrollTarget: '#about',
			speed:1500,
			offset:scroll
		});
  		return false;
	});
	$('#e').click(function() {
		$.smoothScroll({
			scrollTarget: '#expertise',
			speed:1500,
			offset:scroll
		});
  		return false;
	});
	
	$('#b').click(function() {
		$.smoothScroll({
			scrollTarget: '#blog',
			speed:1500,
			offset:scroll
		});
  		return false;
	});	    
	$('#tbh').click(function() {
		if($('#container').hasClass('single')){
			window.location.href = 'http://candelaconsultantsllc.com';
			}
		else{
		$.smoothScroll({
			scrollTarget: '#top',
			speed:1500,
			offset:scroll
		});
  		return false;
  		}
	});	    
	$('#tba').click(function() {
		$.smoothScroll({
			scrollTarget: '#about',
			speed:1500,
			offset:scroll
		});
  		return false;
	});
	$('#tbe').click(function() {
		$.smoothScroll({
			scrollTarget: '#expertise',
			speed:1500,
			offset:scroll
		});
  		return false;
	});
		    
	$('#tbb').click(function() {
		$.smoothScroll({
			scrollTarget: '#blog',
			speed:1500,
			offset:scroll
		});
  		return false;
	});
	$('#tbc').click(function() {
		$.smoothScroll({
			scrollTarget: '#footer',
			speed:1500,
			offset:scroll
		});
  		return false;
	});
	$('#pro').click(function() {
		$.smoothScroll({
			scrollTarget: '#prospect',
			speed:1500,
			offset:scroll+10
		});
  		return false;

	});
	$('#geo').click(function() {
		$.smoothScroll({
			scrollTarget: '#geology',
			speed:1500,
			offset:scroll+10
		});
  		return false;
	});
	$('#eco').click(function() {
		$.smoothScroll({
			scrollTarget: '#economic',
			speed:1500,
			offset:scroll+10
		});
  		return false;
	});

	function generateNoise(opacity) {
   if ( !!!document.createElement('canvas').getContext ) {
      return false;
   }

   var canvas = document.createElement("canvas"),
   ctx = canvas.getContext('2d'),
   x, y,
   r, g, b,
   opacity = opacity || .2;

   canvas.width = 100;
   canvas.height = 100;

   ctx = canvas.getContext("2d");

   for ( x = 0; x < canvas.width; x++ ) {
      for ( y = 0; y < canvas.height; y++ ) {
         r = Math.floor( Math.random() * 80 );
         g = Math.floor( Math.random() * 80 );
         b = Math.floor( Math.random() * 80 );

         ctx.fillStyle = "rgba(" + r + "," + g + "," + b + "," + opacity + ")";
         ctx.fillRect(x, y, 1, 1);
      }
   }
	$('.sub li').css('background-image', "url(" + canvas.toDataURL("image/png") + ")");
}

generateNoise(.1);
});
var locus;
var mediaInspector;
var scroll;
var zIndex;
$(window).load(function() {
	mediaInspector = document.getElementById('mediaInspector');
	adjust=parseInt($('#topBar').css('margin-top').replace("px", ""));
	locus =$('#topBar').offset().top;
	if (mediaInspector.currentStyle) {
  		  zIndex = mediaInspector.currentStyle['zIndex'];
 	} else if (window.getComputedStyle) {
 		   zIndex = window.getComputedStyle(mediaInspector, '').getPropertyValue("z-index");
	};
	if (zIndex==1){	
		scroll=-50;
		$(window).scroll(function() {
			if(locus-adjust >= $(window).scrollTop()) {
				if($('#topBar').hasClass('fixed')) {
					$('#topBar').removeClass('fixed');
					$('#topBar').addClass('absolute');
				}
			} else {
				if(!$('#topBar').hasClass('fixed')) {
					$('#topBar').removeClass('absolute');
					$('#topBar').addClass('fixed');
				}
			}
		});
	} else {
		scroll=-25;
	};
});
$(window).resize(function() {
	if($('#topBar').hasClass('fixed')) {
		$('#topBar').removeClass('fixed');
		$('#topBar').addClass('absolute');
	}
 	locus =$('#topBar').offset().top;
	if (mediaInspector.currentStyle) {
  		  zIndex = mediaInspector.currentStyle['zIndex'];
 	} else if (window.getComputedStyle) {
 		   zIndex = window.getComputedStyle(mediaInspector, '').getPropertyValue("z-index");
	};
 	if (zIndex==1){
 		scroll=-50;
 	} else {
 		scroll=-25;
 	};
});
