$(document).ready(function(){ 
		
		$(".pressReleaseFile, .pressKitFile").click(function(){
			filmID = $(this).attr('id');
			filmTitle = $(this).attr('title');
			videoSrc = $(this).attr('href');
			
			videoSource = $(this).attr('href');
			
			var temp = new Array();
			temp = videoSource.split('/');
			fileLink = '/'+temp[2]+'/'+temp[3]+'/'+temp[4];
		
			var prime = new Array();
			prime = videoSource.split('f/');
			
			imageSource = prime[0]+'tf/'+prime[1];
			
			videoPlayerHeight = '392';
			videoPlayerWidth = '480';
			videoPlayerID = $(this).attr('id');
			videoPlayerSwf = 'http://media.netpr.pl/m/video/jwplayer/4/player.swf';
			videoPlayerSkin = 'http://media.netpr.pl/biuletyn/js/stylish.swf';
			
			videoPlayerPreview = '/PressOffice/getNewsThumbnail.PressRelease.106904.po?file='+videoPlayerID;
			videoBackcolor = '000000';
			videoFrontcolor = 'ffffff';
			videoLightcolor = '6bcce8';
			videoScreencolor = '000000';
			
			if ($(this).attr('class') == 'pressReleaseFile') {
				videoFlvVersion = '2.flv';
				clientID = $(".pressReleaseFiles").attr('id');
			} else {
				videoFlvVersion = '.flv';
				clientID = $(".pressKitFiles").attr('id');
			}
			
			videoPlayerCode = '<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,40,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" height="'+videoPlayerHeight+'" width="'+videoPlayerWidth+'"><param name="wmode" value="transparent" /><param value="'+videoPlayerSwf+'" name="src"><param value="true" name="allowFullScreen"><param value="image='+imageSource+'&amp;skin='+videoPlayerSkin+'&amp;backcolor='+videoBackcolor+'&amp;frontcolor='+videoFrontcolor+'&amp;lightcolor='+videoLightcolor+'&amp;screencolor='+videoScreencolor+'&amp;height='+videoPlayerHeight+'&amp;width='+videoPlayerWidth+'&amp;file='+videoSrc+'&autostart=true&bufferlength=2" name="flashvars"><embed allowfullscreen="true" allowscriptaccess="always" menu="false" type="application/x-shockwave-flash" src="'+videoPlayerSwf+'" wmode="transparent" pluginspage="http://www.adobe.com/go/getflashplayer" flashvars="image='+imageSource+'&bufferlength=2&autostart=true&amp;skin='+videoPlayerSkin+'&amp;height='+videoPlayerHeight+'&amp;width='+videoPlayerWidth+'&amp;file='+videoSrc+'&amp;backcolor='+videoBackcolor+'&amp;frontcolor='+videoFrontcolor+'&amp;lightcolor='+videoLightcolor+'&amp;screencolor='+videoScreencolor+'" width="'+videoPlayerWidth+'" height="'+videoPlayerHeight+'"></object>';			
			
			startWidth = 480;
			startHeight = startWidth * 3 / 4 +32;
			
			var videoCode = '<div id="dialog" style="display: none;"><div class="video" style="position: relative; z-index: 999"></div></div><div id="embMe" style="display: none;"><div style="margin: 15px 10px 5px 10px;"><span>Szerokość: <input style="font: 11px Verdana; width: 30px" id="vidWidth" type="text" value="'+startWidth+'"/></span><span style="margin-left: 15px;">Wysokość: <input style="font: 11px Verdana; width: 30px" id="vidHeight" type="text" value="'+startHeight+'"/></span><span style="cursor: pointer; margin-left: 10px;" id="okBtn">GENERUJ</span></div><div style="margin: 20px 10px 5px 10px;">Skopiuj kod i wklej na swoją stronę:</div><div id="textarea" style="margin: 10px; padding: 3px; border: 1px solid #333;"><textarea style="border: 1px solid #fff; height: 140px;width: 299px; font: 11px Verdana; color: #666"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+startWidth+'" height="'+startHeight+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"> <param name="src" value="http://media.netpr.pl/m/video/jwplayer/4/player.swf"/><param name="allowFullScreen" value="true"/><param name="flashvars" value="image='+imageSource+'&bufferlength=2&skin=http://media.netpr.pl/biuletyn/js/stylish.swf&backcolor=0x000000&frontcolor=0xFFFFFF&fullscreen=true&menu=false&lightcolor=0x44b1f6&autostart=false&height='+startHeight+'&width='+startWidth+'&file='+videoSrc+'"/><embed flashvars="image='+imageSource+'&bufferlength=2&skin=http://media.netpr.pl/biuletyn/js/stylish.swf&backcolor=0x000000&frontcolor=0xFFFFFF&fullscreen=true&menu=false&lightcolor=0x44b1f6&autostart=false&height='+startHeight+'&width='+startWidth+'&file='+videoSrc+'" pluginspage="http://www.adobe.com/go/getflashplayer" src="http://media.netpr.pl/m/video/jwplayer/4/player.swf" type="application/x-shockwave-flash" menu="false" allowscriptaccess="always" allowfullscreen="true" height="'+startHeight+'" width="'+startWidth+'"/></object></textarea></div></div>'
			
			$("body").append(videoCode);
			
			$("#dialog").dialog({title: filmTitle, height: 392, width: 480, dragabble: true,resizable:false,modal: true,overlay: {opacity: 0.8,background: "black"},close:function() {
				$(".ui-dialog, #dialog, #embMe").remove();
			}, open: function() {
				$("#dialog").attr("style","")
				$(".video").append(videoPlayerCode);
			}});
			
			$(".ui-dialog").height("auto");
			
			$("#dialog").append("<div class='embed' style='position: absolute; z-index: 999999; top: 350px;'></div>");
			
			$(".ui-dialog").mouseover(function(){
				$(".embed").fadeTo(1,0.6).show();
			}).mouseout(function(){
				$(".embed").hide();
			});
			
			/* embed */
			
			$(".embed").mouseover(function(){
				$(this).addClass("embOver");
			}).mouseout(function(){
				$(this).removeClass("embOver");
			}).click(function(){
				$(".ui-dialog, #dialog").remove();
				$("#embMe").dialog({title: 'Wklej wideo', dragabble: true, resizable: false, height: 280, width: 330, close: function() {
					$(".ui-dialog, .ui-dialog-overlay, #dialog, #embMe").remove();
				}, open: function() {$("#embMe").show();}});
			});
			
			$("#embMe textarea, #embMe input").click(function(){$(this).select();});
			
			$("#vidWidth").blur(function(){
				changedWidth = $(this).attr('value');
				changedHeight = changedWidth * 3 /4 +32;
				$("#vidHeight").attr("value",changedHeight);
			});
			
			$("#vidHeight").blur(function(){
				changedHeight = $(this).attr('value');
				changedWidth = (changedHeight - 32)*4/3;
				$("#vidWidth").attr("value",changedWidth);
			});
			
			$("#okBtn").click(function(){
				vidHeight = $("#vidHeight").attr('value');
				vidWidth = $("#vidWidth").attr('value');
				videoCodeCustom ='<textarea style="border: 1px solid #fff; height: 140px;width: 299px; font: 11px Verdana; color: #666"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+vidWidth+'" height="'+vidHeight+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"> <param name="src" value="http://media.netpr.pl/m/video/jwplayer/4/player.swf"/><param name="allowFullScreen" value="true"/><param name="flashvars" value="image='+imageSource+'bufferlength=2&skin=http://media.netpr.pl/biuletyn/js/stylish.swf&backcolor=0x000000&frontcolor=0xFFFFFF&fullscreen=true&menu=false&lightcolor=0x44b1f6&autostart=false&height='+vidHeight+'&width='+vidWidth+'&file='+videoSource+'"/><embed flashvars="image='+imageSource+'bufferlength=2&skin=http://media.netpr.pl/biuletyn/js/stylish.swf&backcolor=0x000000&frontcolor=0xFFFFFF&fullscreen=true&menu=false&lightcolor=0x44b1f6&autostart=false&height='+vidHeight+'&width='+vidWidth+'&file='+videoSource+'" pluginspage="http://www.adobe.com/go/getflashplayer" src="http://media.netpr.pl/m/video/jwplayer/4/player.swf" type="application/x-shockwave-flash" menu="false" allowscriptaccess="always" allowfullscreen="true" height="'+vidHeight+'" width="'+vidWidth+'"/></object></textarea>'
				$("#embMe #textarea").fadeOut();
				$("#embMe textarea").remove()
				$("#embMe #textarea").append(videoCodeCustom);
				$("#embMe #textarea").fadeIn();
				$("#embMe textarea").click(function(){$(this).select();});
			});
			
		});
		
});

