/* JS - DELO
 */

(function ($) {
$(document).ready(function() {

	// Cycle ul element inside ul
	// Etelje - www.etelje.com
        var wrapper = $(".front #block-views-naslovka-header");
	    var items = $('.front #block-views-naslovka-header .view-content .views-row');
        var i = 1;
        var stop = false;

        wrapper.append('<div class="navigation"><ul></ul></div>');
        var holder = $('.front #block-views-naslovka-header div.navigation ul');

        items.each(function() {
           holder.append('<li class="views-row-' + i + '"><a href="javascript:void(0);" rel="views-row-' + i + '"></a></li>');
           i++;
        });

        $(".front #block-views-naslovka-header div.navigation ul li.views-row-1 a").addClass('active');

        $('.front #block-views-naslovka-header div.navigation ul li a').click(function (){
            var row = $(this).attr('rel');
            $(".front #block-views-naslovka-header .view-content .views-row").hide();
            $(".front #block-views-naslovka-header .view-content ." + row).show();
            stop = true;
            $(".front #block-views-naslovka-header ul li a").removeClass('active');
            $(this).addClass('active');
            return 0;
        });

	if(items.length>1){
		cycleDiv(1, items.length, 5000);
	}

	function cycleDiv(startFrame, endFrame, delay) {
		setTimeout(cycle(startFrame, startFrame, endFrame, delay), delay);
	}

	function cycle(frame, startFrame, endFrame, delay) {
		return (function() {
                    if(!stop){
			$('.front #block-views-naslovka-header .view-content .views-row-' + frame).fadeOut('slow');
			if (frame == endFrame) {
				frame = startFrame;
			} else {
				frame = frame + 1;
			}
			$('.front #block-views-naslovka-header .view-content .views-row-' + frame).fadeIn('slow');
                        $(".front #block-views-naslovka-header div.navigation ul li a").removeClass('active');
                        $(".front #block-views-naslovka-header div.navigation ul li.views-row-" + frame + " a").addClass('active');
			
                            setTimeout(cycle(frame, startFrame, endFrame, delay), delay + 2500);
                    }
	 })
	}

});
})(jQuery);

/**
 * Klub polet.
 */
(function ($) {
	$(document).ready(function() {

		// Cycle ul element inside ul
		// Etelje - www.etelje.com
	        var wrapper = $(".page-klub-polet #block-views-klub-polet-highlited-block-1");
		    var items = $('.page-klub-polet #block-views-klub-polet-highlited-block-1 .view-content .views-row');
	        var i = 1;
	        var stop = false;

	        wrapper.append('<div class="navigation"><ul></ul></div>');
	        var holder = $('.page-klub-polet #block-views-klub-polet-highlited-block-1 div.navigation ul');

	        items.each(function() {
	           holder.append('<li class="views-row-' + i + '"><a href="javascript:void(0);" rel="views-row-' + i + '"></a></li>');
	           i++;
	        });

	        $(".page-klub-polet #block-views-klub-polet-highlited-block-1 div.navigation ul li.views-row-1 a").addClass('active');

	        $('.page-klub-polet #block-views-klub-polet-highlited-block-1 div.navigation ul li a').click(function (){
	            var row = $(this).attr('rel');
	            $(".page-klub-polet #block-views-klub-polet-highlited-block-1 .view-content .views-row").hide();
	            $(".page-klub-polet #block-views-klub-polet-highlited-block-1 .view-content ." + row).show();
	            stop = true;
	            $(".page-klub-polet #block-views-klub-polet-highlited-block-1 ul li a").removeClass('active');
	            $(this).addClass('active');
	            return 0;
	        });

		if(items.length>1){
			cycleDiv(1, items.length, 5000);
		}

		function cycleDiv(startFrame, endFrame, delay) {
			setTimeout(cycle(startFrame, startFrame, endFrame, delay), delay);
		}

		function cycle(frame, startFrame, endFrame, delay) {
			return (function() {
	                    if(!stop){
				$('.page-klub-polet #block-views-klub-polet-highlited-block-1 .view-content .views-row-' + frame).fadeOut('slow');
				if (frame == endFrame) {
					frame = startFrame;
				} else {
					frame = frame + 1;
				}
				$('.page-klub-polet #block-views-klub-polet-highlited-block-1 .view-content .views-row-' + frame).fadeIn('slow');
	                        $(".page-klub-polet #block-views-klub-polet-highlited-block-1 div.navigation ul li a").removeClass('active');
	                        $(".page-klub-polet #block-views-klub-polet-highlited-block-1 div.navigation ul li.views-row-" + frame + " a").addClass('active');
				
	                            setTimeout(cycle(frame, startFrame, endFrame, delay), delay + 2500);
	                    }
		 })
		}

	});
	})(jQuery);;
