$(document).ready( function(){
	$('#portfolio').innerfade({
		speed: 'slow',
		timeout: 4000,
		type: 'sequence',
		containerheight: '284px'
	});
	
	$('#faq div').hide();
	j = 1;
	$('#faq a').each(function(i){
		testy = $(this).attr('href');
		if(testy == '#'){
			$(this).next().attr('id', 'faq_'+j);
			$(this).attr('rel', j);
			$(this).css({'text-decoration' : 'none', 'font-weight' : 'bold'});
			$(this).before('<br />');
			$(this).after('<br />');
		}
		j++;
	});
	
	$('#faq a').click(function(){
		var whatLink = $(this).attr('href');
						
		var relID = $(this).attr('rel');
		var faqID = 'faq_'+relID;
		
		if($('#'+faqID).is(':hidden')){
			$('#'+faqID).slideDown('slow');
		}else{
			$('#'+faqID).slideUp('slow');
		}
		
		if(whatLink == '#'){
			return false;
		}

	});
	
	$('#hidden').css('display', 'none');
	
	$('#archives').click(function(){
		$('#hidden').slideToggle('slow');
	});
	
	$('input[type=hidden]').each(function(){
		$(this).css('display', 'none');
	});
		
	$(':input').focus(function(){
		if($(this).val() == $(this).attr('rel')){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			var atty = $(this).attr('rel');
			$(this).val(atty);
		}
	});
	
	//INPUTS AND SUCH
	$('input[type=hidden]').each(function(){
		$(this).css('display', 'none');
	});
	
	$('input[type=checkbox]').each(function(){
		$(this).css({width : 'auto', display: 'inline', });
	});
		
	$(':input').focus(function(){
		if($(this).val() == $(this).attr('rel')){
			$(this).val('');
		}
	}).blur(function(){
		if($(this).val() == ''){
			var atty = $(this).attr('rel');
			$(this).val(atty);
		}
	});

 	$('.showDescription').toggle(function(){
		$(this).next().show(1000);
		$(this).css('font-weight', 'bold');
	},function(){
		$(this).next().hide('slow');
		$(this).css('font-weight', 'normal');
	});
	
	//BLOGGITY BLOGGERSON
	$('.viewComments').each(function(){
		$(this).next().css('display', 'none');
	});
	
 	$('.viewComments').toggle(function(){
		$(this).next().slideDown(1000);
		$(this).html('nevermind');
	},function(){
		$(this).next().slideUp('slow');
		$(this).html('View Comments');
	});
	
 	$('.addComment').toggle(function(){
		$(this).next().slideDown(1000);
		$(this).html('nevermind');
	},function(){
		$(this).next().slideUp('slow');
		$(this).html('Add Comment');
	});	
	
	$('.addComment').each(function(){
		$(this).next().css('display', 'none');
	});
	
	$('input[rel=hide]').click(function(){
		var co = $(this).prev();
		var wh = $(this).prev().prev();
		var com = $(co).val();
		var who = $(wh).val();
		var id = $(this).attr('hidden');
		var bad = '';
		
		if(who == 'Your Name'){
			$(wh).css('background-color', '#74423c');
			var bad = 'true';
		}else{
			$(wh).css('background-color', '#5A4C44');
		}
		
		if(com == 'Your Comment'){
			$(co).css('background-color', '#74423c');
			var bad = 'true';
		}else{
			$(co).css('background-color', '#5A4C44');
		}
		
		if(bad == ''){
			$.ajax({
				type: 'POST',
				url: 'php/ajax/comments.php',
				data: 'ID='+id+'&who='+who+'&what='+com,
				success: function(msg){
					if(msg == 'bad'){
						alert('There was an error processing your comment. Sorry.');
					}else{
						alert('Your comment is being processed. This page will automatically refresh.');
						$(wh).val('Your Name');
						$(co).val('Your Comment');
						location.reload();
					}
				},
				dataType: 'html'
			});
		}
		
	})
});