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

//*************************************** J Q U E R Y ****************************************************************
var stop = "5";
$(document).ready(function() {


    // obsluha formulï¿½ï¿½e s checkboxy ve volbï¿½ch pro vyhledï¿½vï¿½nï¿½
    $("#header form div input.all").click(function(){
        if($(this).attr("checked") == true)
        {
            $("#header form div input.eee").removeAttr("checked");
        }
    });
 
 	$('#header form div a.close').click(function() {
      $('#header form div').fadeOut(400);
      return false;
      
  	});
  	
  	$('#header form input.vstup').click(function() {
      // $('#header form div').css({ display: "block" });
       $('#header form div').fadeIn(400);
      
 	});
 
 	$('#header form input.vyhledat').hover(function() {
 		$(this).css('cursor','hand');
 	});
 	
 	
 	if($('div.bilboard div.text').text() != ""){
	 	$('div.bilboard div.text').marquee('pointer').mouseover(function () {
	            $(this).trigger('stop');
	        }).mouseout(function () {
	            $(this).trigger('start');
	        }).mousemove(function (event) {
	            if ($(this).data('drag') == true) {
	                this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
	            }
	        }).mousedown(function (event) {
	            $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
	        }).mouseup(function () {
	            $(this).data('drag', false);
	        })
	
	}
	
	$("div#slideshow div.prew").mouseover(function(){
 	
 	   stop = 1;
 	   setSide('right');
 	   	
 	});
 	
 	$("div#slideshow div.prew").mouseout(function(){
 	
 	   stop = 0;
 	     	
 	});
 	
 	$("div#slideshow div.next").mouseover(function(){
 	
 	   stop = 1;
 	   setSide('left');
 	   	
 	});
 	
 	$("div#slideshow div.next").mouseout(function(){
 	
 	   stop = 0;
 	     	
 	});
 	
 	if(document.getElementById("slideshow")){
 	    var imgSize = $("div#slideshow ul img").size();
 	    var totalWidth = 0; 
 		for(i = 0;i < imgSize;i++ ){
 		    totalWidth = totalWidth + $("div#slideshow ul img").eq(i).width()+2;
 		}

 		$("div#slideshow ul").css("width",totalWidth);
 	}
 	
 	quickSearchInit('searchInput','searchContent');
 	
    setInterval("zmenBarvu()",350) ;
    
    $('#sliderID').DDSlider({
		selector: '.slider_selector'
	}); 
     	 	 	
});

var barva1 = "#FFFFFF";
var barva2 = "#FFE744";
var aktualniBarva = barva1; // počáteční nastavení

	
function zmenBarvu(){
    if(aktualniBarva == barva1){
    	$("img#battle").css("border-color",barva2);
    	aktualniBarva = barva2;
    }else{
    	$("img#battle").css("border-color",barva1);
    	aktualniBarva = barva1;
    }
} 

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();
		 	   }
	 	   }
		});
		 		
 	}
}

function setSide(side){
    
    if(this.stop == 1){
        
	    var left    = $("div#slideshow ul").css("left");
	    var intLeft = Number(left.substring(0,left.length - 2));  
	    var width   = $("div#slideshow ul").css("width");
	    var speed   = 2;
	    
	    width = Number(width.substring(0,width.length - 2));
        width=width.toFixed(3);
	    //speed = width / speed
	     
	    if(side == "left"){ 
	    
	        var d = intLeft + speed ;
            d=d.toFixed(3); 
	        if(intLeft == 0)return;
            $("div#slideshow ul").css("left",d+"px");
 	        setTimeout("setSide('left')",5);
 	        
	    }else{ 
	    
	        var d = intLeft - speed ; 
            d=d.toFixed(3); 
	        //alert(' left = '+intLeft+" d = "+d+' width = '+width);
	        var l = 600 - width; 
	        if(intLeft <= l)return;
	        $("div#slideshow ul").css("left",d+"px");
            setTimeout("setSide('right')",5);     
              
	    }	      
        
    }else{
        
        return;
    }
}



function addPhoto1(){
    
    id = $('.currentContent p.photos input:last').attr('id');
    id++;
    photo = "<label> &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 addName(){

    var i = $('input[type=hidden]').val();
    i++;
    var battle = '<p>'+
					    '<label for="login">'+i+'.jméno: </label>'+
					    '<input id="login" type="text" name="name[]" size="20" />'+
					'</p>'+
					'<p>'+
					    '<label for="login">'+i+'.věk: </label>'+
					    '<input class="age" id="login" type="text" name="age[]" size="20" />'+
					'</p>';
	$('input[type=hidden]').val(i);				
    $('div.battle-names').append(battle);

}

