//Dave.
//Site by Matt Coleman for Drexler (drxlr.com)

jQuery(function ($) {
		
	//Fades
	$('h1 a').hover( function() {
		$(this).fadeTo(100, .5);
		}, function() {
		$(this).fadeTo(200, 1);			
		});

	//Prevent Image Tooltips from showing
		$('.recent-work li img').attr('title','');
		$('.recent-work li img').children().attr('title','');

	//Fades
	$('.recent-work a').hover( function() {
		$(this).find('img').fadeTo(100, .5);
		$(this).find('span').show().fadeTo(100, 1);
		}, function() {
		$(this).find('img').fadeTo(200, 1);			
		$(this).find('span').fadeTo(200, 0).hide();		
		});
	
	$('.share').hover( function() {
		$(this).find('ul').slideToggle(100);
		}, function() {
		$(this).find('ul').slideToggle(200);			
		});
	
	//Fade in Homepage Images in Order -------------------------------------------------------------------
	function randsort(c) {
			var o = new Array();
			for (var i = 0; i < c; i++) {
				var n = Math.floor(Math.random()*c);
				if( jQuery.inArray(n, o) > 0 ) --i;
				else o.push(n);
			}
			return o;
		}
 
		var e = $('.recent-work li');
		var c = e.size();
		var r = randsort(c);
		 
		$('.recent-work li').each(function(i) {
			var e = $(this);
			e.fadeTo(0, 0);
			setTimeout(function(){
				e.fadeTo(400, 1);
			}, [i]*100);
		});	
		
		//Hide Recent Label on Scroll
		$(window).scroll( function() {
		    if($(this).scrollTop() > 40) {
		        $('.recent-label').fadeOut(200);
		    } else {
		        $('.recent-label').fadeIn(200);
		    }
		});	
	
	
		//Work Filtering -------------------------------------------------------------------
   		
   		//$(function() {
		//	var newSelection = "";
		//		$("#filter a").click(function(){
		//		    $(".work li").fadeTo(100, 1);
		//			$("#filter a").removeClass("current");
		//			$(this).addClass("current");
		//			newSelection = $(this).attr("rel");
		//			$(".work li").not('.'+newSelection).fadeTo(100, 0.1);
					//$(".work li").is('.'+newSelection).fadeTo(100, 1);
					//Let em know something happened
				    //$(".work li'.'+newSelection").fadeTo(200, 1)
				    //return false;
		//		});
			
		//	});


	//To Top Functions -------------------------------------------------------------------

	$('.top').hide();

	$(window).scroll( function() {
		var windowTop = $(window).scrollTop();
	    if($(this).scrollTop() > 500) {
	        $('.top').fadeIn(400);
	        $('.top').css({ 'bottom' : '200px' , 'position' : 'fixed' });
	    } else {
	        $('.top').fadeOut(150);
	    }
	});
		
	function filterPath(string) {
		  return string
		    .replace(/^\//,'')
		    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
		    .replace(/\/$/,'');
		  }
		 
		  var locationPath = filterPath(location.pathname);
		  $('a[href*=#]').each(function() {
		    var thisPath = filterPath(this.pathname) || locationPath;
		    if (  locationPath == thisPath
		    && (location.hostname == this.hostname || !this.hostname)
		    && this.hash.replace(/#/,'') ) {
		      var $target = $(this.hash), target = this.hash;
		      if (target) {
		        var targetOffset = $target.offset().top;
		        $(this).click(function(event) {
		          event.preventDefault();
		          $('html, body').animate({scrollTop: targetOffset}, 600, function() {
		            location.hash = target;
		          });
		        });
		      }
		    }
		  }); 



//And...done.

});
