$.extend(config, {portfolio: {emailDefaultText: 'Email address goes here', commentDefaultText: 'Write a comment...', previewImage: {minHeight: '350px',maxHeight: ''}, commentHTML: '<dl id="newest-comment" class="comment none"><dt></dt><dd><span></span><span class="timestamp"></span></dd></dl>'}});

$(document).ready(function(){
	config.portfolio.previewImage.maxHeight = $('#previewImage>img').height()+'px';
	$('#new-comment textarea')
		.focus(function(){
			if (this.value == config.portfolio.commentDefaultText){this.value = '';}
			$('#comment-save, #email').show();
		})
		.blur(function(){
			if (this.value == ''){this.value = config.portfolio.commentDefaultText;}
			//if (this.value == config.portfolio.commentDefaultText){$('#comment-save').hide();}
		})
		.attr('maxlength', 160)
		.maxlength();
	$('#email')
		.focus(function(){
			if (this.value == config.portfolio.emailDefaultText){this.value = '';}
		})
		.blur(function(){
			if (this.value == ''){this.value = config.portfolio.emailDefaultText;}
		});
	$('#previewImage').hover(function(){$('#previewImageSizer', this).animate({height: '20px'}, 200);},function(){$('#previewImageSizer', this).animate({height: '0px'}, 200);});
	$('#previewImage').click(function(){
		var newHeight = ($('span', this).attr('class') == 'triDown') ? config.portfolio.previewImage.maxHeight : config.portfolio.previewImage.minHeight;
		$('span', this).toggleClass('triUp', 'triDown');
		$('#previewImage').animate({height: newHeight}, 400);
	});
	
	
	/* events */
	$(document).bind('new-comment', function(e, response) {
		if (response.success == true) {
			$('#new-comment').slideUp(300);
			$('.comments').append(config.portfolio.commentHTML);
			$('#newest-comment').hide();
			$('#newest-comment dt').text(response.data.email);
			$('#newest-comment dd span:eq(0)').text(response.data.comment);
			$('#newest-comment dd span:eq(1)').text(response.data.timestamp);
			$('#newest-comment').slideDown(400);
		} else {
			var errorHTML = '<h4><em class="color-red">Error</em> While Adding Comment</h4><ul class="ic-list">';
			$.each(response.error, function(i, val) {
				errorHTML += '<li class="color-red">'+val.message+'</li>';
			});
			errorHTML += '</ul>';
			$.facebox(errorHTML);
			return false;
		}
	});
});
