$(document).ready(function(){
	
	if(typeof initialize === 'function') { 
		initialize(); 
	}

	/* Portfolio Effects */
	$('.portfolio-item').hover(function(){
		$(this).children('.portfolio-meta').slideDown('fast');	
	}, function(){
		$(this).children('.portfolio-meta').slideUp('fast');	
	});
	
	/* @END Portfolio Effects */
	
	/* Article Effects */
	var $scrollingDiv = $("#item-description");
 	
	$(window).scroll(function(){			
		// if marginTop < #item-content.height-#item-description.height:
		if (parseFloat($scrollingDiv.css("marginTop")) < ($("#item-content").height()-$("#item-description").height()) )
		{
		    $scrollingDiv
		    	.stop()
		    	.animate({"marginTop": ($(window).scrollTop()) + "px"}, "slow" );				
		}
	});
	/* @END Article Effects */

	
	/* Twitter Effects */
	$('#twitter-link').mouseover(function(){
		$('#latest-tweet').fadeIn();
	});
	
	$('#latest-tweet').mouseout(function(){
		$(this).fadeOut();
	});
	/* @END Twitter Effects */
	
	/* Footer Button Effects */
	function hoverEvent(id){
		
		if ($('#'+id).attr("class") != "selected")
		{
		    html = "<span class=\""+id+"-hover\" /><span class=\""+id+"-normal\" />";
    		$('#'+id).css({backgroundImage:"none"}).html(html);
    		$('#'+id).mouseenter(function() {
		    	$('.'+id+'-hover').fadeIn();
    			$('.'+id+'-normal').fadeOut();
    			$('#'+id+"-icon").fadeIn();
		    }).mouseleave(function(){
    			$('.'+id+'-hover').fadeOut();
    			$('.'+id+'-normal').fadeIn();
    			$('#'+id+"-icon").fadeOut();
		    });
		
		}
    };
    
    hoverEvent("sheet-online");
	hoverEvent("sheet-pdf");
    /* @END Footer Button Effects */
	
	/* @ PRIMARY NAV */
	
	$('#primary-nav a').css({border:"none", paddingTop:"0px"});
	
    function fadeLinks(selector, speed, bgcolor) {	
					
		$(selector).each(function(){ 
			if ($(this).attr("class") != "selected")
			{
				var html = $(this).html();
				$(this).html("<span class=\"one\">"+ html +"</span>");
				$(this).append("<span class=\"two\">"+ html +"</span>");		
				if($.browser.msie){
					$("span.one",$(this)).css("background",bgcolor);
					$("span.two",$(this)).css("background",bgcolor);	
					$("span.one",$(this)).css("opacity",1);			
				};
				$("span.two",$(this)).css("opacity",0);		
				$("span.two",$(this)).css("position","absolute");		
				$("span.two",$(this)).css("top","0");
				$("span.two",$(this)).css("left","0");		
				$(this).hover(
					function(){
						$("span.one",this).fadeTo(speed, 0);				
						$("span.two",this).fadeTo(speed, 1);
					},
					function(){
						$("span.one",this).fadeTo(speed, 1);	
						$("span.two",this).fadeTo(speed, 0);
					}			
				)	
			} else {
				$(this).css({
					"paddingTop": "15px",
					"borderTop" : "3px solid #008496"
				});
			}
		});
	};
	
	fadeLinks("#primary-nav a", "normal", "#FFFFFF");
	
	/* @END Primary Nav */
	
	/* Address Effects */
	$("#footer-content address").css({backgroundImage:"none"});
	
	fadeLinks("#footer-content address", "normal", "#253247");
	
	/* @END Address Effects */
	
	/* About Effects */
	
	$("#nav-process").click(function(e){

		e.preventDefault();
		
		$("#nav-about").css('color','#008496');
		
		$("#nav-process").css('color','#D2E9EF');
		
		$('#process-web').css('width', '950px');
		
		$("#about-nav").animate({
			backgroundPosition: "65px"
		});
		
		$("#about").animate({
			opacity: "hide",
			left: -$("#about").outerWidth()
		});
		
		$("#about-process").animate({
			opacity: "show",
			left: 0
		});
		
	});
	
	$("#nav-about").click(function(e){
		e.preventDefault();
		
		$("#nav-about").css('color','#D2E9EF');
		
		$("#nav-process").css('color','#008496');
		
		$("#about-nav").animate({
			backgroundPosition: "-120px"
		});
			
		$("#about").animate({
			opacity: "show",
			left: 0
		});
		
		
		$("#about-process").animate({
			opacity: "hide",
			left: $("#about").outerWidth()
		});
		
	});
	
	/* @END About Effects */
	
	/* About Process Effects */
	
	$('#branding-header a').click(function(e){
		e.preventDefault();
		$('#web-header a').css('color', '#CCC');
		$(this).css('color', '#008496');
		
		$('#process-web').fadeOut('normal', function(){
			$('#process-branding').fadeIn();
			$('#process-branding li').each(function(i){
				$(this).wait((i+1)*25).animate({
					marginTop: "0px"
				});
			});
		});
		
		$('#process-web li').each(function(i){
			$(this).wait((i+1)*25).animate({
				marginTop: "150px"
			});
		});

	});
	
	$('#web-header a').click(function(e){
		e.preventDefault();
		$('#branding-header a').css('color', '#CCC');
		$(this).css('color', '#008496');
		
		$('#process-branding').fadeOut('normal', function(){
			$('#process-web').fadeIn();
			$('#process-web li').each(function(i){
				$(this).wait((i+1)*25).animate({
					marginTop: "0px"
				});
			});
		});
		
		$('#process-branding li').each(function(i){
			$(this).wait((i+1)*25).animate({
				marginTop: "150px"
			});
		});

	});
	
	/* @END About Process Effects */

	$.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };
});
