$(document).ready(function(){
	$('a[rel^=lightbox]').lightBox();
	
	$('.btnGB').attr('value','');
	$(".btnGB").hover(
    function () { $(this).css('background-position', '0 0' ); },
    function () { $(this).css('background-position', '0 -'+$(this).outerHeight()+'px' ); }
  );

	$(".hoverGB").hover(
    function () { $(this).css('background-position', '-'+$(this).outerWidth()+'px 0' ); },
    function () { $(this).css('background-position', '0 0' ); }
  );  


  $("#home-calendar .content").GBSlider({
    counter: 2,
    margin:  10,
    nextId:  'down-calendar',
    prevId:  'up-calendar',
    firstId: 'firstBtn-calendar',
    lastId:  'lastBtn-calendar'	
  });

  
  $("#homebox #calendar").click(function(){
    $("#homebox #home-news .content").hide();
    $("#homebox #home-news .remote").hide();
    $("#homebox #news").removeClass('active');

    $("#homebox #home-calendar .content").fadeIn();
    $("#homebox #home-calendar .remote").show();
    $("#homebox #calendar").addClass('active');
    
  });

  $("#homebox #news").click(function(){
    $("#homebox #home-calendar .content").hide();
    $("#homebox #home-calendar .remote").hide();
    $("#homebox #calendar").removeClass('active');

    $("#homebox #home-news .content").fadeIn();
    $("#homebox #home-news .remote").show();
    $("#homebox #news").addClass('active');
    
    $("#home-news .content").GBSlider({
      counter: 2,
      margin: 10,
      nextId:  'down-news',
      prevId:  'up-news',
      firstId: 'firstBtn-news',
      lastId:  'lastBtn-news'	
    });    
    
  });

  $("#homebox #home-news .content").hide();
  $("#homebox #home-news .remote").hide();

  $('.catalog_perex .podrobnosti table').css({ 'width': '100%', 'height': 'auto' });

});



(function($) {

	$.fn.GBSlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			counter: 1,
			margin: 10,
      prevId: 		'up',
			prevText: 		'<span>Předchozí</span>',
			nextId: 		'down',	
			nextText: 		'<span>Další</span>',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		true,
			speed: 			500,
			auto:			false,
			pause:			2500,
			continuous:		false
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height();
			obj.width(w); 
			obj.height((h*options.counter)+options.margin); 
			obj.css("overflow","hidden");
			var ts = (s)-1;
			
			var t = 0;
			if(!options.vertical) $("ul", obj).css('width',s*w);			
			if(!options.vertical) $("li", obj).css('float','left');
			
			if(options.controlsShow){
				var html = options.controlsBefore;
				if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
				html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
				html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
				if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
				html += options.controlsAfter;						
				$(obj).parent().find('.remote').html(html);
        //$(obj).before(html);										
			};
	
			$("a","#"+options.nextId).click(function(){		
				animate("next",true);
			});
			$("a","#"+options.prevId).click(function(){		
				animate("prev",true);				
			});	
			$("a","#"+options.firstId).click(function(){		
				animate("first",true);
			});				
			$("a","#"+options.lastId).click(function(){		
				animate("last",true);				
			});		
			
			function animate(dir,clicked){
				var ot = t;				
				switch(dir){
					case "next":
						t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;						
						break; 
					case "prev":
						t = (t<=0) ? (options.continuous ? ts : 0) : t-1;
						break; 
					case "first":
						t = 0;
						break; 
					case "last":
						t = ts;
						break; 
					default:
						break; 
				};	
				
				var diff = Math.abs(ot-t);
				var speed = diff*options.speed;						
				if(!options.vertical) {
					p = (t*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						speed
					);				
				} else {
					p = ((t*h)-1);
					
					$("ul",obj).animate(
						{ marginTop: -(p+(options.margin*t)) }, 
						speed
					);
          /*("ul",obj).css('top',p+'px');*/          					
				};
				
				if(!options.continuous && options.controlsFade){					
					if(t==ts){
						$("a","#"+options.nextId).addClass('notactive');
						$("a","#"+options.lastId).addClass('notactive');
					} else {
						$("a","#"+options.nextId).removeClass('notactive');
						$("a","#"+options.lastId).removeClass('notactive');			
					};
					if(t==0){
						$("a","#"+options.prevId).addClass('notactive');
						$("a","#"+options.firstId).addClass('notactive');
					} else {
						$("a","#"+options.prevId).removeClass('notactive');
						$("a","#"+options.firstId).removeClass('notactive');
					};					
				};				
				
				if(clicked) clearTimeout(timeout);
				if(options.auto && dir=="next" && !clicked){;
					timeout = setTimeout(function(){
						animate("next",false);
					},diff*options.speed+options.pause);
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
		
			if(!options.continuous && options.controlsFade){					
				$("a","#"+options.prevId).addClass('notactive');
				$("a","#"+options.firstId).addClass('notactive');				
			};				
			
		});
	  
	};

})(jQuery);






