jQuery.fx.step.rotation = function(fx) {
    var r = '' + fx.now + fx.unit;
    fx.elem.style.rotation = r;
    fx.elem.style['-webkit-transform'] = 'rotate(' + r + ')';
    fx.elem.style['-moz-transform'] = 'rotate(' + r + ')';
};

jQuery.fx.step['-app-shadow'] = function(fx) {
    var s = '' + fx.now + fx.unit;
    fx.elem.style['-app-shadow'] = s;
    fx.elem.style['box-shadow'] = '0 0 ' + s + ' #888';
    fx.elem.style['-webkit-box-shadow'] = '0 0 ' + s + ' #888';
}

$(function() {
	
	$('a[rel=boxy]').boxy();
	
	$('.rollover').rollover();
	
	$('h3:not(.inverse)').wrapInner('<span class="inverse"></span>');
	$('.main .left :first, .main .right :first').addClass('first');
	$('[hint]').inputHint({hintAttr: 'hint'});
	
	$('#nav a:not(.selected), #portfolio-item .sidebar .url').css('color', '#000000').hover(function() {
		$(this).stop().animate({color: '#ffffff'}, 200);
	}, function() {
		$(this).stop().animate({color: '#000000'}, 200);
	});
	
	$('#newsletter-blurb .actuator').click(function() {
		var $ns = $('#newsletter-signup');
		$ns.stop().animate({width: $ns.width() > 0 ? 0 : 200});
		return false;
	});
	
	$('#portfolio-index li a').hover(function() {
        $(this).stop().animate({rotation: '3deg', '-app-shadow': '10px' }, 200);
        $(this).find('.mask').stop().animate({opacity: 0.5}, 200);
    }, function() {
        $(this).stop().animate({rotation: '0deg', '-app-shadow': '0px'}, 200);
        $(this).find('.mask').stop().animate({opacity: 0}, 200);
    });
    
    $('#newsletter-signup').submit(function() {
        var $input = $(this).find('[name=email]'), $inner = $(this).find('.inner');
            $.ajax({
            data: {email: $input.val()},
                error: function() { $input.addClass('error'); },
                success: function() { 
                    alert("Thank you for signing up");
                    $input.removeClass('error').val('').blur();
                    $('#newsletter-blurb .actuator').click();
                },
                type: 'POST',
                url: $(this).attr('action')
        });
        return false;
    });
    
    $(document).bind('show.boxy', function(evt, data) {
        data.boxy.find('#contact-dialog').ajaxForm({
            success: function() {
                data.hideAndUnload();
            },
            error: function() {
                alert('Please complete the name and email fields');
            }
        });
    });
    
});