$("document").ready(function(){
   $('#botThree1').click(function(){
      var link = $(this).find('.linkTo').html();
      window.location.href = link;
   });
   $('.flexslider2').flexslider({
      animation: "fade",              //String: Select your animation type, "fade" or "slide"
      slideDirection: "horizontal",   //String: Select the sliding direction, "horizontal" or "vertical"
      slideshow: true,                //Boolean: Animate slider automatically
      slideshowSpeed: 7000,           //Integer: Set the speed of the slideshow cycling, in milliseconds
      animationDuration: 600,         //Integer: Set the speed of animations, in milliseconds
      directionNav: false,             //Boolean: Create navigation for previous/next navigation? (true/false)
      controlNav: false,               //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage
      keyboardNav: true,              //Boolean: Allow slider navigating via keyboard left/right keys
      mousewheel: false,              //Boolean: Allow slider navigating via mousewheel
      prevText: "Previous",           //String: Set the text for the "previous" directionNav item
      nextText: "Next",               //String: Set the text for the "next" directionNav item
      pausePlay: false,               //Boolean: Create pause/play dynamic element
      pauseText: 'Pause',             //String: Set the text for the "pause" pausePlay item
      playText: 'Play',               //String: Set the text for the "play" pausePlay item
      randomize: false,               //Boolean: Randomize slide order
      slideToStart: 0,                //Integer: The slide that the slider should start on. Array notation (0 = first slide)
      animationLoop: true,            //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
      pauseOnAction: true,            //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
      pauseOnHover: false,            //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
      controlsContainer: "",          //Selector: Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.
      manualControls: "",             //Selector: Declare custom control navigation. Example would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.
      start: function(){},            //Callback: function(slider) - Fires when the slider loads the first slide
      before: function(){},           //Callback: function(slider) - Fires asynchronously with each slider animation
      after: function(){},            //Callback: function(slider) - Fires after each slider animation completes
      end: function(){}               //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
   });
   $('#mycarousel').jcarousel({
      vertical: true,
      scroll: 2
   });
   $('h1').hide();
   $('.fancybox').fancybox({
      'transitionIn':'fade',
      'transitionOut':'fade',
      'speedIn':700, 
      'speedOut':300, 
      'overlayOpacity':0.3,
      'overlayColor':'#000000',
      'padding':0,
      'margin':20,
      'titleShow':true,
      'changeSpeed':0,
      'scrolling':'no'
   });
   $("#rightSubMenu").mousemove(function(e){
      var h = $('#rightSubMenuScroller').height()+13;
      var offset = $($(this)).offset();
      var position = (e.pageY-offset.top)/$(this).height();
      if(position<0.33) {
         $(this).stop().animate({ scrollTop: 0 }, 1200);
      }
      else if(position>0.66) {
         $(this).stop().animate({ scrollTop: h }, 1200);
      }
      else
      {
         $(this).stop();
      }
   });
   $("#rightSubMenu").mouseout(function(e){
      $(this).stop();
   });
   $('#rightSubMenuScroller .rsmEntry').click(function(){
      var request = $(this).attr('id');
      $('#leftSlider').remove(); 
      $.get('/ajax/loadImgs.php?request='+request, function(data){
         var newData = data.split('//DELIMITER//');
         $("#leftSliderWrap").html(newData[0]);
         $("#botThree2").html(newData[1]);
         loadSlider();
      });
      $('#rightSubMenuScroller .rsmEntry').removeClass('active');
      $(this).addClass('active');
   });
   loadSlider();
   /* read href */
      var href = $(location).attr('href'),
      hrefLenght = href.length,
      hrefPos = href.indexOf("#"),
      hrefPage = href.slice(hrefPos+1);

      if (hrefPos > '1'){
         switch (hrefPage) {
            case 'stany': request = 'images06'; break;
            case 'podlahy': request = 'images07'; break;
            case 'mobiliar': request = 'images08'; break;
            case 'osvetlenie': request = 'images09'; break;
            case 'ozvucenie': request = 'images10'; break;
            default: request = 'images06';
         }
         $('#leftSlider').remove(); 
         $.get('/ajax/loadImgs.php?request='+request, function(data){
            var newData = data.split('//DELIMITER//');
            $("#leftSliderWrap").html(newData[0]);
            $("#botThree2").html(newData[1]);
            loadSlider();
         });
         $('#rightSubMenuScroller .rsmEntry').removeClass('active');
         $('#rightSubMenuScroller #'+request).addClass('active');
      }
   /* ********* */
   $('#topMenu a').click(function(){
         var href = $(this).attr('href'),
         hrefLenght = href.length,
         hrefPos = href.indexOf("#"),
         hrefPage = href.slice(hrefPos+1);

         if (hrefPos > '1'){
            switch (hrefPage) {
               case 'stany': request = 'images06'; break;
               case 'podlahy': request = 'images07'; break;
               case 'mobiliar': request = 'images08'; break;
               case 'osvetlenie': request = 'images09'; break;
               case 'ozvucenie': request = 'images10'; break;
               default: request = 'images06';
            }
            $('#leftSlider').remove(); 
            $.get('/ajax/loadImgs.php?request='+request, function(data){
               var newData = data.split('//DELIMITER//');
               $("#leftSliderWrap").html(newData[0]);
               $("#botThree2").html(newData[1]);
               loadSlider();
            });
            $('#rightSubMenuScroller .rsmEntry').removeClass('active');
            $('#rightSubMenuScroller #'+request).addClass('active');
         }
   });
});

function loadSlider(){
   $("#leftSlider").nivoSlider({
      effect:"fade",
      slices:15,
      animSpeed:500,
      pauseTime:5000,
      startSlide:0,
      directionNav:false,
      directionNavHide:true,
      controlNav:false,
      controlNavThumbs:false,
      controlNavThumbsFromRel:true,
      keyboardNav:true,
      pauseOnHover:false,
      manualAdvance:false
   });
}

