function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.hover(function() {
    	carousel.options.smer = 'right';
        carousel.options.animation = 800;
        carousel.options.auto = 0.00001;
        carousel.startAuto();
    }, function() {
    	carousel.stopAuto();
    	carousel.options.auto = 0;
    });

    carousel.buttonPrev.hover(function() {
        carousel.options.smer = 'left';
        carousel.options.animation = 800;
        carousel.options.auto = 0.00001;
        carousel.startAuto();
    }, function() {
    	carousel.stopAuto();
    	carousel.options.auto = 0;
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.options.auto = 0;
    }, function() {
    	carousel.options.auto = 0;
    });
};


$(document).ready(function() { 
  
 ajx_form('#regmail','#newsletter', true, false);
 ajx_form('#friendmail','#box3_btm', true, false);

 $(".tip").ToolTipDemo("#FFFFFF", "#000000");
 
 $("#ask_form").validate();
 $("#inzerce_form").validate();
 $("#sendmail_form").validate();
 
 $('#toplink').click(function(){
 	$.scrollTo( "#top", 600);
 });
 
 $('.mapa_lnk').click(function(){
    $("#map").show();
 	$.scrollTo( "#map", 600);
 });
 
 
 $('.fldrname').click(function(){
 	var rel = $(this).attr("rel");
 	$(".fldr_data").hide();
 	$(".fldr"+rel).show();
 	$.scrollTo( "#fldrname"+rel, 800);
 });
  
  
 
 $('.c2v').click(function(){
	var rel = $(this).attr("rel");
	var id = $(this).attr("id");
	$(".anketa").load("ajx_vote_anketa.php?id=" + rel + "&rep=" + id, {limit: 25}, function(){});
 });
 
 $('.filtr_rreg').click(function(){
 	$(".filtr_rcit").unCheckCheckboxes();
 	$(".filtr_rcit").hide();
 });
 
 $('.filtr_lnk').click(function(){
	var rel = $(this).attr("rel").split("_");
	$(".filtr_"+rel[0]).unCheckCheckboxes();
	$(".filtr_"+rel[0]).checkCheckboxes("#inp_"+rel[0]+rel[1]);
	if(rel[0]=='rreg' || rel[0]=='rscat'){
		$(".filtr_rcit").unCheckCheckboxes();
		$(".filtr_rcit").hide();
	}
	$('#filtr_ds').submit();
 });
 
 $('.selrev').click(function(){
  var rel = $(this).attr("rel");
  $(".filtr_"+rel).toggleCheckboxes();
 });
 $('.selall').click(function(){
  var rel = $(this).attr("rel");
  $(".filtr_"+rel).checkCheckboxes();
 });
 $('.selnon').click(function(){
  var rel = $(this).attr("rel");
  $(".filtr_"+rel).unCheckCheckboxes();
 });
 
 
  		
 function ajx_form(fname, tid, rebind, modalMsg){
 	$(fname).submit(function() {
 	
   		$(this).ajaxSubmit({
 		target: tid,
 		success: function(){
 			if(modalMsg){
 		    	showMsg('msg',300,90,2000);
 		    }
 		    if(rebind){
 				ajx_form(fname, tid, rebind, modalMsg);
 			}
 		}
 	});
 	return false;});
 }
 
 function ajx_cart(fname, tid){
 	$(fname).submit(function() { 
   		var rel = $(this).attr("target");
   		$(this).ajaxSubmit({
 		url: "ajx_cart.php",
 		target: tid,
 		beforeSubmit: function(){tb_remove(false)},
 		success: function(){
 			document.getElementById(rel).value='';
 			showMsg('msg',500,35,2000);
 		}
 	});
 	return false;});
 }
  
 function showMsg(div,width,height,time){
 	tb_show('', '#TB_inline?reload=false&height='+height+'&width='+width+'&inlineId='+div+'&modal=true', null, true)
	setTimeout(function(){tb_remove(false)}, time);
 }
 
 function str_replace(haystack, needle, replacement) {
    var temp = haystack.split(needle);
    return temp.join(replacement);
 }
 
 $("#close_tb").click(function(){
 	self.parent.tb_remove('true');
 });
 

 $('.radio_input').click(function(){
 	$('#inzerce_filtr').submit();
 });
 $('.show_search').click(function(){
 	showhide('.inzerce_search');
 }); 
 

 initMenu();
 
 
 $('.addinput_btn').click(function() { add_input(this); });          
 $('.reminput_btn').click(function() { rem_input(this); });
 
 initFolderselect();
 initEnter('.cisla');
 
 
 $('.msgform_lnk').click(function(){
 	var rel = $(this).attr("rel");
 	var title = $(this).attr("title");
 	var lng = $('#setlng').val();
 	tb_show(title, 'sendreply.php?idz='+rel+'&keepThis=true&TB_iframe=true&reload=false&height=450&amp;width=500&amp;lng='+lng, null);
 	return false;
 });
 
  $('.msgform2_lnk').click(function(){
 	var rel = $(this).attr("rel");
 	var title = $(this).attr("title");
 	var lng = $('#setlng').val();
 	tb_show(title, 'sendmail.php?idz='+rel+'&keepThis=true&TB_iframe=true&reload=false&height=250&amp;width=500&amp;lng='+lng, null);
 	return false;
 });
 
 
 $('.sh_allin').click(function(){
 	var rel = $(this).attr("rel");
 	showhide('#inp_'+rel+'_allin');
 	$('#inp_'+rel+'_allin').focus();
 });  
 
});
//konec onload


