jQuery(document).ready(function(){
	   
	   Addr = jQuery('#mins').children().find('.phidden').html();
	   ClipId = jQuery('#mins').children().find('.phidden').next().html();
	   WhenAdd = jQuery('#mins').children().find('.whenAdd').children().html();
	   When = jQuery('#mins').children().find('.whenAdd').children().next().html();
	   Descript = jQuery('#mins').children().find('.descript').children().html();
	   TimeDescript = jQuery('#mins').children().find('.time').children().html();
	   Time = jQuery('#mins').children().find('.time').children().next().html();
	   Page = jQuery('#page_nr').html();
	   jQuery.post('./ajax_php_fun/film.php', { Addr : Addr , ClipId : ClipId, WhenAdd : WhenAdd, When : When, Descript : Descript, TimeDescript : TimeDescript, Time : Time, Page : Page } ,function(data, textStatus) {
			 jQuery("#film").html(data);
	   });
	   
	   jQuery.post('./ajax_php_fun/editComm.php', { ClipId : ClipId } ,function(data, textStatus) {
			 jQuery("#editComents").html(data);
			 acceptAndDelate();
	   });
	   
	   jQuery.post('./ajax_php_fun/readComm.php', { ClipId : ClipId } ,function(data, textStatus) {
			 jQuery("#readComents").html(data);
			 jQuery('#commButt').click(function() {
				 jQuery('#myForm').children().find('.textarea').val('');
				 jQuery('#myForm').children().find('.input').val('');
				 if(jQuery('#myForm').css('display') == 'none') {
					 jQuery('#myForm').css( 'display','block');
				 }else {
					 jQuery('#myForm').css( 'display','none');
				 }
				 jQuery('#inputClipId').val(ClipId);
			 });
	   });
	   
	   jQuery('.cPointer').click(function() {
			jQuery('#myForm').css( 'display','none');
			Addr = jQuery(this).parent().find('.phidden').html();
			ClipId = jQuery(this).parent().find('.phidden').next().html();
			WhenAdd = jQuery(this).parent().next().find('.whenAdd').children().html();
			When = jQuery(this).parent().next().find('.whenAdd').children().next().html();
			Descript = jQuery(this).parent().next().find('.descript').children().html();
			TimeDescript = jQuery(this).parent().next().find('.time').children().html();
			Time = jQuery(this).parent().next().find('.time').children().next().html();
			
			jQuery.post('./ajax_php_fun/film.php', { Addr : Addr, ClipId : ClipId, WhenAdd : WhenAdd, When : When, Descript : Descript, TimeDescript : TimeDescript, Time : Time } ,function(data, textStatus) {
				   jQuery("#film").html(data);
				   jQuery('#commButt').click(function() {
						jQuery('#myForm').children().find('.textarea').val('');
						jQuery('#myForm').children().find('.input').val('');
						if(jQuery('#myForm').css('display') == 'none') {
						    jQuery('#myForm').css( 'display','block');
						}else {
						    jQuery('#myForm').css( 'display','none');
						}
						jQuery('#inputClipId').val(ClipId);
				   });
			});
			
			jQuery.post('./ajax_php_fun/readComm.php', { ClipId : ClipId } ,function(data, textStatus) {
				   jQuery("#readComents").html(data);
			});
			
			jQuery.post('./ajax_php_fun/editComm.php', { ClipId : ClipId } ,function(data, textStatus) {
				   jQuery("#editComents").html(data);
				   acceptAndDelate();
			});
	   });
	   
	   $('#myForm').ajaxForm(function() { 
             jQuery('#myForm').css( 'display','none');
		   ClipId = jQuery('#film').find('.phidden').html();
		   jQuery.post('./ajax_php_fun/readComm.php', { ClipId : ClipId } ,function(data, textStatus) {
				 data = '<div class="oneFilmComm"><h1 class="whoCommFilm">Twój komentarz został wysłany do akceptacji.</h1></div>'+data;
				 jQuery("#readComents").html(data);
		   });
        }); 
	   
});

function href(addr){
	location.assign(addr);
}

function loadPage(text) {
		switch(text) {
			case "produkcje":	window.open('./production.php','productionWindow','width=1024,height=760,resizable=yes,scrollbars=yes');//location.assign("production.php");
						break;
			case "blog":	window.open('./blog','blogWindow','width=1024,height=760,resizable=yes,scrollbars=yes');//location.assign("production.php");
						break;
			default	:	break;
		}
}

function trimLength(textarea, maxChars) {	
	if (textarea.value.length > maxChars) {
        textarea.value = textarea.value.substr(0, maxChars);
    } 
}

function acceptAndDelate() {
	   jQuery('.acceptComm').click(function() {
					 target = jQuery(this).css('display', 'none');
					 Id = jQuery(this).parent().prev().find('.phidden').html();
					 jQuery.post('./ajax_php_fun/editDB.php', { Id : Id, What : 'AcceptComm' } ,function(data, textStatus) {
						     target.siblings(".info").html(data);
					 });
	   });
			  
	    jQuery('.DelateComm').click(function() {
			   Id = jQuery(this).parent().prev().find('.phidden').html();
			   jQuery.post('./ajax_php_fun/editDB.php', { Id : Id, What : 'DelateComm' } ,function(data, textStatus) {
				   jQuery.post('./ajax_php_fun/editComm.php', { ClipId : ClipId } ,function(data, textStatus) {
						 jQuery("#editComents").html(data);
						 acceptAndDelate();
				   });
			   });
	    });
	    
	    jQuery('.responseComm').click(function() {
			  target = jQuery(this).parent().find('.myResponse');
			  jQuery(target).children().find('.textarea').val('');
			  //jQuery(target).children().find('.input').val('');
			  if(jQuery(target).css('display') == 'none') {
					jQuery(target).css( 'display','block');
					
					jQuery(target).ajaxForm(function() { 
						   jQuery(target).css( 'display','none');
						   ClipId = jQuery(target).parent().parent().prev().children().next().next().html();
						   //alert(ClipId);
						   jQuery.post('./ajax_php_fun/editComm.php', { ClipId : ClipId } ,function(data, textStatus) {
								 jQuery("#editComents").html(data);
								 acceptAndDelate();
						   });
					});
					
			  }else {
					jQuery(target).css( 'display','none');
			  }
	    });
	    
	    jQuery('.editResp').click(function() {
			target = jQuery(this).parent().find('.myResponse');
			val = jQuery(target).parent().prev().find('.p_text_r').text();
			jQuery(target).children().find('.textarea').val(val);
			if(jQuery(target).css('display') == 'none') {
					jQuery(target).css( 'display','block');
					jQuery(target).ajaxForm(function() { 
						   jQuery(target).css( 'display','none');
						   ClipId = jQuery(target).parent().parent().prev().children().next().next().html();
						   jQuery.post('./ajax_php_fun/editComm.php', { ClipId : ClipId } ,function(data, textStatus) {
								 jQuery("#editComents").html(data);
								 acceptAndDelate();
						   });
					});
					
			  }else {
					jQuery(target).css( 'display','none');
			  }
	    
	    });
	    
	    jQuery('.delResp').click(function() {
			 Id = jQuery(this).parent().prev().find('.phidden').html();
			 jQuery.post('./ajax_php_fun/editDB.php', { Id : Id, What : 'delResp' } ,function(data, textStatus) {
				    jQuery.post('./ajax_php_fun/editComm.php', { ClipId : ClipId } ,function(data, textStatus) {
						  jQuery("#editComents").html(data);
						  acceptAndDelate();
				    });
			 });
	    });
}
