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

//*************************************** J Q U E R Y ****************************************************************
$(document).ready(function() {
	
    if(document.getElementById("sortListBasic")){
        
	    $("#sortListBasic").sortable({
	
	        revert:false,
	        cursor: "move",
	        dropOnEmpty: true,
	        scroll:false,
	        tolerance: 'pointer',
	        helper: 'clone',
	        'placeholder':'placeholder'
	
	 	});
	 	
	 	$("#sortListBasic").disableSelection();	 	
    }

 	$("#sortList").sortable({
 	
 	    axis: "y",
        revert:false,
        cursor: "move",
        dropOnEmpty: false,
        scroll:false,
        tolerance: 'pointer',
        helper: 'clone'
 	
 	});
 	
 	$("#sortListVip").sortable({
 	
 	    axis: "y",
        revert:false,
        cursor: "move",
        dropOnEmpty: false,
        scroll:false,
        tolerance: 'pointer',
        helper: 'clone'
        
 	
 	});
 	
 	 	
 	$(".rightSlide").mouseover(function(){
 	
 	   stop = 1;
 	   setSide('right');
 	   	
 	});
 	
 	$(".rightSlide").mouseout(function(){
 	
 	   stop = 0;
 	     	
 	});
 	
 	$(".leftSlide").mouseover(function(){
 	
 	   stop = 1;
 	   setSide('left');
 	   	
 	});
 	
 	$(".leftSlide").mouseout(function(){
 	
 	   stop = 0;
 	     	
 	});
 	
 	
 	// Tlacitka slideshow	
	$('div#news-block h2').eq(0).mouseover(function(){
		$('div#actuality-blog-content').cycle('pause');		
		$('div#extra a').eq(0).click();
		
		return false;
		
	});
	$('div#news-block h2').eq(0).mouseout(function(){		
		$('div#actuality-blog-content').cycle('resume');		
		return false;		
	});
	
	$('div#news-block h2').eq(1).mouseover(function(){		
		$('div#actuality-blog-content').cycle('pause');
		$('div#extra  a').eq(1).click();
		
		return false;
		
	});
	$('div#news-block h2').eq(1).mouseout(function(){		
		$('div#actuality-blog-content').cycle('resume');		
		return false;		
	});
	
	$('div.blog').mouseover(function(){		
		$('div#actuality-blog-content').cycle('pause');
		$('div#extra  a').eq(1).click();
		
		return false;
		
	});
	$('div.blog').mouseout(function(){		
		$('div#actuality-blog-content').cycle('resume');		
		return false;		
	});
	
	$('div.actu').mouseover(function(){		
		$('div#actuality-blog-content').cycle('pause');
		$('div#extra  a').eq(0).click();
		
		return false;
		
	});
	$('div.actu').mouseout(function(){		
		$('div#actuality-blog-content').cycle('resume');		
		return false;		
	});
	
	quickSearchInit('searchInput','searchContent'); 
 	quickSearchInit('searchInput2','searchContent2'); 	
		
 	 	 	
});

function quickSearchInit(searchInput,searchContent){

	if(document.getElementById(searchInput)){
 	
 		$('input#'+searchInput).quicksearch('ul.'+searchContent+' li');
		
		$('input#'+searchInput).focus(function () {
			$('ul.'+searchContent).show();
		 	$('ul.'+searchContent+' li').show();
		});
		
 		$("body").click(function(e){
		  //you can then check what has been clicked
		   var target = $(e.target);
  
		   if(!target.is("input#"+searchInput)){
			   if($('ul.'+searchContent).is(':visible')){
		 			$('ul.'+searchContent).hide();
		 			$('ul.'+searchContent+' li').hide();
		 	   }
	 	   }
		});
		 		
 	}
}


var stop = "5";
function setSide(side){
    
    if(this.stop == 1){
        
	    var left    = $("#program").css("left");
	    var intLeft = Number(left.substring(0,left.length - 2));  
	    var width   = $("#program").css("width");
	    var speed   = 20;
	    
	    width = Number(width.substring(0,width.length - 2));
	    width = width - 23.9;
        width=width.toFixed(3);
	    speed = width / speed
	     
	    if(side == "left"){ 
	    
	        var d = intLeft + speed ;
            d=d.toFixed(3); 
	        if(intLeft == 0)return;
            $("#program").css("left",d+"cm");
 	        setTimeout("setSide('left')",60);
 	        
	    }else{ 
	    
	        var d = intLeft - speed ; 
            d=d.toFixed(3); 
	        //alert(' left = '+intLeft+" d = "+d+' width = '+width);
	        if(intLeft == -width)return;
	        $("#program").css("left",d+"cm");
            setTimeout("setSide('right')",60);     
              
	    }	        
        
    }else{
        
        return;
    }
}

