$(document).ready(function(){

  var pocet;
  var varianta;
  varianta=0;
  pocet=0;
  function changeText(p) {
    if (p == 0) {
      $(".prodLeft img").attr("src", "/images/produkty/granat-right.png");
      $(".prodRight img").attr("src", "");
       $(".lahevNav[rel='0'] .lahevActive").fadeIn();
    }
    if (p == 1) {
      $(".prodLeft img").attr("src", "/images/produkty/11-right.png");
      $(".prodRight img").attr("src", "/images/produkty/lezak-left.png");
       $(".lahevNav[rel='1'] .lahevActive").fadeIn();
    }
    if (p == 2) {
      $(".prodLeft img").attr("src", "/images/produkty/decko-right.png");
      $(".prodRight img").attr("src", "/images/produkty/granat-left.png");
       $(".lahevNav[rel='2'] .lahevActive").fadeIn();
    }
    if (p == 3) {
      $(".prodLeft img").attr("src", "/images/produkty/cerny-right.png");
      $(".prodRight img").attr("src", "/images/produkty/11-left.png");
       $(".lahevNav[rel='3'] .lahevActive").fadeIn();
    }
    if (p == 4) {
      $(".prodLeft img").attr("src", "/images/produkty/nealko-right.png");
      $(".prodRight img").attr("src", "/images/produkty/decko-left.png");
       $(".lahevNav[rel='4'] .lahevActive").fadeIn();
    }
    if (p == 5) {
      $(".prodLeft img").attr("src", "/images/produkty/svetly-right.png");
      $(".prodRight img").attr("src", "/images/produkty/cerny-left.png");
       $(".lahevNav[rel='5'] .lahevActive").fadeIn();
    }
    if (p == 6) {
      $(".prodLeft img").attr("src", "");
      $(".prodRight img").attr("src", "/images/produkty/nealko-left.png");
       $(".lahevNav[rel='6'] .lahevActive").fadeIn();
    }
    varianta=0;
    $(".varianty").fadeOut();
    $(".produktImg").delay(1000).animate({"top": "-32px"}, 1, 'easeInOutCirc');
    $(".varianty").delay(1000).fadeIn();
  }
  $(".prodLeft").click(function(){

    $(".lahevActive").fadeOut();
    $(".lahevNormal").fadeIn();
    
    if (pocet > 4) {
        $(".prodLeft").hide();
        $("#produktyBlock").animate({"left": "-=996px"}, 800, 'easeInOutCirc');
        pocet=pocet+1;
        changeText(pocet);
    } else {
        $("#produktyBlock").animate({"left": "-=996px"}, 800, 'easeInOutCirc');
        $(".prodRight").show();
        pocet=pocet+1;
        changeText(pocet);
    }
  	return false;
  });
  $(".prodRight").click(function(){

    $(".lahevActive").fadeOut();
    $(".lahevNormal").fadeIn();
    
    if (pocet < 2) {
        $(".prodRight").hide();
        $("#produktyBlock").animate({"left": "+=996px"}, 800, 'easeInOutCirc');
        pocet=pocet-1;
        changeText(pocet);
    } else {
        $("#produktyBlock").animate({"left": "+=996px"}, 800, 'easeInOutCirc');
        $(".prodLeft").show();
        pocet=pocet-1;
        changeText(pocet);
    }
  	return false;
  });
  
  $(".lahevNav").click(function(){
    
    $(".lahevActive").fadeOut();
    $(".lahevNormal").fadeIn();
    
    if ($(this).attr('rel') == 0) {
       $("#produktyBlock").animate({"left": "0px"}, 800, 'easeInOutCirc');
       pocet = 0;
       $(".lahevNav[rel='0'] .lahevNormal").fadeOut('200');
       $(".lahevNav[rel='0'] .lahevActive").fadeIn('500');
  	}
    if ($(this).attr('rel') == 1) {
       $("#produktyBlock").animate({"left": "-996px"}, 800, 'easeInOutCirc');
       pocet = 1;
       $(".lahevNav[rel='1'] .lahevNormal").fadeOut('200');
       $(".lahevNav[rel='1'] .lahevActive").fadeIn('500');
  	}
    if ($(this).attr('rel') == 2) {
       $("#produktyBlock").animate({"left": "-1992px"}, 800, 'easeInOutCirc');
       pocet = 2;
       $(".lahevNav[rel='2'] .lahevNormal").fadeOut('200');
       $(".lahevNav[rel='2'] .lahevActive").fadeIn('500');
  	}
    if ($(this).attr('rel') == 3) {
       $("#produktyBlock").animate({"left": "-2988px"}, 800, 'easeInOutCirc');
       pocet = 3;
       $(".lahevNav[rel='3'] .lahevNormal").fadeOut('200');
       $(".lahevNav[rel='3'] .lahevActive").fadeIn('500');
  	}
    if ($(this).attr('rel') == 4) {
       $("#produktyBlock").animate({"left": "-3984px"}, 800, 'easeInOutCirc');
       pocet = 4;
       $(".lahevNav[rel='4'] .lahevNormal").fadeOut('200');
       $(".lahevNav[rel='4'] .lahevActive").fadeIn('500');
  	}
    if ($(this).attr('rel') == 5) {
       $("#produktyBlock").animate({"left": "-4980px"}, 800, 'easeInOutCirc');
       pocet = 5;
       $(".lahevNav[rel='5'] .lahevNormal").fadeOut('200');
       $(".lahevNav[rel='5'] .lahevActive").fadeIn('500');
  	}
    if ($(this).attr('rel') == 6) {
       $("#produktyBlock").animate({"left": "-5976px"}, 800, 'easeInOutCirc');
       pocet = 6;
       $(".lahevNav[rel='6'] .lahevNormal").fadeOut('200');
       $(".lahevNav[rel='6'] .lahevActive").fadeIn('500');
  	}
  	
  	if (pocet > 5) {
        $(".prodLeft").hide();
        changeText(pocet);
    } else if (pocet < 1) {
        $(".prodRight").hide();
        changeText(pocet);
    } else {
        $(".prodLeft").show();
        $(".prodRight").show();
        changeText(pocet);
    }
  	return false;
  });
  
  $("#hpIcons a").mouseenter(function() {
    if ($.browser.msie) {
      $(this).children(".iconHover").show();
    } else {
      $(this).children(".iconHover").fadeIn(300);
    };
  });

  $("a.icon").mouseout(function() {
    $(this).children(".hoverBg").clearQueue();
    if ($.browser.msie) {
      $(this).children(".iconHover").hide();
    } else {
      $(this).children(".iconHover").fadeOut(300);
    };
  });

  $(".contentMenu li").mouseenter(function() {
    if ($.browser.msie) {
      $(this).children(".hoverBg").show();
    } else {
      $(this).children(".hoverBg").show().css({"opacity" : "0"}).animate({"opacity" : "1", "bottom": "-=8px"}, 300);
    };

  });

  $(".contentMenu li").mouseout(function() {
    $(this).children(".hoverBg").clearQueue();
    if ($.browser.msie) {
      $(this).children(".hoverBg").hide();
    } else {
      $(this).children(".hoverBg").fadeOut(300);
    };
    $(this).children(".hoverBg").animate({"bottom": "-35px"}, 1);
  });

  $("#footer .text").focusin(function() {
       $(".newsletterGlow").fadeIn(500);
  });

  $("#footer .text").focusout(function() {
       $(".newsletterGlow").fadeOut(500);
  });


  function slideText(s) {
    if (s == 0) {
      $(".slideLeft").html("");
      $(".slideRight").html("Strana 2/3");
    }
    if (s == 1) {
      $(".slideLeft").html("Strana 1/3");
      $(".slideRight").html("Strana 3/3");
    }
    if (s == 2) {
      $(".slideLeft").html("Strana 2/3");
      $(".slideRight").html("");
    }
    Cufon.refresh();
  }

  var slide;
  slide=0;
  $(".slideLeft").click(function(){
    if (slide < 2) {
        $(".slideLeft").hide();
        $("#slideBlock").animate({"left": "+=960px"}, 800, 'easeInOutCirc');
        slide=slide-1;
        slideText(slide);
    } else {
        $("#slideBlock").animate({"left": "+=960px"}, 800, 'easeInOutCirc');
        $(".slideRight").show();
        slide=slide-1;
        slideText(slide);
    }
  	return false;
  });
  
  $(".slideRight").click(function(){
    if (slide > 0) {
        $(".slideRight").hide();
        $("#slideBlock").animate({"left": "-=960px"}, 800, 'easeInOutCirc');
        slide=slide+1;
        slideText(slide);
    } else {
        $("#slideBlock").animate({"left": "-=960px"}, 800, 'easeInOutCirc');
        $(".slideLeft").show();
        slide=slide+1;
        slideText(slide);
    }
  	return false;
  });

  $(".slideIcon").mouseenter(function() {
    $(this).children(".iconHover").fadeIn(300);
  });

  $(".slideIcon").mouseout(function() {
    $(this).children(".iconHover").fadeOut(300);
  });

  var max;
  max = 0;
  $(".varianty").click(function(){
    max = $(this).attr('rel');
    max = max-1;
    if (varianta < max) {
        $(".produktImg").animate({"top": "-=531px"}, 800, 'easeInOutCirc');
        varianta=varianta+1;
    } else {
        $(".produktImg").animate({"top": "-32px"}, 800, 'easeInOutCirc');
        varianta=0;
    }
  	return false;
  });
  

  $(".crop a").mouseenter(function() {
    $(this).animate({"top": "5px"}, 200);
  });

  $(".crop a").mouseout(function() {
    $(this).animate({"top": "10px"}, 200);
  });
  
  $(".btn").mouseenter(function() {
    $(".btn .hover").fadeIn(300);
  });

  $(".btn").mouseleave(function() {
    $(".btn .hover").fadeOut(300);
  });

});