/* JS - DELO
 */

(function ($) {
$(document).ready(function() {
  if($('.page-node .node-top-5').length > 0) {
    $('.top5-items').addClass('js-enabled');
    
    function checkPosition() {
      var innerPosition = $('.top5-items-inner').position();
      
      if(innerPosition.left >= 0) {
        $('.top5-controls .back').hide();
      } else {
        $('.top5-controls .back').show();
      }
      
      if(innerPosition.left <= -2908) {
        $('.top5-controls .next').hide();
      } else {
        $('.top5-controls .next').show();
      }
      
      for(i=0;i<5;i++){
        pos = -1*(i*727);
        itemPos = innerPosition.left;
        //alert(pos + " == " + itemPos);
        
        if(pos == itemPos) {
          $('.top5-link-items .top5-link-item').removeClass('active');
          $('.top5-link-items .top5-item-top'+(i+1)).addClass('active');
        } 
      }
      
    }
    
    enabledClick = true;
    
    function moveInner(position,itemClass) {
      enabledClick = false;
      
      $('.top5-items-inner').animate({
        left: position
      }, 500, function() {
        // Animation complete.
        checkPosition();
        
        enabledClick = true;
      });     
    }

    var myFile = document.location.toString();
    
    if (myFile.match('#')) { // the URL contains an anchor
      // click the navigation item corresponding to the anchor
      var myAnchor = myFile.split('#')[1];
      var targetItem = 'top5-item-'+myAnchor;       
      var itemPosition = $('.top5-items .'+targetItem).position();
      $('.top5-items-inner').css('left',-itemPosition.left + 'px');
      checkPosition();
      //moveInner(-itemPosition.left);
    } else {
      checkPosition();
    }
    
    $('.top5-controls .next').click(function(){
      if(enabledClick != false) {
        enabledClick = false;    
        moveInner('-=727');
      }   
    });
    
    $('.top5-controls .back').click(function(){
      if(enabledClick != false) {
        enabledClick = false;    
        moveInner('+=727');
      }  
    });
    
    $('.top5-link-items .top5-link-item').click(function(){
      if(enabledClick != false) {
        var targetItem = $(this).attr('rel');       
        var itemPosition = $('.top5-items .'+targetItem).position();       
        moveInner(-itemPosition.left);
      }
    });
    
    $('.top5-gallery-preview').hide();
    
    $('.top5-gallery-preview-0').show();
    
    $('.top5-gallery-preview-0').addClass('active');
    
    
    $('.top5-gallery-thumb').click(function(){
      var parent = $(this).parents('.top5-item-gallery');
      
      var targetItem = $(this).attr('rel');
      $(parent).find('.top5-gallery-preview.active').fadeOut();
      $('.'+targetItem).fadeIn();   
      $(parent).find('.top5-gallery-preview.active').removeClass('active');
      $('.'+targetItem).addClass('active');
    });
    
  }
});
})(jQuery);;
/* JS - DELO
 */

(function ($) {
$(document).ready(function() {
  if($('.videos-gallery-display').length > 0) {
    $('.videos-gallery-display .video-preview-list-item').hide();
    $('.videos-gallery-display .video-preview-list-item.item-1').show();
    
    $('.videos-gallery-display .jcarousel-item').click(function(){
      index = $(this).attr('jcarouselindex');
      $('.videos-gallery-display .video-preview-list-item').hide();
      $('.videos-gallery-display .video-preview-list-item.item-'+index).show();
    });
  }
});
})(jQuery);;
/*  
 * Zamenja font na Windows XP
 */