function validate_kontakt(form)
{

  if (form.jmeno.value == '' || form.jmeno.value == 'Jméno')
  {
    alert('Je nutné zadat Vaše jméno!');
    form.jmeno.focus();
    return false;
  }
  else if (form.email.value == '' || form.email.value == 'E-mail *')
  {
    alert('Je nutné zadat Váš email!');
    form.email.focus();
    return false;
  }  
  else if (form.vzkaz.value == '' || form.vzkaz.value == 'Zpráva *')
  {
    alert('Je nutné zadat Váš vzkaz!');
    form.vzkaz.focus();
    return false;
  }
  
  else
    return true;
}

function validate_kontakt_en(form)
{

  if (form.jmeno.value == '' || form.jmeno.value == 'Jméno')
  {
    alert('Is necessary to enter your name!');
    form.jmeno.focus();
    return false;
  }
  else if (form.email.value == '' || form.email.value == 'E-mail *')
  {
    alert('Is necessary to enter your email!');
    form.email.focus();
    return false;
  }
  else if (form.vzkaz.value == '' || form.vzkaz.value == 'Zpráva *')
  {
    alert('Is necessary to enter your message!');
    form.vzkaz.focus();
    return false;
  }

  else
    return true;
}

function validate_kontakt_de(form)
{

  if (form.jmeno.value == '' || form.jmeno.value == 'Jméno')
  {
    alert('Es ist nötig Ihre Name aufgeben!');
    form.jmeno.focus();
    return false;
  }
  else if (form.email.value == '' || form.email.value == 'E-mail *')
  {
    alert('Es ist nötig Ihre Email aufgeben!');
    form.email.focus();
    return false;
  }
  else if (form.vzkaz.value == '' || form.vzkaz.value == 'Zpráva *')
  {
    alert('Es ist nötig Ihre Nachricht aufgeben!');
    form.vzkaz.focus();
    return false;
  }

  else
    return true;
}

function validatesearch (form)
{

	if (form.keyword.value.length < 2 || form.keyword.value == 'hledaný výraz...')
  {
    alert('Pro vyhledávání je nutné zadat minimálně 2 znaky!');
    form.keyword.focus();
    return false;
  }
  else if (form.keyword.value.length < 2 || form.keyword.value == 'Search...')
  {
    alert('For searchig is necessary to enter minimum 2 sings!');
    form.keyword.focus();
    return false;
  }
  else if (form.keyword.value.length < 2 || form.keyword.value == 'Suchen...')
  {
    alert('Für Suchen müssen Sie min. 2 Symbolen aufgeben!');
    form.keyword.focus();
    return false;
  }
  else
    return true;
}

function echeck(str, lng) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Zadali jste e-mail v nesprávném tvaru.")
		   return false
		}

    if (lng == 'cz')
      var hlaska = "Zadali jste e-mail v nesprávném tvaru.";
    else if (lng == 'en')
      var hlaska = "Your email is incorrect.";
    else if (lng == 'de')
      var hlaska = "Sie haben schlechtes Email aufgegeben.";


		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(hlaska)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(hlaska)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(hlaska)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(hlaska)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(hlaska)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(hlaska)
		    return false
		 }

 		 return true					
	}

function validatenl (form)
{
  if (form.email.value.length < 2 || form.email.value == 'Zadejte svůj e-mail')
  {
    alert('Pro odběr newsletteru musíte vyplnit Váš e-mail!');
    form.email.focus();
    return false;
  }
  else if (echeck(form.email.value,'cz')==false){
		form.email.value="";
		form.email.focus();
		return false
	}
  else
    return true;
}

function validatenl_en (form)
{
  if (form.email.value.length < 2 || form.email.value == 'Zadejte svůj e-mail')
  {
    alert('If you want to get newsletter you must enter email!');
    form.email.focus();
    return false;
  }
  else if (echeck(form.email.value,'en')==false){
		form.email.value="";
		form.email.focus();
		return false
	}
  else
    return true;
}

function validatenl_de (form)
{
  if (form.email.value.length < 2 || form.email.value == 'Zadejte svůj e-mail')
  {
    alert('Für Neuheiten müssen Sie Ihres Email aufgeben!');
    form.email.focus();
    return false;
  }
  else if (echeck(form.email.value,'de')==false){
		form.email.value="";
		form.email.focus();
		return false
	}
  else
    return true;
}
