jQuery.event.add(window, "load", resizeFrame);
jQuery.event.add(window, "resize", resizeFrame);

function resizeFrame() 
{
	var w = $(document).width();
	var widthLeft;
	var widthRight;
	var heightLeft;
	var heightRight;
	
	if( w > 1220 ) {
		widthLeft = 255;
		widthRight = 289;
		heightLeft = 780;
		heightRight = 502;
	} else {
		widthLeft = w < 1024 ? 157 : ( w - 960 ) / 2 + 125;
		widthRight = w < 1024 ? 191 : ( w - 960 ) / 2 + 159;
		heightLeft = widthLeft * 780 / 255;
		heightRight = widthRight * 502 / 289;
	}
		
	$("#leftbuilding").css('width', widthLeft);
	$("#leftbuilding img").css('width',widthLeft);
	$("#rightbuilding").css('width',widthRight);
	$("#rightbuilding img").css('width',widthRight);
	$("#leftbuilding").css('height', heightLeft);
	$("#leftbuilding img").css('height',heightLeft);
	$("#rightbuilding").css('height',heightRight);
	$("#rightbuilding img").css('height',heightRight);
}

$(document).ready(function(){
	
	// PNG
	$(document).pngFix();
	
	// Portfolio
	var oml = $("#scroller").scrollLeft();
	var count = 0;
	
	$(".description:gt(0)").css("display", "none");
	
	$("#scroll-right").click(function(){
		if (oml > -$("#scroller").width() +600){
			oml -= 600;
			$("#scroller").animate({marginLeft: oml}, 600);
			count++;
			swapDescription( count );
			$("#scroll-left").fadeIn();
		}
		if (oml <= -$("#scroller").width() +600)
		{
			$("#scroll-right").fadeOut();
		}
	});
	
	$("#scroll-left").fadeOut();
	$("#scroll-left").click(function(){
		if (oml < 0){
			oml += 600;
			$("#scroller").animate({marginLeft: oml});
			count--;
			swapDescription( count );
			$("#scroll-right").fadeIn();
		}
		if(oml > -1){
			$("#scroll-left").fadeOut();
		}
	});
	
	// Rozwiajanie menu, działa póki co tylko dla internetu - w razie rozwoju poprawić.
	if($(".sub .current").size() > 0)
	{
		$("a.expand").toggle(
			function(){
				$(this).parent().css( "background-image", "url('/workspace/images/arrow.gif')");
				$($(this).attr("href")).slideUp();
			}, function(){
				$(this).parent().css( "background-image", "url('/workspace/images/arrow-down.gif')");
				$($(this).attr("href")).slideDown();
			}
		);
		$("a.expand + ul").slideDown();
	}
	else
	{
		$("a.expand").toggle(
			function(){
				$(this).parent().css( "background-image", "url('/workspace/images/arrow-down.gif')");
				$($(this).attr("href")).slideDown();
			}, function(){
				$(this).parent().css( "background-image", "url('/workspace/images/arrow.gif')");
				$($(this).attr("href")).slideUp();
			}
		);
	}
	
	$("#blog-navi img.prev").hover(
		function(){$(this).attr("src", "/workspace/images/post-prev-over.png")},
		function(){$(this).attr("src", "/workspace/images/post-prev.png")}
	);
	
	$("#blog-navi img.next").hover(
		function(){$(this).attr("src", "/workspace/images/post-next-over.png")},
		function(){$(this).attr("src", "/workspace/images/post-next.png")}
	);
	
	$("#blog-navi img.up").hover(
		function(){$(this).attr("src", "/workspace/images/post-up-over.png")},
		function(){$(this).attr("src", "/workspace/images/post-up.png")}
	);
});

function swapDescription( count ) {
	$(".description:visible").fadeOut(300, function(){ $(".description:eq("+count+")").fadeIn(300)})
}