function addPhoto2(){
    
    id = $('.currentContent p.photos input:last').attr('id');
    id++;
    photo = "<br /><br /><label> &nbsp; </label><input id=\""+id+"\" type=\"file\" name=\"photo"+id+"\" size=\"47\"><label> &nbsp; </label><br />Link:<input id=\""+id+"\" type=\"text\" name=\"link"+id+"\" size=\"47\">";
    $('.currentContent p.photos').append(photo);
    $('.currentContent p input[type=hidden]').val(id);
    
    if(id == 5){
    
        $('#pridat_foto').css("display","none");   
    
    }

}

function addPhoto3(){
    
    id = $('.add-article p.photos input:last').attr('id');
    id++;
    photo = "<label> &nbsp; </label><input id=\""+id+"\" type=\"file\" name=\"photo"+id+"\" size=\"38\">";
    $('.add-article p.photos').append(photo);
    $('.add-article p input[type=hidden]').val(id);
    
    if(id == 5){
    
        $('#pridat_foto').css("display","none");   
    
    }

}

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

		}

	});
   

}

function getSubcategory(id,subcategoryID){
	 
	    if(!id){
	    	id = $("p select[name=category]").val();
        }
		$.ajax({
			type: "POST",
			url: "/admin/helper/get-subcategory",
			data: "categoryID="+id+"&subCategoryID="+subcategoryID,
			success: function(html){      
	             $("div.subcategory").html(html);  
	        }
	
		});  
		
		  
	
	}
	
function setComment(homeID){
    
    var comment  = $("div.textArea textarea[name=text]").val();
    var login    = $("div.login input[name=login]").val();
    var password = $("div.login input[name=password]").val();

    comment = encodeURIComponent(comment);

	$.ajax({
		type: "POST",
		url: "/helper/comment",
		data: "comment="+comment+"&homeID="+homeID+"&login="+login+"&password="+password,
		success: function(html){      
	         $("div.article form").html(html);  
	    }
	
	});  

}

function setVideoComment(videoID){
    
    var comment  = $("div.textArea textarea[name=text]").val();
    var login    = $("div.login input[name=login]").val();
    var password = $("div.login input[name=password]").val();

    comment = encodeURIComponent(comment);

	$.ajax({
		type: "POST",
		url: "/helper/video-comment",
		data: "comment="+comment+"&videoID="+videoID+"&login="+login+"&password="+password,
		success: function(html){      
	         $("div.article form").html(html);  
	    }
	
	});  

}

function getCrew(char){
	$.ajax({
		type: "POST",
		url: "/helper/crew",
		data: "char="+char,
		success: function(html){      
	         $("div.cL").html(html);  
	    }
	
	});  
	
}

function slide(tag)
 	{ 	
 	
 		var month = $(tag).next();
 		
 		if( month.is(':hidden') )
 		{
 			
      		month.slideDown("slow");
      	}
      	else
      	{
      		month.slideUp("slow");
      	}      
      	
	}
	
function page(page,content,type){
	
		    $.ajax({
				type: "POST",
				url: "/helper/"+content,
				data: "page2="+page+"&type="+content+"','"+type,
				success: function(html){    
		             $("div.last-videos").html(html); 

		        }
	
			});   

}

	function addVid2(){
    
	    id = $('.add-article p.videos input:last').attr('id');
	    id++;
	    photo = "<label> &nbsp; </label><input id=\""+id+"\" type=\"text\" name=\"video"+id+"\" size=\"52\">";
	    $('.add-article p.videos').append(photo);
	    $('.add-article p input[name=hiddenVideo]').val(id);
    
	}
	
function addUser(element){
    
    var userID = $(element).find("input[name='userID']").val();
    var title    = $(element).text();
    
    $("input#searchInput").val(title);
    $("input#ui").val(userID);
    
}

function deleteUser(id,crewID){
	
	jConfirm('Opravdu chcete smazat tohoto uživatele ? ', 'Smazat', function(result) {
	    
	    if(result)
        {
			$.ajax({
		        type: "POST",
		        url: "/helper/delete-user",
		        data: "id="+id+"&crewID="+crewID,
		        success: function(html){
		             window.location.reload();          
		        }
		
		    }); 
	    
	    }
    
     });
    
}

function loadBanner(){
	var so = new SWFObject('/Public/Banner/banner.swf','mpl1','468','60','10');
    
    so.addParam('wmode','transparent');
    so.write('banner');
}