function add_cis(cis_name){
 	tb_show('Přidat záznam do číselníku', 'ciselnik.php?fn='+cis_name+'&amp;keepThis=true&amp;TB_iframe=true&amp;reload=false&amp;height=auto&amp;width=auto', null);
}

function ed_cis(cis_name){
 	$("#sel_"+cis_name+" option:selected").each(function () {
 	    tb_show('Upravit záznam v číselníku', 'ciselnik.php?fn='+cis_name+'&amp;id_cis_'+cis_name+'='+$(this).val()+'&amp;keepThis=true&amp;TB_iframe=true&amp;reload=false&amp;height=auto&amp;width=auto', null);
 	});
}


function del_cis(cis_name){
    
    if (!confirm('Opravdu chcete tento záznam vymazat?')){
 		return false;   
    }
    
    $("#sel_"+cis_name+" option:selected").each(function () {
 	  var sel = $(this).val();
 	  
 	  $.ajax({
 	  	type: "GET",
 	  	url: "ajx_ciselnik.php?fn="+cis_name+"&akce=del&id_cis_"+cis_name+"="+sel,
 	  	success: function(){
 	  		$("#sel_"+cis_name).removeOption(/./).ajaxAddOption("ajx_ciselnik.php?fn="+cis_name+"&amp;id_cis_"+cis_name+"="+sel, {}, false, function(){
 	     	//$("#sel_"+cis_name+" option:contains('vyberte')").attr("selected", true);
 	    });
   	   }
     }); 	    
 	});
 
 }
 
 
 
 
 
 
 function get_cis(cis_name,matches){
 
    $("#sel_"+cis_name+" option:selected").each(function () {
   	var idz = $(this).val();
   	//var inputs = ['kp_jmeno', 'kp_email', 'kp_telefon'];
   	var inputs = matches.split(';');
   	
   	$.ajax({
   	 type: "GET",
   	 url: "ajx_cis_data.php",
   	 data: "fn="+cis_name+"&id_cis_"+cis_name+"="+idz+"&m="+matches,
   	 dataType: "xml",
   	 success: function(xml){
		$("element", xml).each(function(){
			
			var ele = this;
			
     		$.each(inputs,function(index,value){
             	$("#inp_"+value).val($(value, ele).text());    		
    		});
			
		});
   	   }
     });   	
    }); 
 }
 
 



function switch_img(id_katalog,imgnr){
	$('#foto').fadeOut("fast");
	setTimeout(function(){
		$('.preload').show();
		setTimeout(function(){
		$("#detail_foto").load("ajx_switchimg.php?id_katalog="+id_katalog+"&imgnr="+imgnr);}
		, 400); $.scrollTo( "#detail_foto", 600);
	}, 400);
}

function switch_img2(id_katalog,imgnr){
	$('#info').hide();
	$('#foto').fadeOut("fast");
	setTimeout(function(){
		$('.preload').show();
		setTimeout(function(){
		$("#detail_foto").load("ajx_detail_gallery.php?id_katalog="+id_katalog+"&imgnr="+imgnr); }
		, 400);
	}, 400);
}

function mainmenu(){
$(" .katmenu ul ").css({display: "none"}); // Opera Fix
$(" .katmenu li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

function showhide(what){
  var d = ( $(what).css('display') );
  if(d=='none'){ $(what).show(); }
  else{ $(what).hide(); }
}


function initMenu() {
	$('.leftmenu ul').hide();
   // $('.leftmenu ul:first').show();
    $('.leftmenu ul.visib').show();
    $('.leftmenu li a').click(
    function() {
    var checkElement = $(this).next();
    if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
    checkElement.slideUp('normal');
    return false;
    }
  if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
  	$('.leftmenu ul:visible').slideUp('normal');
  	checkElement.slideDown('normal');
  	return false;
  }
  }
  );
  }
  
  
  