(function ($) {
  $(document).ready(function() {
    if (navigator.userAgent.indexOf("Windows NT 5.1") != -1)
    {
      $("#comments .title, .block h2.block-title, #top-navigation ul li a, \
         h1, h2, h3, h4, h5, h6, \
         .front .region-header .view-zadnje-dodano h2, \
         #front-columns .column-teaser-content h2, \
         .view-display-id-izpostavljena_galerija .post-title, \
         #front-top5 .top5-items .top5-item, \
         .front .region-header .field-name-field-kategorija, \
         .tagadelic.level1, .tagadelic.level2, .tagadelic.level3")
           .css('font-family', 'Arial, sans-serif')
           .css('font-weight', 'bold');
    }
  });
})(jQuery);

;
/* JS - DELO
 */

(function ($) {
$(document).ready(function() {
  if($('.page-node .node-geartest').length > 0) {
    $('.geartest-items').addClass('js-enabled');
    
    function checkPosition() {
      var elm_width = 727;
      var elm_count = $('.geartest-items-inner').children().size();
      var innerPosition = $('.geartest-items-inner').position();
      var width = elm_count * elm_width;
      if ($('.geartest-items-inner').width() != width) {
        $('.geartest-items-inner').css('width', width + 'px');
      }
      
      if(innerPosition.left >= 0) {
        $('.geartest-controls .back').hide();
      } else {
        $('.geartest-controls .back').show();
      }
      
      if(innerPosition.left <= elm_width - width) {
        $('.geartest-controls .next').hide();
      } else {
        $('.geartest-controls .next').show();
      }
      
      for(i=0;i<elm_count;i++){
        pos = -1*(i*727);
        itemPos = innerPosition.left;
        //alert(pos + " == " + itemPos);
        
        if(pos == itemPos) {
          $('.geartest-link-items .geartest-link-item').removeClass('active');
          $('.geartest-link-items .geartest-item-'+i).addClass('active');
          move_links('undefined', i);
        } 
      }
      
    }
    
    enabledClick = true;
    
    function moveInner(position,itemClass) {
      enabledClick = false;
      
      $('.geartest-items-inner').animate({
        left: position
      }, 500, function() {
        // Animation complete.
        checkPosition();
        
        enabledClick = true;
      });     
    }

    var myFile = document.location.toString();
    
    if (myFile.match('#')) { // the URL contains an anchor
      // click the navigation item corresponding to the anchor
      var myAnchor = myFile.split('#')[1];
      var targetItem = 'geartest-item-'+myAnchor;       
      var itemPosition = $('.geartest-items .'+targetItem).position();
      $('.geartest-items-inner').css('left',-itemPosition.left + 'px');
      checkPosition();
      //moveInner(-itemPosition.left);.geartest-link-list .item-list
    } else {
      checkPosition();
    }
    
    $('.geartest-controls .next').click(function(){
      if(enabledClick != false) {
        enabledClick = false;    
        moveInner('-=727');
      }   
    });
    
    $('.geartest-controls .back').click(function(){
      if(enabledClick != false) {
        enabledClick = false;    
        moveInner('+=727');
      }  
    });
    
    $('.geartest-link-items .geartest-link-item').click(function(){
      if(enabledClick != false) {
        var targetItem = $(this).attr('rel');       
        var itemPosition = $('.geartest-items .'+targetItem).position();       
        moveInner(-itemPosition.left);
      }
    });
    
    $('.geartest-gallery-preview').hide();
    
    $('.geartest-gallery-preview-0').show();
    
    $('.geartest-gallery-preview-0').addClass('active');
    
    
    $('.geartest-gallery-thumb').click(function(){
      var parent = $(this).parents('.geartest-item-gallery');
      
      var targetItem = $(this).attr('rel');
      $(parent).find('.geartest-gallery-preview.active').fadeOut();
      $('.'+targetItem).fadeIn();   
      $(parent).find('.geartest-gallery-preview.active').removeClass('active');
      $('.'+targetItem).addClass('active');
    });
    
    // Move slide up and down
    function move_links(direction, expose_item_nr) {
      var window_height = $('.geartest-link-list .item-list').height();
      var container_height = $('.geartest-link-list .item-list .geartest-link-items').outerHeight(true);
      var move_height = container_height > window_height ? $('.geartest-link-list .item-list .geartest-link-items .first').outerHeight(true) : 0;
      var curr_position = parseInt($('.geartest-link-list .item-list .geartest-link-items').css('top'));
      var actual_move = '';
      $('.geartest-link-list .geartest-links-control').removeClass('disabled');
      
      if (!expose_item_nr || expose_item_nr < 0) {
        move_height *= 3;
        if (direction == 'up') {
          actual_move = '-=' + move_height;
          if (curr_position - move_height < window_height - container_height && window_height - container_height < 0 ) {
            actual_move = window_height - container_height;    
            $('.geartest-link-list .geartest-links-control.up').addClass('disabled');  
          }
        }
        else {
          actual_move = '+=' + move_height;
          if (curr_position + move_height > 0 ) {
            actual_move = '0';
            $('.geartest-link-list .geartest-links-control.down').addClass('disabled');            
          }
        }
      }
      else {
        actual_move = '-' + expose_item_nr * move_height;
        if (expose_item_nr * move_height * -1 < window_height - container_height  && window_height - container_height < 0) {
          actual_move = window_height - container_height;
          $('.geartest-link-list .geartest-links-control.up').addClass('disabled');          
        }
        if (expose_item_nr * move_height * -1 > 0 ) {
          actual_move = '0';
          $('.geartest-link-list .geartest-links-control.down').addClass('disabled');          
        }
      }
      
      if (move_height == 0) {
        $('.geartest-link-list .geartest-links-control.up').addClass('disabled');  
        $('.geartest-link-list .geartest-links-control.down').addClass('disabled');        
      }
      
      $('.geartest-link-list .item-list .geartest-link-items').animate({
        top: actual_move
      }, 500);     
      
    }
    
    $('.geartest-link-list .geartest-links-control').click(function(){
      if ($(this).hasClass('up')) {
        move_links('up');
      }
      else {
        move_links('down');      
      } 
    });
    
  }
});
})(jQuery);
;
/*
 * JS - DELO
 */
