Cufon.replace('.light', { fontFamily: "Whitney Light", hover: {color:'#A6B541'} } );
Cufon.replace('.book', { fontFamily: "Whitney Book" } );

jQuery.fn.columnHeight = function() {
	var $ = jQuery;
	var objs = $(this);

	$(window).bind('resize', function() {
		// Get max height
		var maxHeight = 0;
		objs.each(function() {
			var thisMargin = parseInt( $(this).css("margin-top") );
			maxHeight = Math.max( $(this).height() + thisMargin, maxHeight );
		});

		// Set that height to all objects
		objs.each(function() {
			var thisMargin = parseInt( $(this).css("margin-top") );
			var targetHeight = maxHeight - thisMargin;

			$(this).css({
				paddingBottom: targetHeight - $(this).height()
			});
		});

		// Fill window
		var targetHeight = $("body").height() - $("#header").outerHeight(true);
		objs.each(function() {
			var thisPadding = targetHeight - $(this).outerHeight(true);

			if(thisPadding>0)
				$(this).css({
					paddingBottom: thisPadding + parseInt( $(this).css("padding-bottom") )
				});
		});
	});

	// Initial resize
	$(window).trigger('resize');
	$(window).bind('scroll', function() {
		$(window).trigger('resize');
	});
}

jQuery.fn.floatingMenu = function() {
	var $ = jQuery;
	var triggers = new Array();

	this.each(function() {
		var obj = this;

		// Get a starting point
		var initPos = $(this).offset().top;

		// Preset width and height
		$(this).width( $(this).width() );
		$(this).parent().height( $(this).parent().height() );

		// The function where it all happens
		function thisOnResize() {
			if( $(window).scrollTop()>initPos ) {
				// Floating
				$(obj).css({
					position: "fixed",
					top: 0,
					left: $(obj).parent().offset().left
				})
			} else {
				// Static at the top
				$(obj).css({
					position: "relative",
					left: 0,
					top: 0
				});
			}
		}

		triggers.push(thisOnResize);
	});

	// A 'shortcode'
	function windowScroll() {
		for(i=0; i<triggers.length; i++)
			triggers[i]();
	}

	// If the element is with fixed position,
	// it needs to be moved on resize, because
	// it's left is relative to the window
	$(document).ready(windowScroll);
	$(window).bind('scroll', windowScroll);
	$(window).bind('resize', windowScroll);
	$(window).bind('load', windowScroll);
	windowScroll();
}


jQuery(document).ready(function($){
	try {
		$(document).pngFix(); 
	} catch( err ) {
		// Blank
	}

	$(window).load(function(){ 
		var side_col = $('.column-3');
		var main_col = $('.column-4');
		if ( !side_col.length ) { side_col = $('.column-5') };
		if ( !main_col.length ) { main_col = $('.column-6') };
		if ( !side_col.length ) { side_col = $('.column-1') };
		if ( !main_col.length ) { main_col = $('.column-2') };
		
		if ( side_col.height()+150 > main_col.height() ) {
			$('#footer').css('margin-top', side_col.height() - main_col.height() + 200);
		};
	    $('.columns').columnHeight(); 

	    $(".column-1 .menu").floatingMenu();
	}) 
	
	$('.gform_wrapper li.gfield label').each(function() {
		var parent = $(this).parent();
		if ( parent.children('.gfield_description').length > 0 ) {
			$(this).remove().insertBefore(parent.children('.gfield_description:last'));
		} else {
			parent.append($(this).remove());
		}
	});
	
	$('.blink').
	focus(function() {
		if(this.title==this.value) {
			this.value = '';
		}
	})
	.blur(function(){
		if(this.value=='') {
			this.value = this.title;
		}
	});
	
	$('#slider li a.handle:not(:animated)').click(function() {
		var slide = $(this).closest('li');
		var slides_left = slide.prevAll();
		var slides_right = slide.nextAll();
		
		if (slide.is('.hleft')) {
			slide.removeClass('hleft').addClass('hright').animate({left: '+=600'});
			slides_right.filter('.hleft').removeClass('hleft').addClass('hright').animate({left: '+=600'});
		} else if(slide.is('.hright')) {
			slides_left.filter(':not(.hleft)').animate({left: '-=600'}).addClass('hleft').removeClass('hright');
		}
		
		return false;
	});
	$('.hentry:last').addClass('last');
	
	
	$('#search .submit, .blog-sidebar .newsletter-signup .submit, .blog-entry .post-reply .submit, .contact-form .submit, #searchform input').hover( 
		function(){$(this).addClass('submit-hover'); }, 
		function(){ $(this).removeClass('submit-hover'); }       
	); 
	 
	 
	$('.page-nav .prev').hover( 
		function(){ $(this).addClass('prev-hover'); }, 
		function(){ $(this).removeClass('prev-hover'); } 
	); 
	 
	$('.page-nav .next').hover( 
		function(){ $(this).addClass('next-hover'); }, 
		function(){ $(this).removeClass('next-hover'); } 
	); 
	 
	$('.work-samples ul li').hover( 
		function(){ $(this).addClass('hover') }, 
		function(){ $(this).removeClass('hover') } 
	); 
	 
	$('.clients .image').hover( 
		function(){ $(this).addClass('image-hover'); }, 
		function(){ $(this).removeClass('image-hover'); } 
	); 
	$('.clients .image').click(function(e) {
		window.location = $(this).closest('.image').find('a.button').attr('href');
		return false;
	});
});
