$(document).ready(function() {
	if(!$.fontAvailable('Museo') && !($.browser.name == 'msie' && $.browser.versionNumber == 6)) {
		Cufon.replace('h1, h2, h3, h4, .details dd[class!=services]', {
			fontFamily: 'Museo',
			textShadow: '0 2px #07090d'
		});
		Cufon.replace('.nav.site li a strong, .recent-work h3, .link h3', {
			fontFamily: 'Museo',
			textShadow: '0 1px #07090d'
		});
		Cufon.replace('.panel.header h2, .panel h2.header, .panel.header h3, .panel h3.header, h3.button', {
			fontFamily: 'Museo',
			textShadow: '0 1px #b3cdec'
		});
		Cufon.replace('.post .meta .month, .post .meta .day', {
			fontFamily: 'Junction',
			textShadow: '0 1px #07090d'
		});
	}
	
	$('a#logo')
		.hover(function() {
			$(this).append('<span></span>');
			$(this).children('span').animate(
				{opacity: 1},
				200
			);
		}, function() {
			$(this).children('span').animate(
				{opacity: 0},
				100,
				'linear',
				function() { $(this).remove(); }
			);
		});
	
	$('.posts.index .post')
		.hover(function() {
			$(this).find('.meta dd:not(.permalink)').show('fast');
		}, function() {
			$(this).find('.meta dd:not(.permalink)').hide('fast');
		});
	
	$('.post .meta dd.reblog, .post .meta dd.tags, .post .meta dd.notes')
		.hover(function() {
			$(this).children(':first').fadeIn('fast');
		}, function() {
			$(this).children(':first').fadeOut('fast');
		});
	
	if (typeof(SyntaxHighlighter) != "undefined") {
		SyntaxHighlighter.config.tagName = "code";
		SyntaxHighlighter.defaults['auto-links'] = false;
		SyntaxHighlighter.defaults['gutter'] = false;
		SyntaxHighlighter.all();
		
		$('pre')
			.hover(function() {
				preWidth = $(this).width();
				codeWidth = $(this).find('.syntaxhighlighter .lines').width();
				if (codeWidth > preWidth) {
					$(this)
						.animate({
							width: codeWidth + 'px'
						}, 'fast')
						.addClass('expanded');
				}
			}, function() {
				if ($(this).hasClass('expanded')) {
					$(this)
						.animate({
							width: '502px'
						}, 'fast')
						.removeClass('expanded');
				}
			});
	}
	
	// Home
	if ($('body#home').length) {
		$('.recent-work .window').rotator();
	}
	
	
	// Work
	if ($('body#work').length) {
		$('.gallery .nav a.toggle').bind("click", function() {
			$(this).toggleClass('active');
			$('.all-work').slideToggle('normal');
			return false;
		});
	}
	
	
	// Contact
	if ($('body#contact').length) {
		
		// project fields
		$('#is-project:checked').each(function() {
			$('#project-details').show();
		});
		$('#is-project').click(function() {
			$('#project-details').slideToggle("normal");
		});
		
		// slider
		cOptions = {dropDecimals: true};
		$('#project-budget-slider').slider({
			min: 3000,
			max: 20000,
			step: 250,
			value: 6000,
			slide: function(e, ui) {
				$('.slider label').text('$'+ui.value).formatCurrency(cOptions);
				$('#project-budget').val('$'+ui.value).formatCurrency(cOptions);
			}
		});
		$('.slider label').text($('#project-budget-slider').slider('value')).formatCurrency(cOptions);
		$('#project-budget').val($('#project-budget-slider').slider('value')).formatCurrency(cOptions);
	
	}
});


/* 
 * Content Rotator
 * Scrolls content inside a frame
 * @author Eric Grossnickle
 */
jQuery.fn.rotator = function(options) {
	var settings = jQuery.extend({
		"group_id": $(this).attr('id'),
		"inner_id": $(this).children(':first').attr('class'),
		"timer": false,
		"duration": 5000,
		"onInit": function() {},
		"onHover": function() {},
		"onLeave": function() {},
		"center": false
	}, options);
	
	var $images = $(this).find('.images:first'),
	    imageH = $images.find('a:first').height() + parseInt($images.find('a:first').css('margin-bottom').replace('px', '')),
	    current = 1,
	    total = $images.children('a').size();
	
	$('.pager a').unbind("click");
	$('.pager a.previous').bind("click", function() {
		previous();
		return false;
	});
	$('.pager a.next').bind("click", function() {
		next();
		return false;
	});
	
	function previous() {
		last = current;
		
		if(current == 1) current = total;
		else current--;
		
		$images.animate({
			marginTop: -(current-1) * imageH
		}, {duration: 2000, easing: 'easeOutElastic', queue: false});
		
		$('#work-info-'+last).fadeOut('1000', function() {
			$('#work-info-'+current).fadeIn('1000');
		});
	}
	
	function next() {
		last = current;
		
		if(current == total) current = 1;
		else current++;
		
		$images.animate({
			marginTop: -(current-1) * imageH
		}, {duration: 2000, easing: 'easeOutElastic', queue: false});
		
		$('#work-info-'+last).fadeOut('1000', function() {
			$('#work-info-'+current).fadeIn('1000');
		});
	}
};

