/*                                     JQUERY ON DOC READY
__________________________________________________________
*/

$(document).ready(function(){



	/* ---SMOOTH SCROLL----------------------------- */
	
	$('div#buttonBar a').smoothScroll({
        afterScroll: function() {
        	/* location.hash = this.hash; */
        }
    });
    
    $('div#bio a').smoothScroll({
        afterScroll: function() {
        	/* location.hash = this.hash; */
        }
    });

	/* ---RSS Reader ------------------------------- */
	
	
	$('#result').rssfeed('http://twitter.com/statuses/user_timeline/15597240.rss', {
		limit: 5,
		header: false
	});
	

	/* ---NAV BAR ANIMATION------------------------- 

   	var w = $(window).width();
   	
   	var thisguy = (w/2)-1421;
   	var mywork = (w/2)-1325;
   	var whaticando = (w/2)-1213;
   	var messageme = (w/2)-1091;
   	
   	var lastclicked = 1421;
	
    $('div#navbar').css({backgroundPosition: thisguy +'px 0'});
    
    */
    
    /* ---FOOTER HEIGHT FIX------------------------- 
    
    var h = $(window).height();
    $("div#contact").css("min-height", h - 334 +'px');

*/

	/* ---NAV BAR ANIMATION------------------------- 
	
	function isScrolledIntoView(elem) {
        var docViewTop = $(window).scrollTop();
        var docViewBottom = docViewTop + $(window).height();

        var elemTop = $(elem).offset().top;
        var elemBottom = elemTop + $(elem).height();

        return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
    }

    $(window).scroll(function() {
        if(isScrolledIntoView('#about')) {
        	$('div#navbar').stop().animate({backgroundPosition: thisguy +'px 0'}, {duration:300});
       		lastclicked = 1421;
        } else if(isScrolledIntoView('#work')) {
            $('div#navbar').stop().animate({backgroundPosition: mywork +'px 0'}, {duration:300});
       		lastclicked = 1325;
        } else if(isScrolledIntoView('#services')) {
       		$('div#navbar').stop().animate({backgroundPosition: whaticando +'px 0'}, {duration:300});
        	lastclicked = 1213;
        } else {
        	$('div#navbar').stop().animate({backgroundPosition: messageme +'px 0'}, {duration:300});
        	lastclicked = 1091;
        }
    });

	*/

	/* ---BROWSER RESIZE - NAVBAR FIX--------------- 
	
    $(window).resize(function() {
    	var w = $(window).width();
    	
    	var thisguy = (w/2)-1421;
	   	var mywork = (w/2)-1325;
	   	var whaticando = (w/2)-1213;
	   	var messageme = (w/2)-1091;
    	
		$('div#navbar').css({backgroundPosition: (w/2)-lastclicked +'px 0'});
		
		$(window).scroll(function() {
	        if(isScrolledIntoView('#about')) {
	        	$('div#navbar').stop().animate({backgroundPosition: thisguy +'px 0'}, {duration:300});
	       		lastclicked = 1421;
	        } else if(isScrolledIntoView('#work')) {
	            $('div#navbar').stop().animate({backgroundPosition: mywork +'px 0'}, {duration:300});
	       		lastclicked = 1325;
	        } else if(isScrolledIntoView('#services')) {
	       		$('div#navbar').stop().animate({backgroundPosition: whaticando +'px 0'}, {duration:300});
	        	lastclicked = 1213;
	        } else {
	        	$('div#navbar').stop().animate({backgroundPosition: messageme +'px 0'}, {duration:300});
	        	lastclicked = 1091;
	        }
        });
        
        
	    // Footer height fix after resize
	    var h = $(window).height();
    	$("div#contact").css("min-height", h - 334 +'px');
	    
    });

*/

	/* ---HOMEPAGE FANCYBOX------------------------- */
	
	$("a.thumbs").fancybox({
		'titleShow': true,
		'titlePosition'	: 'over',
		'overlayColor' : '#000',
		'overlayOpacity' : '0.9',
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});



	/* ---FADE BIO ON HOVER------------------------- 

	$("div#fadebox").hover(function(){
		$("div#bio").stop().fadeTo(600, 1);
	},function(){
		$("div#bio").stop().fadeTo(800, 0);
	});
	
	$('div#bio').hide();

*/

	/* ---LAYOUT SWITCH----------------------------- 
	
	$("a#switch").toggle(function(){
		$("a#switch").css("background-position", "bottom left");
		$("div#work, div#services, div#contact").css("width", "auto");
		$("div#container").stop().animate({width: "850px"}, 300);
		$("div#bio").css("margin-left", "435px");
		$("div.webwork, div.logowork").css("margin-left", "21px");
		$("div#bio").stop().fadeTo(800, 1);
		
		$("div#fadebox").hover(function(){
			$("div#bio").stop().fadeTo(600, 1);
		},function(){
			$("div#bio").stop().fadeTo(0, 1);
		});
		
		$("a#switch").hover(function(){
		$("a#switch").css("background-position", "bottom right");
			},function(){
		$("a#switch").css("background-position", "bottom left");
		});
		
		$("div#contact_form").css("width", "826px");
		$("div#contact_form label input").css("width", "393px");
		$("div#contact_form label textarea").css("width", "810px");
		
	},function(){
		$("a#switch").css("background-position", "top left");
		$("div#container").stop().animate({width: "420px"}, 300);
		$("div#work, div#services, div#contact").stop().animate({width: "390px"}, 300);
		$("div#bio").css("margin-left", "5px");
		$("div#bio").css("background-image", "url(img/bg-bio.gif)");
		$("div.webwork, div.logowork").css("margin-left", "0px");
		$("div#bio").hide();

		$("div#fadebox").hover(function(){
		$("div#bio").stop().fadeTo(600, 1);
			},function(){
		$("div#bio").stop().fadeTo(800, 0);
		});
		
		$("a#switch").hover(function(){
		$("a#switch").css("background-position", "top right");
			},function(){
		$("a#switch").css("background-position", "top left");
		});
		
		$("div#contact_form").css("width", "auto");
		$("div#contact_form label input").css("width", "175px");
		$("div#contact_form label textarea").css("width", "374px");
		
	});

*/

	/* ---SORT WORK DROPDOWN------------------------ 

	$('div.logowork').hide();
	$('select#sortwork').val('webwork');
	
	$('select#sortwork').change(function() {
	    $('div.webwork').hide();
	    $('div.logowork').hide();
	    $('div.' + $(this).val()).stop().fadeTo(600, 1);
	});

*/


	

});







