
$(document).ready(function() {
/* 	Cufon.replace('.content', {fontFamily : 'carbon'}); */
	var hoverColor = $('body').attr('hover');

	$('.project #menu-item-52, .post #menu-item-186').addClass('current-menu-item');
	$('img').attr('title','');
	$('.tile').hover(function() {	
		$hover = $(this).find('.project-hover');
		$glassbar = $(this).find('.glass-bar');
		$title = $(this).find('.tile-title');
		
		$hover.stop().css({
			opacity: '1',
			display: 'block'
			});			
		$glassbar.stop().css({
			opacity: '0'
			})	
			
		$title.stop().css({'color' :'white'});
	}, function() {
		$glassbar.stop().animate({
			opacity: '1'
			},600)	
		$hover.stop().animate({
			opacity: '0'
			},600)	
		$title.stop().animate({'color' :'black'},600);
	})


	$('.search-result').hover(function() {
		$(this).css('background','white').find('.tab-arrow').css({'display' : 'block' , 'opacity' : '1'});
	}, function() {
		$(this).animate({
			'backgroundColor': $('body').css('backgroundColor')
		},300).find('.tab-arrow')
			.animate({
				'opacity':'0'
			},300, function() {
			$(this).find('.tab-arrow').css('display','none')
		});		
	})
	
	
	$('#footer-links').find('a').hover(function() {
		$(this).attr('originalOpacity', $(this).css('opacity'));
		$(this).stop().css({'opacity':'1'});	
	}, function() {
		var originalOpacity = $(this).attr('originalOpacity');
		$(this).stop().animate({
			'opacity': originalOpacity
		}, 600)
	})
	
	$('#follow-carbon').find('a').hover(function() {
		$(this).data('originalOpacity', $(this).css('opacity'));
		$(this).stop().css('opacity','1')		
	}, function() {
		$(this).stop().animate({
			'opacity': .4
		}, 600)
	})	

	$('#single-news').find('a').find('img').parent().each(function() {
		var attachment = $(this).find('img').attr('src');
	//	$(this).attr('href',attachment).attr('rel','fancybox');
	});

	$('.content a img:not(.no-lightbox)').parent().fancybox({
		padding : 20,
		overlayOpacity : .94,
		cyclic : true
	
	})


	

	
	
/*
	$('.content').find('p').find('a').find('img').parent().css({   //Wordpress WYSIWYG doesn't always wrap content in a <p> tag
		'padding-left' : '0px',
		'padding-right' : '0px',
		'margin-bottom' : '0px',
		'display' : 'block',
		'float' : 'left'}).parent().css({
			'padding-left' : '0px',
			'padding-right' : '0px',
			'margin-bottom' : '0px'});
	
	$('.content').find('p').find('img').parent().css({
		'padding-left' : '0px'
	})
*/
	
	$('.news-tile').hover(function() {
		$(this).stop().find('.news-index-hover').fadeIn(0);	
		$(this).stop().find('.tab-arrow').css({'opacity': '1', 'filter' : '', 'display' : 'block'});
		$(this).stop().css({
			'backgroundColor' : '#' + hoverColor,
			'borderColor' : '#' + hoverColor
		});
	}, function() {
		$(this).stop().find('.tab-arrow').animate({'opacity':'0', 'filter' : ''},300).css('display', 'none');
		$(this).stop().find('.news-index-hover').fadeOut(400);
		$(this).stop().animate({'backgroundColor' : 'white',
		'borderColor' : 'white'},300);
	
	});		
		
	$('#search, #s').click(function() {
		$('#searchform').css({'opacity' : '1', 'filter' : '', 'display':'block'});
		$('#s').focus();		
			
		return false;
	});
	$('#s').bind('focus',function() {
		
	})	

	$(document).click(function(){
		$('#searchform').animate({'opacity' : '0', 'filter' : ''},250).css('display','none');		
	})		

	
	
/*
	$('#clickarea, #searchform').hover(function() {	
	}, function() {
		$('#searchform').fadeOut('fast');	
		
	})
*/
	
	
	//highlight class black hover
	$('.highlight').find('a').hover(function() {
		$(this).attr('color', $(this).css('color'));
		$(this).stop().animate({			
			color: '#111111'
		},0)
	
	}, function() {
		if ($(this).parent().hasClass('current_page_item') ||  $(this).parent().hasClass('current-menu-item')) {
			$(this).stop().animate({
				color: 'black'
			},200)			
		} else {
		var originalColor = $(this).attr('color');
		$(this).stop().animate({
			'color': originalColor
		},100)	
		}			
	})
	

	
	$('#menu-primary a').hover(function() { // different for primary nav because they're images :/
		$(this).stop().animate({		
			opacity: '1',
			filter: ''
		},0)	
	}, function() {	
		if ($(this).parent().hasClass('current_page_item') ||  $(this).parent().hasClass('current-menu-item')) {
			$(this).stop().animate({
				opacity: '1',
				filter: ''
			},200)			
		} else {	
			$(this).stop().animate({				
				opacity: '.5'
			},200)
		}	
	})
	

	
	$('#menu-footer').find('a').hover(function() {
		$(this).stop().animate({'color' : 'black'},0);
	}, function() {
		$(this).stop().animate({'color' : '#808080'}, 300)
	
	})
	
	
	$('.button, .tax-bar').hover(function() {
		$(this).stop().animate({backgroundColor: '#' + hoverColor},0)
	
	}, function() {
		$(this).stop().animate({backgroundColor: 'white'},300)
	})
	
	$('#single-pagination').find('a').hover(function() {
		$(this).stop().css({
			'backgroundImage' : 'url(/wp-content/themes/foundry/images/nav-sprite.png)',
			'backgroundRepeat' : 'no-repeat',
			'backgroundPosition' : '-100px -169px'}).animate({backgroundColor: '#' + hoverColor},0)
	
	}, function() {
		$(this).stop().css({
			'backgroundImage' : 'none'
		}).animate({backgroundColor: 'white'}, 300)	
	})

	
	
	
		$inputs = $("input.defaultText");
	  $inputs.focus(function(srcc) { //for default form values
	    if ($(this).val() == $(this)[0].title) {
	    	$(this).removeClass("defaultTextActive");
	    	$(this).val("");
	    }
    });
    
    $inputs.blur(function() {
    	if ($(this).val() == "") {
      	$(this).addClass("defaultTextActive");
      	$(this).val($(this)[0].title);
      }
    });
    
    $inputs.blur();
		$("p:empty").remove();   //strip empty p's. thanks wordpress!   
		
		$('.single-post img.size-full').each(function() { //temporary, until they fix all the images to be full width. (stretches images to full width)
			var aspect = $(this).width() / 846;
			$(this).width($(this).width() / aspect);
			$(this).height($(this).height() / aspect);
						
		})
		
		$('#back-to-top').bind('click',function() {
			$.scrollTo(0,1200,{'easing': 'easeOutExpo'});
		
		})
		
		$('#menu-project-industry li a').addClass('ajaxy ajaxy-page');
		
		$('#process').find('.process-contain').hover(function() {
			$(this).find('.process').stop().css('opacity','0');
			$(this).find('.process-hover').stop().css('opacity','1');
		}, function() {
			$(this).find('.process').stop().animate({'opacity':'1'},350);
			$(this).find('.process-hover').stop().animate({'opacity':'0'},350);			
		})
		
/*
		$('.content h2:first').css('background','red');
		$('.content h2:first').nextAll('h2').css('background','green');
*/
		
		
		
		
		
		
		
		
		
		
		
		
		
		
/*
		$('.projects .menu a').each(function() {
			$(this).attr('rel' ,$(this).attr('href'));
			$(this).attr('href','#/projects/industry/consumer');
		})	
*/	
		
		
	

  /*
$(".projects .menu a").click(function(){
    var href = $(this).attr( "href" );
		
    // Push this URL "state" onto the history hash.
    $.bbq.pushState();

    // Prevent the default click behavior.
    return false;
  });
  
  // Bind a callback that executes when document.location.hash changes.
  $(window).bind( "hashchange", function(e) {
    // In jQuery 1.4, use e.getState( "url" );
    var url = $.bbq.getState( "url" );
    console.log(url);
  		$old = $('#project-contain > *');
			$('#project-contain > *').remove();
			$('#project-contain').append('<div class="ajax"></div>');
			$.ajax({url: url,
			   type: 'get', 
			   datatype: 'html',
			   success: function(outData) {
			   	$('#project-contain').html(
				   	$(outData).find('#project-contain')).fadeIn();
				   	console.log($(outData).find('#project-contain'));
			   }     
		});
    // In this example, whenever the event is triggered, iterate over
    // all `a` elements, setting the class to "current" if the
    // href matches (and removing it otherwise).
    $(".projects .menu a").each(function(){
      var href = $(this).attr( "href" );

      if ( href === url ) {
        $(this).parent().addClass( "current_page_item" );
      } else {
        $(this).removeClass( "current_page_item" );
      }
    });

    // You probably want to actually do something useful here..
  });
  


  // Since the event is only triggered when the hash changes, we need
  // to trigger the event now, to handle the hash the page may have
  // loaded with.
 $(window).trigger( "hashchange" );
*/  		











/*


// Keep a mapping of url-to-container for caching purposes.
  var cache = {
    // If url is '' (no fragment), display this div's content.
    '': $('.bbq-default')
  };
  
  // Bind an event to window.onhashchange that, when the history state changes,
  // gets the url from the hash and displays either our cached content or fetches
  // new content to be displayed.
  $(window).bind( 'hashchange', function(e) {
    
    // Get the hash (fragment) as a string, with any leading # removed. Note that
    // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
    var url = $.param.fragment();
    
    // Remove .bbq-current class from any previously "current" link(s).
    $( 'a.bbq-current' ).removeClass( 'bbq-current' );
    
    // Hide any visible ajax content.
    $( '.bbq-content' ).children( ':visible' ).hide();
    
    // Add .bbq-current class to "current" nav link(s), only if url isn't empty.
    url && $( 'a[href="#' + url + '"]' ).addClass( 'bbq-current' );
    
    if ( cache[ url ] ) {
      // Since the element is already in the cache, it doesn't need to be
      // created, so instead of creating it again, let's just show it!
      cache[ url ].show();
      
    } else {
      // Show "loading" content while AJAX content loads.
      $( '.bbq-loading' ).show();
      
      // Create container for this url's content and store a reference to it in
      // the cache.
      cache[ url ] = $( '<div class="bbq-item"/>' )
        
        // Append the content container to the parent container.
        .appendTo( '.bbq-content' )
        
        // Load external content via AJAX. Note that in order to keep this
        // example streamlined, only the content in .infobox is shown. You'll
        // want to change this based on your needs.
        .load( url, function(){
          // Content loaded, hide "loading" content.
          $( '.bbq-loading' ).hide();
        });
    }
  })
  
  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).trigger( 'hashchange' );
*/
		




	
});