function addVideoPlaylist(element){
    
    var videoID = $(element).find("input[name='videoID']").val();
    var title    = $(element).find("input[name='videoTitle']").val();
    
    $("input#searchInput").val(title);
    
    $.ajax({
        type: "POST",
        url: "/admin/helper/set-video",
        data: "videoID="+videoID,
        success: function(html){
             $("div.anotation").html(html);          
        }

    }); 
}


function getVideos(url) {

    $("div.animationVideo")
        .ajaxStart(function(){
            $(this).show();
        })
        .ajaxComplete(function(){
            $(this).hide();
        });
        
    $.ajax({
	    type: "POST",
		url: "/admin/helper/get-videos",
		data: "url="+url,
		success: function(html){   

             location.reload(true); 

        }

		});     
	
}

function regenerateImage(file,folder,id,trygenerate,footage,edit){

    $("div.animation"+id)
        .ajaxStart(function(){
            $(this).show();
        })
        .ajaxComplete(function(){
            $(this).hide();
        });

    var second;
    
    if(trygenerate){
        second = 5;
    }else{
        second = $(".getNewVideos input[name=second"+id+"]").val();
    }
    if(second != ""){
        
        if(second > 0){
        
            if(footage >= second || footage == ''){
            
			    $.ajax({
					type: "POST",
					url: "/admin/helper/regenerate-image",
					data: "second="+second+"&file="+file+"&folder="+folder+"&edit="+edit,
					success: function(html){    
				        
				        location.reload(true);          
			
			        }
			
				}); 
			
			}else{
				alert("Zadali jste počet sekund vyšší než je délka videa! Náhled nebude vygenerován! ");
			}
		
		}else{
		    alert("Počet sekund musí být větší jak 0!");
		}
		
	}else{
	    alert("Nezadali jste počet sekund k vytvoření náhledu!");
	}

}

function saveSortedList(controler,sortlist){
    
    var rowNumber = $('#'+sortlist+' li').size();
    var sort = new Array();
    
    for(i = 0;i < rowNumber;i++){
    
        sort[i] = $('#'+sortlist+' li').eq(i).attr("id");
         
    }
    
    $.ajax({
		type: "POST",
		url: "/admin/helper/savesortedlist",
		data: "sort="+sort+"& control="+controler,
		success: function(html){
		    
		    $('div.sortMessage').css("display","inline-block");
		    $('div.sortMessage').html("Pořadí úspěšně uloženo");
            
			}

	});    

}

function savePlaylist(type){
    
    var rowNumber = $('#sortList li').size();
    var sort = new Array();
    
    for(i = 0;i < rowNumber;i++){
    
        sort[i] = $('#sortList li').eq(i).attr("id");
         
    }
    
    $.ajax({
		type: "POST",
		url: "/admin/helper/saveplaylist",
		data: "sort="+sort+"&type="+type,
		success: function(html){
		    
		    $('div.sortMessage').css("display","inline-block");
		    $('div.sortMessage').html("Pořadí úspěšně uloženo");
            
			}

	});    

}


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[name=hidden]').val(id);
    
    if(id == 5){
    
        $('#pridat_foto').css("display","none");   
    
    }

}

function addLink(){
    
    oldId = $('.currentContent p input[name=oldHiddenLink]').val();
    oldId++;
    
    id = $('.currentContent p input[name=hiddenLink]').val();
    id++;
    link = " <fieldset><p><label>"+oldId+".nadpis</label><input type=\"text\" name=\"titleLink[]\" /></p><p><label>"+oldId+".nadpis(En)</label><input type=\"text\" name=\"titleLinkEn[]\" /></p><p><label>"+oldId+".odkaz</label><input type=\"text\" name=\"link[]\" value=\"http://\" /></p><p><label>"+oldId+".popis</label><input type=\"text\" name=\"description[]\" /></p><p><label>"+oldId+".popis(En)</label><input type=\"text\" name=\"descriptionEn[]\" /></p> </fieldset>";
    $('.currentContent div.links').append(link);
    $('.currentContent p input[name=hiddenLink]').val(id);
    $('.currentContent p input[name=oldHiddenLink]').val(oldId);
}

