$(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' ); }
  );  

	$(".catalog_item").hover(
    function () { $(this).addClass('catalog_item_hover'); },
    function () { $(this).removeClass('catalog_item_hover'); }
  );  


	$(".catalog_item").click(function(){
		location.href=$(this).find('a').attr('href');
	});

	$(".category-items .item").hover(
    function () { $(this).addClass('item_hover'); },
    function () { $(this).removeClass('item_hover'); }
  );
  
  
 
  


  $("#action_list").easySlider({
    controlsShow: true,
  	auto: true,
  	continuous: false,
    speed: 500,
    pause: 2500
  });

  $("#teaser .foo").carousel({
    direction: "vertical",
    loop: true,
    pagination: true,
    autoSlide: true,
    autoSlideInterval: 6000,
    delayAutoSlide: 0,
    effect: "fade"
  });
  

  $("#form-login").submit(function(e){
    
    if (validate_login(this))
    {
      $.post("/katalog/?action=login&lng="+$(this).attr('rel'), $(this).serialize(), function(response){

        if (response == 'error')
        {
          $('#login-result').html('<p class="chyba">Nesprávné přihlašovací údaje!</p>');
          $("input[name=password]").val('');
        }
        else
        {
          window.location.href=response;
        }
      });
    }
    
    return false;
  });  


  $("#form-login_en").submit(function(e){

    if (validate_login_en(this))
    {
      $.post("/katalog/?action=login&lng="+$(this).attr('rel'), $(this).serialize(), function(response){

        if (response == 'error')
        {
          $('#login-result').html('<p class="chyba">Incorrect login informations!</p>');
          $("input[name=password]").val('');
        }
        else
        {
          window.location.href=response;
        }
      });
    }
    
    return false;
  }); 
  

  $("#form-login_de").submit(function(e){
    
    if (validate_login_de(this))
    {
      $.post("/katalog/?action=login&lng="+$(this).attr('rel'), $(this).serialize(), function(response){

        if (response == 'error')
        {
          $('#login-result').html('<p class="chyba">Falsche Almendungs Daten!</p>');
          $("input[name=password]").val('');
        }
        else
        {
          window.location.href=response;
        }
      });
    }
    
    return false;
  });     
  
  $("#login-pass").click(function(){
    $("#login-box-overlay").show();
    
    $.get("/katalog/ajax-password.php?lng="+$(this).attr('rel'), function(data){
      $("#login-box .inner").html(data);
    });
    
    $("#login-box").addClass('pass');
    $("#login-box").fadeIn("fast");
    
      $("#close-button").click(function(){ 
         box_remove('pass');
         $("#login-box .inner").html();
      });
  });

  $("#login-change").click(function(){
    $("#login-box-overlay").show();
    
    $.get("/katalog/ajax-change.php?lng="+$(this).attr('rel'), function(data){
      $("#login-box .inner").html(data);
    });
    
    $("#login-box").addClass('pass');
    $("#login-box").fadeIn("fast");
    
      $("#close-button").click(function(){ 
         box_remove('pass');
         $("#login-box .inner").html();
      });
  });

  $("#login-reg").click(function(){
    $("#login-box-overlay").show();
    
    $.get("/katalog/ajax-registrace.php?lng="+$(this).attr('rel'), function(data){
      $("#login-box .inner").html(data);
    });
    
    $("#login-box").addClass('reg');
    $("#login-box").fadeIn("fast");
    
                
      
      $("#close-button").click(function(){ 
         box_remove('reg');
         $("#login-box").removeClass('reg-confirm');
         $("#login-box .inner").html();
      });
  });


  function box_remove(css) {
    $("#login-box-overlay").hide();
    $("#login-box").removeClass(css);
    
    $("#login-box").fadeOut("fast");
    $("#login-box").hide();

    if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
      $("body","html").css({height: "auto", width: "auto"});
      $("html").css("overflow","");
    }

    document.onkeydown = "";
    document.onkeyup = "";
    return false;
} 

});


function CategoryItemImage()
{
  $('.category-items .item .photo img').each(function(){ 
    var height = $(this).innerHeight();
    
    if (height > 115)
     $(this).css('width','65px');

  
    if ($(this).innerHeight() > 115)
    {
      $(this).css('width','auto');
      $(this).css('height','115px');
    }
  });

}


function validate_login(form)
{
  if (form.email.value == "")
  {
    alert('Je nutné vyplnit pole E-mail!');
    form.email.focus();
    return false;
  }
  else if (echeck(form.email.value,'cz')==false)
  {
		form.email.focus();
		return false;
	}
  else if (form.password.value == "")
  {
    alert('Je nutné vyplnit pole Heslo!');
    form.password.focus();
    return false;
  }	
  else
    return true;	
}

function validate_login_en(form)
{
  if (form.email.value == "")
  {
    alert('You must fill in field E-mail!');
    form.email.focus();
    return false;
  }
  else if (echeck(form.email.value,'en')==false)
  {
		form.email.focus();
		return false;
	}
  else if (form.password.value == "")
  {
    alert('You must fill in field Password!');
    form.password.focus();
    return false;
  }	
  else
    return true;	
}

function validate_login_de(form)
{
  if (form.email.value == "")
  {
    alert('Sie müssen in Feld ausfüllen E-mail!');
    form.email.focus();
    return false;
  }
  else if (echeck(form.email.value,'de')==false)
  {
		form.email.focus();
		return false;
	}
  else if (form.password.value == "")
  {
    alert('Sie müssen in Feld ausfüllen Passwort!');
    form.password.focus();
    return false;
  }	
  else
    return true;	
}


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 == 'Hledat na webu...')
  {
    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) {

    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.";

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert(hlaska)
		   return false
		}

		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;
}
