$(document).ready(function(){
	hideProjects();
	hidePersonalProjects();
	$("#seeWork").mouseover(rollOver);
	$("#seeWork").mouseout(rollOut);
	$("#seeWorkPersonal").mouseover(rollOver);
	$("#seeWorkPersonal").mouseout(rollOut);
	$(".projectBlock > h3").click(toggleProject);
	$(".projectBlock > h3").mouseover(rollOver);
	$(".projectBlock > h3").mouseout(rollOut);
	
	var username='carloalducente';
	var format='json';
	var url='http://api.twitter.com/1/statuses/user_timeline/'+username+'.'+format+'?callback=?';
	$.getJSON(url,function(tweet){
		var date = new Date(tweet[0].created_at);
		var tweet = "<span id='tweetData'><a href='http://twitter.com/carloalducente' target='_blank'>@"+username+"</a> - "+(date.getMonth()+1)+"/"+date.getDate()+"/"+date.getFullYear()+"</span><br />"+tweet[0].text;
		$("#lastTweet").html(tweet);
		setTransparentBackground();
	});
});

function rollOver(){
	$(this).addClass("seeWorkHover");
}

function rollOut(){
	$(this).removeClass("seeWorkHover");
}

function setTransparentBackground(){
	$(".transparentBackground").css("width", $(".mainContainer").outerWidth());
	$(".transparentBackground").css("top", $(".mainContainer").css("top"));
	$(".transparentBackground").css("left", $(".mainContainer").css("left"));
	$(".transparentBackground").animate({
		height: $(".mainContainer").outerHeight()
	}, 200);
}

function hideProjects(){
	$(".clientWork").css("display", "none");
	$("#seeWork").html("> Client work.");
	setTransparentBackground();
	$("#seeWork").unbind("click");
	$("#seeWork").click(showProjects);
	closeProjectsInCategory(".clientWork");
}

function showProjects(){
	$(".clientWork").fadeIn(500);
	$("#seeWork").html("> Client work.");
	setTransparentBackground();
	$("#seeWork").unbind("click");
	$("#seeWork").click(hideProjects);
	$('html,body').animate({scrollTop: $("a[name=clientWork]").offset().top},'slow');
}

function hidePersonalProjects(){
	$(".personalWork").css("display", "none");
	$("#seeWorkPersonal").html("> Personal work.");
	setTransparentBackground();
	$("#seeWorkPersonal").unbind("click");
	$("#seeWorkPersonal").click(showPersonalProjects);
	closeProjectsInCategory(".personalWork");
}

function showPersonalProjects(){
	$(".personalWork").fadeIn(500);
	$("#seeWorkPersonal").html("> Personal work.");
	setTransparentBackground();
	$("#seeWorkPersonal").unbind("click");
	$("#seeWorkPersonal").click(hidePersonalProjects);
	$('html,body').animate({scrollTop: $("a[name=personalWork]").offset().top},'slow');
}

function toggleProject(){
	var desc = $(this).parent().children(".projectDescription");
	if($(desc).css("display") == "block"){
		$(desc).css("display", "none");
		$(desc).children("iframe").attr("src", $(desc).children("iframe").attr("src"));
	} else {
		$(desc).fadeIn(500);
		$('html,body').animate({scrollTop: $(desc).parent().offset().top},'slow');
	}
	setTransparentBackground();
}

function closeProjectsInCategory(category){
	$(category).each(function(index){
		var clientProject = $($(category)[index]);
		var clientProjDesc = $(clientProject).children(".projectDescription");
		if($(clientProjDesc).css("display") == "block"){
			$(clientProject).children("h3").click();
		}
	});
}