(function ($) {
  Drupal.behaviors.club_polet_calendar = {};
  Drupal.behaviors.club_polet_calendar.attach = function(context, settings) {
    if($('.day-data').length > 0) {
      $('.day-data').siblings('.day').hover(
        function () {
          var div = $(this).siblings('.day-data');
          var queue = $('#event-container').queue();
          if (queue == undefined || queue.length == 0) {
            $('#event-container').replaceWith('');
            var newelem = $(this).parent().append('<div id="event-container">' + div.html() + '</div>')
            $('#event-container')
            .bind({
              mouseenter: function(){
                $(this).addClass('hover');
              },
              mouseleave: function(){
                $(this).removeClass('hover');
                $(this).fadeOut();
              }
            })
            .fadeIn()
            .css('left', $(this).position().left+10)
            .css('bottom', $(this).position().top+10);
          }
        },
        function () {
          var div = $('#event-container');
          var queue = div.queue();
          setTimeout(function(){
            if(!div.hasClass('hover')) {
              div.fadeOut();
            }
          },200);
        }
      );
    }
  }
})(jQuery);
;
(function ($) {
  $(document).ready(function() {
    if($('.jcarousel-skin-image-gallery-top').length > 0) {
      $('.jcarousel-skin-image-gallery-top .jcarousel-item').each(function() {
        var text = $(this).find('img').attr('title');
        
        if (text.length > 0) {
          $(this).append('<span class="hover-title">'+text+'</span>');
          $(this).find('.hover-title').show();
          $(this).find('.hover-title').hide();
        }
      });

      $('.jcarousel-skin-image-gallery-top .jcarousel-item').hover(
        function () {
          $(this).addClass('hover');
          var elem = this;

          setTimeout(function(){
            var queue = $(elem).queue();
            if ($(elem).hasClass('hover') && queue.length == 0) {
              $(elem).find('.hover-title').fadeIn();
            }            
          }, 500);
        },
        function () {
          $(this).removeClass('hover');
          var elem = this;

          setTimeout(function(){
            if(!$(elem).hasClass('hover')) {
              $(elem).find('.hover-title').fadeOut();
            }
          },500);
        }
      );
    }
  });
})(jQuery);;

