$(document).ready(function(){
			
	$(".attachmentFiles").each(function(){

		/* LICZY ZA��CZNIKI, DOPISUJE NUMERKI */

		var $attachmentFile = $(this).find(".attachmentFile");
		var countAttachments = $attachmentFile.length;

		$(".videoFile").siblings(".fileDetails").find(".fileAboutType").html("wideo");

		$attachmentFile.each(function(){
			var attachmentPosition = $attachmentFile.index(this)+1;
			$(this).find(".fileAboutCount").html(attachmentPosition+"&#160;z&#160;"+countAttachments);
		});

		/* POPRZEDNI/NAST�PNY */

		$attachmentFile.eq(0).find(".fileAboutPrev").css("color","#e5e5e5").removeAttr("class");
		$attachmentFile.eq(countAttachments-1).find(".fileAboutNext").css("color","#e5e5e5").removeAttr("class");

		var $prev = $(this).find(".fileAboutPrev");
		var $next = $(this).find(".fileAboutNext");

		$prev.click(function(){
			$attachmentFile.hide();
			$(this).parent().parent().parent().prev().show();
		});

		$next.click(function(){
			$attachmentFile.hide();
			$(this).parent().parent().parent().next().show();
		});

		/* POKAZUJE PIERWSZY ZA��CZNIK */
		$attachmentFile.eq(0).show();

		$(".filePreviewIcon").css("opacity","0.4");


	});

	/* ODPALA WIDEO */

	function createPlayer() {

		playerHref = 'flash/player/player.swf';
		flashvarsHref = 'flash/player/flashvars.xml';
		bgcolor = '#000000';
		width = 512;
		ratio = 16/9;
		playerControlsHeight = 33;
		height = width/ratio+playerControlsHeight;
		containerHeight = height+80;

		videoHref = $(this).attr("href");
		videoTitle = $(this).attr("title");

		flashvars = 'file='+videoHref+'&config='+flashvarsHref;

		playerCodePartOne = '<object width="'+width+'" height="'+height+'"><param name="movie" value="'+playerHref+'"><param name="flashvars" value="';
		playerCodePartTwo = '"></param></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="transparent"><embed wmode="transparent" src="'+playerHref+'" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" allowscriptaccess="always" allowfullscreen="true" flashvars="';
		playerCodePartThree = '"/></object>';
		playerCode = playerCodePartOne+flashvars+playerCodePartTwo+flashvars+playerCodePartThree;

		playerBoxCode = '<div class="videoPlayer" style="text-align: center;"><div style="position: relative; width: '+width+'; height:'+containerHeight+'px;"><div style="width: '+width+'px; margin: 0 auto 6px auto; text-align: left; position: relative; z-index: 99999; color: #909090; font: bold 18px Arial">'+videoTitle+'</div><div class="videoContainer" style="position: relative; z-index: 999">'+playerCode+'</div></div></div>';
        	$("body").append(playerBoxCode);
		$('.videoPlayer').jOverlay({color:'#000', opacity : 0.75});

	};

	$(".videoFile a").click(createPlayer);

});