function addVideo(){
    
    oldId = $('.currentContent p input[name=oldHiddenVideo]').val();
    oldId++;
    
    id = $('.currentContent p input[name=hiddenVideo]').val();
    id++;
    link = " <fieldset><p><label>"+oldId+".nadpis</label><input type=\"text\" name=\"titleVideo[]\" /></p><p><label>"+oldId+".nadpis(En)</label><input type=\"text\" name=\"titleVideoEn[]\" /></p><p><label>"+oldId+".video</label><input type=\"text\" name=\"linkVideo[]\" /></p> </fieldset>";
    $('.currentContent div.videos').append(link);
    $('.currentContent p input[name=hiddenVideo]').val(id);
    $('.currentContent p input[name=oldHiddenVideo]').val(oldId);
}

function addActualityLink(){
        
    id = $('.currentContent p input[name=hiddenLink]').val();
    id++;
    link = " <fieldset><p><label>"+id+".nadpis</label><input type=\"text\" name=\"titleLink[]\" /></p><p><label>"+id+".nadpis(En)</label><input type=\"text\" name=\"titleLinkEn[]\" /></p><p><label>"+id+".odkaz</label><input type=\"text\" name=\"link[]\" value=\"http://\" /></p><p><label>"+id+".popis</label><input type=\"text\" name=\"description[]\" /></p> <p><label>"+id+".popis(En)</label><input type=\"text\" name=\"descriptionEn[]\" /></p></fieldset>";
    $('.currentContent div.links').append(link);
    $('.currentContent p input[name=hiddenLink]').val(id);
}


function addVideoLink(){
        
    id = $('.currentContent p input[name=hiddenVideo]').val();
    id++;
    link = " <fieldset><p><label>"+id+".nadpis</label><input type=\"text\" name=\"titleVideo[]\" /></p><p><label>"+id+".nadpis(En)</label><input type=\"text\" name=\"titleVideoEn[]\" /></p><p><label>"+id+".video</label><input type=\"text\" name=\"linkVideo[]\" /></p> </fieldset>";
    $('.currentContent div.videoss').append(link);
    $('.currentContent p input[name=hiddenVideo]').val(id);
}


function addPLayTime(){

    count = $('.currentContent p input[name=hiddenPLayTimeCount]').val();
    count++;
    
    date = $('.currentContent div.playTime fieldset:first select[id = date] ').html();
    date = date.replace("selected"," ");
    stage = $('.currentContent div.playTime fieldset:first select[id = stage] ').html();
    stage = stage.replace("selected"," ");
    from = $('.currentContent div.playTime fieldset:first select[id = from] ').html();
    from = from.replace("selected"," ");
    to = $('.currentContent div.playTime fieldset:first select[id = to] ').html();
    to = to.replace("selected"," ");

    playTime = "<fieldset><legend></legend></label><label>Ve dne:</label><select name=\"date[]\">"+date+"</select><br /><label>Na stagei:</label><select name=\"stage[]\">"+stage+"</select><br /><label>Od - do:</label><select name=\"from[]\">"+from+"</select> -- <select name=\"to[]\">"+to+"</select><br /></fieldset>";
    $('.currentContent div.playTime').append(playTime);
    $('.currentContent p input[name=hiddenPLayTimeCount]').val(count);

}


function addNewDay(){
    
    id = $('.currentContent div.date input:last').attr('id');
    id++;
    //photo = "<label for=\"text\"> &nbsp; </label><input id=\""+id+"\" type=\"file\" name=\"photo"+id+"\" size=\"47\">";  
    date = "<p><label for=\"date\">Datum "+id+".dne: </label> <input id=\""+id+"\" type=\"text\" name=\"date[]\" value=\"\" />";
    $('.currentContent div.date').append(date);
    $('.currentContent p input[type=hidden]').val(id);
    
}

function content(id){

    itemek = $('div.currentContent select').val();
    if(itemek == 0){
        itemek = id;
    }
    
    $.ajax({
		type: "POST",
		url: "/admin/helper/obsah",
		data: "item="+itemek,
		success: function(html){

             $("div.contentItem").html(html);   

			}

	});

}

function getFotogallery(folder){

    $("div.loading")
        .ajaxStart(function(){
            $(this).show();
        })
        .ajaxComplete(function(){
            $(this).hide();
        });
    

    itemek = $('div.currentContent select').val();
    if(itemek == 0){
        itemek = folder;
    }
    $.ajax({
		type: "POST",
		url: "/admin/helper/fotogallery",
		data: "item="+itemek,
		success: function(html){
              
             $("div.contentItem").html(html);   

			}

	});

}

function selectAll(){

    $('div.currentContent div.newPhoto input#add').attr("checked",true);

}

