//Slider

$(window).load(function() {
    $('#slider').nivoSlider({ 
    pauseTime:4000, 
    pauseOnHover:false, 
    });
});

$(document).ready(function(){

//Navigation

	if(location.pathname != "/") {
			$('#navigation a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
		} else $('#navigation a:eq(4)').addClass('active');
	
    $("#navigation a.active").stop().hover(function() {
    	$(this).stop().animate({ color: "#fff" }, 300);
    },function() {
   		$(this).animate({ color: "#fff" }, 300);
    });
    
    $("#navigation a:not(.active)").stop().hover(function() {
    	$(this).stop().animate({ color: "#938c89"}, 300);
    },function() {
    		$(this).animate({ color: "#615b58"}, 300);
    });
    
//    $("#who-am-i a, #latest-blog-posts a").stop().hover(function() {
//    	$(this).stop().animate({ color: "#ff9b00" }, 300);
//    },function() {
//    		$(this).animate({ color: "#7aa6b9" }, 300);
//    });
    
//    $(".portfolio-item a").stop().hover(function() {
//    	$(this).stop().animate({ color: "#fa7c00" }, 300);
//    },function() {
//    		$(this).animate({ color: "#55b3c7" }, 300);
//    });
   
   //Tooltips
       $(".tip_trigger").hover(function(){
           tip = $(this).find('.tip');
           tip.show(); //Show tooltip
       }, function() {
           tip.hide(); //Hide tooltip
       }).mousemove(function(e) {
           var mousex = e.pageX + 10; //Get X coodrinates
           var mousey = e.pageY - 40; //Get Y coordinates
           var tipWidth = tip.width(); //Find width of tooltip
           var tipHeight = tip.height(); //Find height of tooltip
   
           //Distance of element from the right edge of viewport
           var tipVisX = $(window).width() - (mousex + tipWidth);
           //Distance of element from the bottom of viewport
           var tipVisY = $(window).height() - (mousey + tipHeight);
   
           if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
               mousex = e.pageX - tipWidth - 20;
           } if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
               mousey = e.pageY - tipHeight - 20;
           }
           //Absolute position the tooltip according to mouse position
           tip.css({  top: mousey, left: mousex });
       });
       
//Tweet!
    
    $(".tweet").tweet({
                username: "DavidMortimer88",
                join_text: "auto",
                count: 3,
                auto_join_text_default: "", 
                auto_join_text_ed: "",
                auto_join_text_ing: "",
                auto_join_text_reply: "",
                auto_join_text_url: "",
                loading_text: "loading tweets..."
     });
     
//FancyBox
     
     $("a.single_image").fancybox({
     	'opacity'		:   true,
     	'transitionIn'	:	'elastic',
     	'transitionOut'	:	'elastic',
     });
     
     $("a.alienvideo").fancybox({
     		'opacity'		:   true,
     		'padding'	    :	'0',
     		'transitionIn'	:	'elastic',
     		'transitionOut'	:	'elastic',
     		'width'			: 700,
     		'height'		: 525,
     		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=10261439',
     		'type'			: 'swf',
     });		
     
     $("a.ww2video").fancybox({
     		'opacity'		:   true,
     		'padding'	    :	'0',
     		'transitionIn'	:	'elastic',
     		'transitionOut'	:	'elastic',
     		'width'			: 700,
     		'height'		: 394,
     		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=10258335',
     		'type'			: 'swf',
     		'overlayColor'  : '#262626',
     });	
     
     $("a.showreel").fancybox({
     		'opacity'		:   true,
     		'padding'	    :	'0',
     		'transitionIn'	:	'elastic',
     		'transitionOut'	:	'elastic',
     		'width'			: 700,
     		'height'		: 394,
     		'href'			: 'http://vimeo.com/moogaloop.swf?clip_id=10257173',
     		'type'			: 'swf',
     		'overlayColor'  : '#262626',
     });
     
     $("a.darts").fancybox({
     		'opacity'		:   true,
     		'padding'	    :	'0',
     		'transitionIn'	:	'elastic',
     		'transitionOut'	:	'elastic',
     		'width'			: 895,
     		'height'		: 550,
     		'href'			: 'http://www.davidmortimer.org.uk/darts/Content/DartsGame.swf',
     		'type'			: 'swf',
     		'overlayColor'  : '#262626',
     });
     
    
 });

//Social Buttons

$(function() {

	$("#contact-items img").css("opacity","0.6");
	$("#contact-items img").hover(function () {

		$(this).stop().animate({
			opacity: 1.0
		}, 300);

	},

function () {

$(this).stop().animate({

	opacity: 0.6

	}, 300);

});

});

