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','#box2_btm', true, false);
 ajx_form('#friendmail','#box3_btm', true, false);
 ajx_cart('.cart_form','#full_kosik');
 
 
$('.remove_btn').click(function(){
	var act = $(this).attr("id");
	var id = act.replace('r','');
	$('#m'+id).val(0);
});

$('.kosik_mnozstvi').keyup(function(){
	var act = $(this).attr("id");
	var id = act.replace('r','');
	var id = id.replace('m','');
	$('#active').val(id);
	
	return false;
});
 
$('.kosik_mnozstvi').delay( {
	event: 'keyup',
	delay: 400,
	fn: function( e, obj ) {
		var act = $('#active').val();
 		$('#cartform'+act).submit();
	}
});


$("#sel_f_doprava").change(function () {
    $("#sel_f_doprava option:selected").each(function () {
   	var idz = $(this).val();
   	
   	$.ajax({
   	 type: "GET",
   	 url: "ajx_cart.php",
   	 data: "f_doprava="+idz,
   	 success: function(xml){
		$("#doprava").val(idz);  	   
   	   }
     });   	
    });
  });
 

 $("#reg_form").validate();
 $("#lostpass_form").validate();
 $("#ask_form").validate();
 
 $('#toplink').click(function(){
 	$.scrollTo( "#top", 600);
 });
 
 $(".tip").ToolTipDemo("#FFFFBD", "#000000");
 
  $('.fldrname').click(function(){
 	var rel = $(this).attr("rel");
 	$(".fldr_data").hide();
 	$(".fldr"+rel).show();
 	$.scrollTo( "#fldrname"+rel, 800);
 });
  		
 function ajx_form(fname, tid, rebind, modalMsg){
 	$(fname).submit(function() { 
   		$(this).ajaxSubmit({
 		target: tid,
 		success: function(){
 			if(modalMsg){
 		    	showMsg('msg',300,90,1000);
 		    }
 		    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,1000);
 			var act = $('#active').val();
			//alert('#m'+act);
			$('#m'+act).focus();
 			ajx_cart(fname, tid);

$('.remove_btn').click(function(){
	var act = $(this).attr("id");
	var id = act.replace('r','');
	$('#m'+id).val(0);
});

$('.kosik_mnozstvi').keyup(function(){
	var act = $(this).attr("id");
	var id = act.replace('r','');
	var id = id.replace('m','');
	$('#active').val(id);
	
	return false;
});
 
$('.kosik_mnozstvi').delay( {
	event: 'keyup',
	delay: 400,
	fn: function( e, obj ) {
		var act = $('#active').val();
 		$('#cartform'+act).submit();
	}
});

$("#sel_f_doprava").change(function () {
    $("#sel_f_doprava option:selected").each(function () {
   	var idz = $(this).val();
   	
   	$.ajax({
   	 type: "GET",
   	 url: "ajx_cart.php",
   	 data: "f_doprava="+idz,
   	 success: function(xml){
		$("#doprava").val(idz);  	   
   	   }
     });   	
    });
  });



 		}
 	});
 	return false;});
 }
  
 function showMsg(div,width,height,time){
 	tb_show('', '#TB_inline?reload=false&height='+height+'&width='+width+'&inlineId='+div+'&modal=true', null, false)
	setTimeout(function(){tb_remove(false)}, time);
 }
 
 $("#close_tb").click(function(){
 	self.parent.tb_remove('true');
 });
 
 
 mainmenu();
 
});
//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"}).show(300);
		//$(document).find('.jcarousel-container:first').css({visibility: "hidden"});
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		//$(document).find('.jcarousel-container:first').css({visibility: "visible"});
		});
}

function showhide(what){
  if (what.style.display=='none')
    { what.style.display=''; }
  else { what.style.display='none' }
}



function init_caru(start){
     $('#mycarousel2').jcarousel({
    	visible: 6,
    	auto: 0,
    	start: start,
        easing: 'linear',
        scroll: 6,
        animation: 800,
        itemLoadCallback: mycarousel_itemLoadCallback
 	});
 }

function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }
    
    jQuery.get(
        'ajx_carousel.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('image', xml).each(function(i) {
    
    	var url = $("url", this).text();
    	var kod = $("kod", this).text();
    	var tema = $("tema", this).text();
    	    
        carousel.add(first + i, mycarousel_getItemHTML(url,kod,tema));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url,kod,tema)
{
	return '<a href="javascript:;" onclick="switch_foto(\'' + kod + '\',this)" title="' + kod + '" onmouseover="blik(this)" style="background: url(\'' + url + '\') center center no-repeat" id="car' + kod + '" class="carousel_foto"></a>';
};



function blik(obj){

  	$(obj).fadeTo(100,0.5,function(){
  			$(obj).fadeTo(500,1);
  		}
  	);
  
}




(function($){
/**
* jQuery delayed event execution.
*/
$.fn.delay = function(options) {
var timer;
var delayImpl = function(eventObj, obj) {
if (timer != null) {
clearTimeout(timer);
}
var newFn = function() {
options.fn(eventObj, obj);
};
timer = setTimeout(newFn, options.delay);
}

return this.each(function() {
var obj = $(this);
obj.bind(options.event, function(eventObj) {
delayImpl(eventObj, this);
});
});
};
})(jQuery);




