// Cufon Font Replacement
function cufonReplace() {
	Cufon.replace('#mainNav ul li a, h1, .workDetails h2 a, h2, .download_cv a, .twitterFeed p, .strapline p', { hover: true });
}


// Valid External Links
function externalLinks() { 
	$('a[rel^=external]').each(function() {
	$(this).attr('target', '_blank');
	});
};


// jQuery SmoothScroll | Version 09-11-02
function smoothScroll() {
$('a[href*=#]').click(function() {

   // duration in ms
   var duration=1000;

   // easing values: swing | linear
   var easing='swing';

   // get / set parameters
   var newHash=this.hash;
   var target=$(this.hash).offset().top;
   var oldLocation=window.location.href.replace(window.location.hash, '');
   var newLocation=this;

   // make sure it's the same location      
   if(oldLocation+newHash==newLocation)
   {
      // animate to target and set the hash to the window.location after the animation
      $('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {

         // add new hash to the browser location
         window.location.href=newLocation;
      });

      // cancel default click action
      return false;
   }

});
}



// Rollover effect, changes element's src attribute on hover:
function iconHover() {
    $('img[src*=icon]').hover(function() {
    	var src = $(this).attr("src").replace(".png", "_hover.png");
    	$(this).attr("src", src); 	
    }, function() {
  		var src = $(this).attr("src").replace("_hover.png", ".png");
    	$(this).attr("src", src); 	   
  });
}


// Apply Lightbox Dynamically
function applyLightbox() {
    $('.galleryHolder li a').attr("rel", "shadowbox[gallery]");
    $('.galleryHolder li.cloned a').attr("rel", "");
}

// Homepage Thumbnail Overlay, applies overlay on hover:
function thumbOverlay() {
    $('.homeWrapper .smallThumbWrap').hover(function() {
    	$(this).find('.hoverOverlay').fadeIn('fast');
    	href = $(this).find('a').attr("href");
		$(this).find('.hoverOverlay').click(
			function() {
    			window.location = href
    			return false;
			});
    }, function() {
  		$(this).find('.hoverOverlay').fadeOut('fast');		   
  });
}


$(document).ready(function() {
	cufonReplace();
	externalLinks();
	smoothScroll();
	iconHover();
	thumbOverlay();
	$('.anythingSlider').anythingSlider({});
	applyLightbox();
	Shadowbox.init();
});

