/* #nav hover */
(function($) {
  $("#nav li").mouseenter(function() {
    $(this).addClass("hover");
  });
})(jQuery);

/* #gallery */
(function($) {
  $(".gallery .bignav .back").mouseenter(function() {
    $(this).addClass("back_hover");
  }).mouseleave(function() {
    $(this).removeClass("back_hover");
  })
  $(".gallery .bignav .forward").mouseenter(function() {
    $(this).addClass("forward_hover");
  }).mouseleave(function() {
    $(this).removeClass("forward_hover");
  })
})(jQuery);

(function($){
  var t;
  var imgs = {
    1:"images/data/contentheader02.png"
  }; // see n2iteks ajaxiga kuskilt

  var count = 0;

  if($('#gallery_id').val() != 0){

    $.ajax({
      type: 'GET',
      url: 'json.php?controller=gallery&action=getimages',
      dataType: 'json',
      success: function(j) {
        imgs = j.images;
        if(imgs != null) {
          var all_images_html = "";
          var bubbles = "";

          for ( key in imgs ) {
            all_images_html += '<img id="splash_' + key + '" style="position: absolute;" height="300" width="900" src="'+imgs[key]+'" alt="" class="hidden" />';
            bubbles += '<span class="bubbles" id="bubble_' + key + '"></span>';
            count++;
          }

          $(".splash img").after(all_images_html);
          $("#bubbles span").after(bubbles);
          t = setTimeout(animate, 5000);
        }
      },
      data: {
        gallery: $('#gallery_id').val()
      },
      async: true
    });

  }

  $('.bubbles').live('click', function(){
    var item = $(this).attr('id').replace('bubble_', '');
    clearTimeout(t);
    var current = $("#current_splash_id").val();
    $("#current_splash_id").val(item);
    $("#splash_" + current).css("z-index", 1).fadeOut(2000);
    $("#splash_" + item).css("z-index", 0).removeClass("hidden").fadeIn(2000);
    $('#bubble_' + current).removeClass('active');
    $('#bubble_' + item).addClass('active');
    t = setTimeout(animate, 7000);
  });



  function animate() {
    var current = $("#current_splash_id").val();
    var next = 0;

    next = parseInt(current) + 1;

    if(next > count)
      next = 0;

    $("#current_splash_id").val(next);

    $("#splash_" + current).css("z-index", 1).fadeOut(2000);
    $("#splash_" + next).css("z-index", 0).removeClass("hidden").fadeIn(2000);
    $('#bubble_' + current).removeClass('active');
    $('#bubble_' + next).addClass('active');
    t = setTimeout(animate, 7000);
  }

})(jQuery);