function initHider(what) {
	$(what).hide();
   
    $(what+'_hider').click(
    function() {
    
    if($(what).is(':visible')) {
    	$(what).slideUp('normal');
    	return false;
    }
    if(!$(what).is(':visible')) {
  		$(what).slideDown('normal');
  		return false;
  	}
  }
  );
  }  


function add_input(value){
		var rel = $(value).attr("rel");
		
		var relarr = rel.split("_");		
		if(relarr[1]){rel = relarr[0];} 
		
        var n = parseFloat($("#counter"+rel).val());
		var m = n + 1;
        //alert(rel);
        var activelng = $('#activelng').val();
        
        if(activelng=='cz'){popiska = 'Smazat';}
        if(activelng=='sk'){popiska = 'Zmazať';}
        
        $("#addinput_btn" + rel).before('<div id="' + rel + '_' + m + '"><input type="text" name="' + rel + '[' + m + ']" id="input' + rel + '_' + m + '" value="" rel="' + rel + '" class="' + rel + ' required number"/>&nbsp;<input type="button" value=" X " class="reminput_btn" rel="' + rel + '_' + m + '" id="rem' + rel + '_' + m + '" title="' + popiska + '" /></div>');
        $("#input"+rel + '_' + m).focus();
        $("#rem"+rel+"_"+m).click(function(){
         	//$("#" + rel + "_" + m).remove();         	
            rem_input($(this),true);        
        });
        
        initEnter('#input' + rel + '_' + m);
                
        $("#counter"+rel).val(m);
    }
    
    
    function rem_input(value,echo){
    	var rel = $(value).attr("rel");
        $("#" + rel).remove();
                        
        var relarr = rel.split("_");		
		if(relarr[1]){rel = relarr[0];}
        
        var ic = $('.'+rel).size();
        if(ic==0){        	
        	//add_input(value);
        }
        
    }


function initFolderselect(){
	var id_inzerce = $("#id_inzerce").val();
	
	$("#sel_slozka option:selected").each(function () {
    		f = $(this).val();
 	});
	
	if((id_inzerce=='')&&(f=='')){
		$("#inzerce_submit").attr("disabled", "true");
	}
	
	$("#sel_slozka").change(function () {
 		//$("#inzerce_submit").removeAttr("disabled"); return false;
    	$("#sel_slozka option:selected").each(function () {
    		folder = $(this).val();
 		});
 		
 		if(folder!=841){
 			
 			$.ajax({
 	  			type: "GET",
		 	  	url: "ajx_folderchk.php?slozka="+folder+"&id_inzerce="+id_inzerce,
 	  			success: function(result){
 	  				if((result!='')||(folder=='')){ 
 	  					if(result!=''){alert(result);}
 	  					$("#sel_slozka option:contains('---')").attr("selected", true);
 	  					$("#inzerce_submit").attr("disabled", "true");
 	  					$("#sel_slozka").focus();
 	  				} else {
 	  					$("#inzerce_submit").removeAttr("disabled");
 	  				}
 	    		}
     		});
 			
 			//alert(folder);
 		} else {
 			$("#inzerce_submit").removeAttr("disabled");
 		} 		
 		 		
 	});

	
	$("#inzerce_submit").click(function () {
		
		var inc=0;
		var k=0;
		$('.cisla').each(function(i, e) {  
			inc++;			
  			if ($(e).val() != "") k++;
		});
		var k2=0;
		$('.cisla2').each(function(i, e) {
			inc++;  			
  			if ($(e).val() != "") k2++;
		});
		if($('#inp_cisla_allin').val()!=''){inc++;}
		if($('#inp_cisla2_allin').val()!=''){inc++;}
		
		if((k==0)&&(k2==0)&&(inc==0)){
			if( $('input:hidden[name=lng]').val()=='cz' ){
				alert('Zadejte prosím alespoň jedno číslo.');
			}
			if( $('input:hidden[name=lng]').val()=='sk' ){
				alert('Zadajte prosím aspoň jedno číslo.');
			}
	
			return false;
		}
	});
	

}

function initEnter(t){
	$(t).keypress(function(e)
        {
            code= (e.keyCode ? e.keyCode : e.which);
            if (code == 13) {
            	add_input(this);
            	//alert('Enter key was pressed.');
            	return false;
            }
            //e.preventDefault();
        });
}


