$(document).ready(function() {
	$(".scrollable").scrollable( );
	resizeIt();
	//$(".readmore").click();
});
$(window).resize(function() {
	resizeIt();
});
function resizeIt() {
	var amountImgs = 5;
	var wWin = $(window).width()-445;
	
	$("#projectscontainer").width(wWin-5);

	$(".items").children("div").width(wWin);
	$(".scrollable").width(wWin);
	var wImg = Math.floor((wWin-(4*amountImgs))/amountImgs);
	$(".scrollable").children("div").children("div").children("img").width(wImg);
	$(".scrollable").children("div").children("div").children("img").height(wImg/1.5);
	$(".scrollable").height(wImg/1.5+8);
	
	$(".projectBigVisual").each(function(i) {
		var wWin = $(window).width()-445;
		if ($(this).children("iframe").length>0) {
			$(this).height(wWin/1.77);
		} else {
			$(this).height(wWin/1.5);
		}
	});
	
	

	
	$("h2").click(function() {
		
		$(this).next("p").children(".readmore").click();
		
	});

	$(".readmore_down").click(function() {
		$(this).hide();
		$(this).parent().next(".extracontent").slideDown();	
	});
	
	$(".readmore_up").click(function() {
		$(".readmore_down").show();
		$(this).parent(".extracontent").slideUp();	
	});
	
	
	$(".readmore").click(function() {
		$(this).hide();
		$(this).parent().next().children(".readless").show();
		$(this).parent().next(".extracontent").slideDown(400, function() {
		});		
	});
	


	$(".readless").click(function() {
		
		$(this).hide();
		$(this).parent(".extracontent").slideUp(200, function() {
			$(this).prev("span").children(".readmore").show();
		});	
		
	});
	
	$(".thmb").click(function() {
	
		$(this).parent().parent().parent().parent().parent().children(".projectBigVisual").slideDown();

		if($(this).hasClass("vid")) {
						var src = $(this).attr("alt");
			$(this).parent().parent().parent().parent().parent().children(".projectBigVisual").children().fadeOut(300, function() {
				var projectW = $(this).parent(".projectBigVisual").width();	
				$(this).parent(".projectBigVisual").animate({"height": projectW/1.77}, 100);
				$(this).parent(".projectBigVisual").html('<iframe src="'+src+'" width="100%" height="100%" frameborder="0"></iframe>');
			});
		} else {
			var src = $(this).attr("src");
			$(this).parent().parent().parent().parent().parent().children(".projectBigVisual").children().fadeOut(300, function() {
				var projectW = $(this).parent(".projectBigVisual").width();
				$(this).parent(".projectBigVisual").animate({"height": projectW/1.5}, 100);
				$(this).parent(".projectBigVisual").html('<img src="'+src+'" width="100%" height="100%">');
			});
		}
		
				
	});
	

}