function getForm(item,parrentlevel,captcha,name,title,text,email){
    
    html =  '<center><div class="reaction"><p class="reaction"><label for="name">Jméno:</label><input id="name" type="text" name="nameReaction" value="'+name+'" />';
    html +=    '<label class="email" for="email">Email:</label><input id="email" type="text" name="emailReaction" value="'+email+'" />';
	html += '</p>';
	            
	html += '<p class="reaction"><label for="title"></label>Re: '+title+'<input id="title" type="hidden" name="titleReaction" value="Re:'+title+'" /></p>';
	html += '<p class="reaction"><label for="name">Text:</label><textarea id="text" name="textReaction">'+text+'</textarea></p>';
	html += '<p class="reaction"><input id="hidden" type="hidden" name="hiddenReaction" value="'+parrentlevel+'" /></p>';
	html += '<p><label></label><img src="/Public/Captcha/'+captcha+'" /><input type="text" name="hiddenCaptcha" /></p>';
	html += '<p class="reaction button"><input id="button" type="submit" name="addReaction" value="Přidat" /></p></div></center>';
	
    $("div.answer"+item).html(html);
    
    if($("div.answer"+item).css("display")=="block"){
        $("div.answer"+item).slideUp("slow");
    }else{
        $("div.answer"+item).slideDown("slow");
    }


}

function lan(lang){
    
    $.ajax({
		type: "POST",
		url: "/jazyk/index/",
		data: "lang="+lang,
		success: function(html){
              
             location.reload(true);   

			}

	});
    

}

function lanPl(lang){
    
    $.ajax({
		type: "POST",
		url: "/jazyk/index/",
		data: "lang="+lang,
		success: function(html){
              
             window.location="/";
   

			}

	});
    

}

