$(function(){
	$("a.project_photo").fancybox({
		'titleShow':false
	});
	$("a.reference_image, a.fancybox").fancybox({
		'titlePosition':'over'
	});
	
	$("form input[type='text'], form textarea").focus(function(){
		$(this).addClass("active");
	}).blur(function(){
		$(this).removeClass("active");
	});
	
	$("#screen_carousel").carouFredSel({
		width: 880,
		height: 350,
		items: {
			visible: 1
		},
		direction: "left",
		scroll: {
			mousewheel: false,
			duration: 500,
			pauseOnHover: true,
			pauseDuration: 5000
		},
		pagination: {
			container: "#screen_pages",
			anchorBuilder: function(n) {
				return "<li></li>";
			}
		}
	});
	
	var loadImage = function(arr, i) {
		if( i < arr.length ) {
			$("<img />")
			.attr("src","/media/img/screen/"+arr[i])
			.load(function(){
				var curr = $("<li />").attr("id","screen_"+i).append(this);
				
				$("#screen_carousel").trigger("insertItem",[curr,"end",0,true]);
				
				if( i == 0 ) {
					$("#screen").fadeIn();
				}
				loadImage(arr,++i);
			});
		}
	}
	if( $("#screen_carousel").length > 0 ) {
		var imgs = ["obrazek-1.jpg","obrazek-2.jpg","obrazek-3.jpg","obrazek-4.jpg"];
		loadImage(imgs, 0);
	}
	
	$("#img_carousel").carouFredSel({
		width: 180,
		items: {
			visible: 3
		},
		direction: "up",
		scroll: {
			mousewheel: true,
			items: 1,
			duration: 300,
			pauseOnHover: true,
			pauseDuration: 2500
		}
	});
});
