//****************************************** METODY *****************************************************************

//*************************************** J Q U E R Y ****************************************************************
$(document).ready(function() {
	
	setBorderOfVideo();	
	
 		
 });
 	
 
 function setBorderOfVideo()
 { 	 
 	$("#tv_divVideo").width( $('#tv_divVideo').children(":first").width() );  
 	
 }
 
 function NewComment(param)
	{
	
     var message = $("#textarea").val();
     
     if(message.length <= 0)
     {          
          
          $("#tv_content div.tv_error").text("Nevyplnili jste text");  
             
     }
     else
     {
          // we want to store the values from the form input box, then send via ajax below
          //var fname     = $('#fname').attr('value');
          //var lname     = $('#lname').attr('value'); 
      
               $.ajax({
                    type: "POST",
                    url: "/comments/newcoment/tv/"+param,
                    data: "message="+ message ,
                    success: function(html){
                    
                    	$("div.tv_comments").html(html);
                         //$('form#submit').hide();
                         //$('div.success').fadeIn();
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                            $("#textarea").val('');
                          
                          
                      } 
               });
     }
	

	} // end of method NewComment	
	
	
	function NextComments(param,limit)
	{    
     
          // we want to store the values from the form input box, then send via ajax below
          //var fname     = $('#fname').attr('value');
          //var lname     = $('#lname').attr('value'); 
      
               $.ajax({
                    type: "POST",
                    url: "/comments/nextcoment/tv/"+param+"/limit/"+limit,
                    success: function(html){
                    
                    	$("div.tv_comments").html(html);
                         //$('form#submit').hide();
                         //$('div.success').fadeIn();
                    },
                    complete: function (XMLHttpRequest, textStatus) {                           
                          
                          
                      } 
               });     
	

	} // end of method NewComment
 
	
	
	function addVideourlToInput(value)
 	{ 	
 	
 		$('input[name=videourl]').val(value);   
 	
 	}
 	
 	function confirmF(title,id)
 	{ 		
 		pokracovat = confirm("Opravdu si přejete smazat toto video? \n\n "+title+"\n\n");
 		if(pokracovat)
 		{
 			window.location="/admin/admintv/smazat/id/"+id;
 		}
 	}
 	
 	function slide(tag)
 	{ 	
 	
 		var month = $(tag).next();
 		
 		if( month.is(':hidden') )
 		{
 			
      		month.slideDown("slow");
      	}
      	else
      	{
      		month.slideUp("slow");
      	}      
      	
	}
	
	
	function showArticle(id)
	{    
     
          // we want to store the values from the form input box, then send via ajax below
          //var fname     = $('#fname').attr('value');
          //var lname     = $('#lname').attr('value'); 
      
               $.ajax({
                    type: "POST",
                    url: "/crewblogcontent/showarticle/"+id,
                    success: function(html){
                    
                    	$("div.crewblog_blogText").html(html);
                         //$('form#submit').hide();
                         //$('div.success').fadeIn();
                    },
                    complete: function (XMLHttpRequest, textStatus) {                           
                          
                          
                      } 
               });     
	

	} // end of method NewComment
	
	function showEditArticle(id)
	{    
     
          // we want to store the values from the form input box, then send via ajax below
          //var fname     = $('#fname').attr('value');
          //var lname     = $('#lname').attr('value'); 
      
               $.ajax({
                    type: "POST",
                    url: "/crewblogcontent/edit/"+id,
                    success: function(html){
                    
                    	$("div.crewblog_blogText").html(html);
                         //$('form#submit').hide();
                         //$('div.success').fadeIn();
                    },
                    complete: function (XMLHttpRequest, textStatus) {                           
                          
                          
                      } 
               });     
	

	} // end of method NewComment
	
	function showArticleKomunita(id)
	{
          // we want to store the values from the form input box, then send via ajax below
          //var fname     = $('#fname').attr('value');
          //var lname     = $('#lname').attr('value'); 
      
               $.ajax({
                    type: "POST",
                    url: "/komunita/showcontent/"+id,
                    success: function(html){
                    
                    	$("div.crewblog_blogText").html(html);
                         //$('form#submit').hide();
                         //$('div.success').fadeIn();
                    },
                    complete: function (XMLHttpRequest, textStatus) {                           
                          
                          
                      } 
               });     
	

	} // end of method NewComment
	
	function editCrewblogData(id)
	{    
     	var idecko = $('#testicek textarea:first-child').attr("id");    	
		var edit_title = $('input[name=edit_title]').val();
		var edit_date = $('input[name=edit_date]').val();		
		var edit_text = tinyMCE.get(idecko).getContent();
		var edit_author = $('input[name=edit_author]').val();
		var edit_saveData = $('input[name=edit_saveData]').val();	
					
		 $.ajax({
                    type: "POST",
                    url: "/crewblogcontent/edit/"+id,
                    data: "edit_title="+ edit_title +"&edit_date="+ edit_date +"&edit_text="+ edit_text +"&edit_author="+ edit_author +"&edit_saveData="+ edit_saveData ,
                    success: function(html){
                    
                    	$("div.crewblog_blogText").html(html);
                         //$('form#submit').hide();
                         //$('div.success').fadeIn();
                    },
                    complete: function (XMLHttpRequest, textStatus) {                          
                          $("p.edit_success").html("údaje úspěšně uloženy");
                          
                      } 
               }); 
      
                   
	

	} // end of method NewComment
	
	function removeFoto(fotoname,divID,id)
	{   		
	
		jConfirm('Opravdu si přejete smazat tuto fotku?', 'Smazat', function(result) {
		
			if(result)
			{
				 $.ajax({
		                    type: "POST",
		                    url: "/crewblogcontent/editfoto/"+id,
		                    data: "fotoname="+ fotoname +"&articleFotoID="+ divID,
		                   	
		                    complete: function (XMLHttpRequest, textStatus) {
		                          $("#edit_foto_"+divID).fadeOut("slow");
		                          
		                      } 
		          }); 
		    }
		   
      	});

	}
	
	function removeArticle(id)
	{   		
	
		jConfirm('Opravdu si přejete smazat tento článek?', 'Smazat', function(result) {
		
			if(result)
			{
				 $.ajax({
		                    type: "POST",
		                    url: "/crewblog/smazat/"+id,
		                    		                   	
		                    complete: function (XMLHttpRequest, textStatus) {
		                          
		                          window.location="/crewblog";
		                          
		                      } 
		          }); 
		          
		    }
		   
      	});
         
	}
	
	function removeVideo(id,articleId)
	{			
		$.ajax({
		         type: "POST",
		         url: "/crewblogcontent/removevideo/"+id+"/"+articleId,                   	
		         success: function(html){                   
	             $("#edit_videos_content").html(html);
	                   //$('form#submit').hide();
	                   //$('div.success').fadeIn();
                 },	                   	
		         complete: function (XMLHttpRequest, textStatus) {		                          
		                          
		         }  
		 }); 
	}
	
	function addVideo(articleId)
	{	
		$("#testLoading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
		
		var videoname = $('input[name=edit_video_text]').val();
		if(videoname == "")
		{
			$("#crewblog_no_video").text("Nevyplnili jste video !");
		}
		else
		{			
			videoname = videoname.replace(/&/gi,"@");
			$.ajax({
			
			         type: "POST",
			         url: "/crewblogcontent/addvideo/"+articleId,   
			         data: "videoname="+videoname,               	
			         success: function(html){   
			                         
		             	$("#edit_videos_content").html(html);
		                   
	                 },	                   	
			         complete: function (XMLHttpRequest, textStatus) {		                          
			              	            
			         }  
			 }); 
		}
	}
	
		   
     function addPhoto(){
    
	    id = $('.currentContent p.photos input:last').attr('id');
	    id++;
	    photo = "<label for=\"text\"> &nbsp; </label><input id=\""+id+"\" type=\"file\" name=\"photo"+id+"\" size=\"47\">";
	    $('.currentContent p.photos').append(photo);
	    $('.currentContent p input[type=hidden]').val(id);
	    
	    if(id == 5){
	    
	        $('#pridat_foto').css("display","none");   
	    
	    }

	}
	
	function addVid(){
    
	    id = $('.currentContent p.videos input:last').attr('id');
	    id++;
	    photo = "<label> &nbsp; </label><input id=\""+id+"\" type=\"text\" name=\"video"+id+"\" size=\"52\">";
	    $('.currentContent p.videos').append(photo);
	    $('.currentContent p input[name=hiddenVideo]').val(id);
    
	}



	 	

		
	
	
	
	