function setTheme(){

    theme = $('input[name=theme]').val();

    $.ajax({
		type: "POST",
		url: "/helper/theme/",
		data: "theme="+theme,
		success: function(html){
			if (theme != '') {
				$("div.oznameni").html("Nová témata podléhají schválení. Pokud bude Vaše téma schváleno, v brzké době se zobrazí na webu. Děkujeme za pochopení.");  
			} else {
				$("div.oznameni").html("Nebylo zadáno žádné téma.");  
			}
			$("input#theme").val("");
		}

	});

}

    function startUpload(){
    
        $('p.upload_process').css("visibility",'visible');
        return true;

    }
    
    function stopUpload(success){
   
      var result = '';
      if (success == 1){
  
	      $('p#result').html('<span class="msg">Soubor úspěšně nahrán<\/span>');
	      $();
  
      }else {
      
          $('p#result').html('<span class="emsg">Došlo k chybě ři nahrávání!<\/span>');
          
      }
      $('p.upload_process').css("visibility",'hidden');
  
      return true;
  
      }
      
     function showAddedMp3(title){
         
         $('div.addedMp3').css('display','block');
         $('div.addedMp3').html(title);
         
         $('input[name = mp3Title]').val("");
         $('input[name = mp3]').val("");
     
     }
     
     function getCustValue(element,id)
	 {
	    title = $(element).text();
	    
	    html  = '<li id="'+id+'">';
	    html += '<div class="listTitleItem cross ">'+title+'</div>';				
		html += '<div class="listItem">';
		html += '    <a onclick="deleteCustValue('+id+');return false;" title="Smaž" href="/">';
		html += '        <img alt="Smaž" src="/Public/Images/Admin/delete.gif" />';
		html += '    </a>';
		html += '</div>';
		html += '<br id="endFloat" />';
	    html += '</li>';
	    
	    oldHtml = $('div.currentContent ul#sortList').html();
	    $('div.currentContent ul#sortList').html(html);
	    $('div.currentContent ul#sortList').append(oldHtml);
	        
	    $('div.cus_list ul li').hide();
	    $('div.cus_list').hide();
	    
	    
	    	    
	    
	 }
	 
	function getCustValueList(element)
	{
	    //$('input.custSearch').val( $(element).text() );
	    $('input.custSearchList').val( $(element).text() );
	    $('div.cus_list ul li').hide();
	    $('div.cus_list').hide();
	}

	function hideCust()
	{
	   $('div.cus_list ul li').hide();
	   $('div.cus_list').hide();
	}
	
		
	
	function deleteCustValue(id)
	 {

	    $('div.currentContent ul#sortList li#'+id).remove();

	 }
	 
	 function programme(id){
	    
	    if($("ul.#mp3-"+id).css("display")=="block"){
	       	
        	$("div.actorlist H5."+id).addClass("actorlist-close");
        	$("div.actorlist H5."+id).removeClass("actorlist-open");
        	$("ul.#mp3-"+id).slideUp("slow");
        }else{

            $("div.actorlist H5."+id).addClass("actorlist-open");
            $("div.actorlist H5."+id).removeClass("actorlist-close");
        	$("ul.#mp3-"+id).slideDown("slow");
    	}
	 
	 }
	
	    
	    
	 function setMp3(type,id){

	    $.ajax({
			type: "POST",
			url: "/helper/setmp3",
			data: "type="+type+"&id="+id,
			success: function(html){
			
	             $("div#actor-content-info").html(html);   
	
				}
	
		});
	
	} 
	
	function setVideo(type,id){

	    $.ajax({
			type: "POST",
			url: "/helper/setvideo",
			data: "type="+type+"&id="+id,
			success: function(html){
			
	             $("div#actor-content-info").html(html);   
	
				}
	
		});
	
	} 
	
	function homepageVideo(){

	    $.ajax({
			type: "POST",
			url: "/helper/homepagevideo",
			success: function(html){
			     $("ul#player-choose li").eq(0).removeClass();
			     $("ul#player-choose li").eq(0).addClass("active");
			     
			     $("ul#player-choose li").eq(1).removeClass();
			     $("ul#player-choose li").eq(1).addClass("inactive");
			     
			     $("ul#player-choose li a").eq(0).removeAttr("id");
			     $("ul#player-choose li a").eq(0).attr("id","player-tv-active");
			     
			     $("ul#player-choose li a").eq(1).removeAttr("id");
			     $("ul#player-choose li a").eq(1).attr("id","player-radio-inactive");
			     
	             $("div.radio-tv").html(html);   
	
				}
	
		});
	
	}
	
	function homepageRadio(){

	    $.ajax({
			type: "POST",
			url: "/helper/homepageradio",
			success: function(html){
			     $("ul#player-choose li").eq(0).removeClass();
			     $("ul#player-choose li").eq(0).addClass("inactive");
			     
			     $("ul#player-choose li").eq(1).removeClass();
			     $("ul#player-choose li").eq(1).addClass("active");
			     
			     $("ul#player-choose li a").eq(0).removeAttr("id");
			     $("ul#player-choose li a").eq(0).attr("id","player-tv-inactive");
			     
			     $("ul#player-choose li a").eq(1).removeAttr("id");
			     $("ul#player-choose li a").eq(1).attr("id","player-radio-active");
			     
	             $("div.radio-tv").html(html);   
	
				}
	
		});
	
	}
	
	function addLeftBanner(banner){
	
	    html = '<embed wmode="transparent" width="750" height="167" quality="high" name="mymovie" id="mymovie" style="" src="/Public/Images/Banner/'+banner+'" type="application/x-shockwave-flash"/>';
	    $("div#info-content div.left").html(html);
                    
	}
	
	function addRightBanner(banner){
	
	    html = '<embed wmode="transparent" width="250" height="167" quality="high" name="mymovie" id="mymovie" style="" src="/Public/Images/Banner/'+banner+'" type="application/x-shockwave-flash"/>';
	    $("div#info-content div.right").html(html);
                    
	}
	
	function addSmallerBanner(banner){
	    
	    html = '<embed class="main-page-add" wmode="transparent" width="458px" height="60px" quality="high" name="mymovie" id="mymovie" style="" src="/Public/Images/Banner/'+banner+'" type="application/x-shockwave-flash"/>';
	    $("div#add-block div.top").html(html);
	
	}
	
	function addSmallBanner(banner){
	    
	    html = '<embed class="main-page-add" wmode="transparent" width="458px" height="90px" quality="high" name="mymovie" id="mymovie" style="" src="/Public/Images/Banner/'+banner+'" type="application/x-shockwave-flash"/>';
	    $("div#add-block div.bottom").html(html);
	
	}
	
$(function(){

	if(document.getElementById("actuality-blog-content")){
		 $('div#actuality-blog-content').cycle({
			 fx: 'fade',
			 timeout: 0,
			 pager: '#extra',
			 before: function(currSlideElement, nextSlideElement, options, forwardFlag){
			 
			 	if($(nextSlideElement).attr("class")== "actu"){
			 		$("h2.actu").addClass("actu-selected");
			 		$("h2.blog").removeClass("blog-selected");
			 	}
			 	if($(nextSlideElement).attr("class")== "blog"){
			 		$("h2.actu").removeClass("actu-selected");
			 		$("h2.blog").addClass("blog-selected");
			 	}
			 }
		 });
 
	}
	
}); 


function searchInputFocused() {
    $('#fakesearch').hide();
    $('#search').show();
    $('#search').focus();
}

function searchInputBlurred() {
    if ($('#search').attr('value') == '') {
        $('#search').hide();
        $('#fakesearch').show();
    }
}



