// JavaScript Document

$(document).ready(function() {
			
			
            $("#commentBold").click(function() {
											var $obj = $("#F_comment").getSelection();
               								$("#F_comment").replaceSelection('[b]' + $obj.text + '[/b]');
            });
			
            $("#commentItalic").click(function() {
											var $obj = $("#F_comment").getSelection();
               								$("#F_comment").replaceSelection('[i]' + $obj.text + '[/i]');
            });
			
            $("#commentLink").click(function() {
											var $obj = $("#F_comment").getSelection();
               								$("#F_comment").replaceSelection('[url=' + $obj.text + ']' + $obj.text + '[/url]');
            });
			
            $("#commentPreview").click(function() {
											commentFuzz();
											
            });
			
            $("#commentLogin").click(function() {
											loginFuzz();
											
            });
			
	function commentFuzz(){
		
			if ($("#fuzz")[0]){
				$("#fuzz").remove();
				$("#prevFuzz").remove();
				$("object").show();
				$("select").show();
				$("embed").show();
				return false;
			}
			
			$('body').append("<div id=\"fuzz\"></div>");
			$("#fuzz").css("height", $('body').height());
			$("object").hide();
			$("select").hide();
			$("embed").hide();
			
			
			$('body').append("<div id=\"prevFuzz\"></div>");
			$("#prevFuzz").css("width", 640);
			
			var $top = document.documentElement.scrollTop + Math.round(document.documentElement.clientHeight/4);
			$("#prevFuzz").css("top", $top);
			$("#prevFuzz").css( 'left', Math.round(($('body').width() - $('#prevFuzz').width())/2) - 20 );
			
			
			var queryString = $('#formWideoComment').formSerialize(); 
			
			$.ajax({
			   type: "POST",
			   //url: "/kk.php",
			   url: "/wideo/komentarz",
			   data: queryString,
			   success: function(msg){ $("#prevFuzz").html( msg ) },
			   error: function(XMLHttpRequest, textStatus, errorThrown){ 
			   																	alert( textStatus  + ': status ' +  XMLHttpRequest.status);																				
																				
																				}
			 });			
			
			
			
			$("#prevFuzz").html( 'otwieranie...' );	
			
			
			$("#fuzz").click(function(){
											$(this).remove();
											$("#prevFuzz").remove();
											$("object").show();
											$("select").show();
											$("embed").show();
									  })		
			$("#prevFuzz").click(function(){
											$("#fuzz").remove();
											$("#prevFuzz").remove();
											$("object").show();
											$("select").show();
											$("embed").show();
									  })		
	}


	function showRequest(){
		alert('ddd');
	}
	
});

function loginFuzz() {
			if ($("#fuzz")[0]){
				$("#fuzz").remove();
				$("#prevFuzz").remove();
				$("object").show();
				$("select").show();
				$("embed").show();
				return false;
			}
			
			$('body').append("<div id=\"fuzz\"></div>");
			$("#fuzz").css("height", $('body').height());
			$("object").hide();
			$("select").hide();
			$("embed").hide();
			
			
			$('body').append("<div id=\"prevFuzz\"></div>");
			$("#prevFuzz").css("width", 400);
			
			var $top = document.documentElement.scrollTop + Math.round(document.documentElement.clientHeight/4);
			$("#prevFuzz").css("top", $top);
			$("#prevFuzz").css( 'left', Math.round(($('body').width() - $('#prevFuzz').width())/2) - 20 );
			
			
	
			$.ajax({
			   type: "POST",
			   url: "/wideo/login",
			   data: "",
			   contentType: "text/plain charset=iso-8859-2",
			   success: function(msg){ $("#prevFuzz").css('background','#FFFFFF');$("#prevFuzz").html( msg ) },
			   error: function(XMLHttpRequest, textStatus, errorThrown){ 
			   																	alert( textStatus  + ': status ' +  XMLHttpRequest.status);																				
																				
																				}
			 });			
			
			
			
			$("#prevFuzz").html( 'otwieranie...' );	
			
			
			$("#fuzz").click(function(){
											$(this).remove();
											$("#prevFuzz").remove();
											$("object").show();
											$("select").show();
											$("embed").show();
									  })		
	}
