var links = {
  clicks: function() {
    $('.box_search_result').click(function(event) {
      el = event.target;

      if ($(el).hasClass('infobox_button')) {
        el = $(el).parents('.item');
        el = $(el).children('a.imgframe')[0];
        location.href = el.href;
      }
      else {
        if ($(el).hasClass('item')) {  
        }
        else {
          el = $(el).parents('.item');
        }
        el = $(el).children('a.imgframe')[0];
        location.href = el.href;
      }
    });
  }
}


var infobutton = {
  size: function() {
    var docHeight = $(document).height();

    $('.infobox_button').each(function() {
      var buttonHeight = $(this).height();
      var bottomSize = docHeight - $(this).offset().top - buttonHeight;

      var item = $(this).parents('.item');
      var infobox = item.children('.infobox')[0];

      if ($(infobox).height() > bottomSize ) {
        $(infobox).addClass('infobox_top');
        var topSize = - $(infobox).height();
        $(infobox).css('top', topSize + 'px');
      }
    });
  },
  overs: function() {
    $('.box_search_result').mouseover(function(event) {
      el = event.target;

      if ($(el).hasClass('infobox_button')) {
        infobox = $($(el).parents('.item')).children('.infobox')[0];
        if ($(infobox).hasClass('invisible')) {
          $(infobox).removeClass('invisible');
        }
      }
    });
  },
  outs: function() {
    $('.box_search_result').mouseout(function(event) {
      el = event.target;

      if ($(el).hasClass('infobox_button')) {
        infobox = $($(el).parents('.item')).children('.infobox')[0];
        if ($(infobox).hasClass('invisible')) {
        }
        else {
          $(infobox).addClass('invisible');
        }
      }
    });
  }
}


$(document).ready(function() {
  links.clicks();
  infobutton.overs();
  infobutton.outs();
  infobutton.size();
  
  if ($('.carousel').length > 0) {
    $('div.carousel').carousel( {
      autoSlide: true,
      autoSlideInterval: 5000,
      delayAutoSlide: 3000,
      loop: true,
      effect: "fade",
      pagination: true
    });
  }
  else if ($('.box_minicarousel').length > 0) {
    // $('.minicarousel').jcarousel({scroll: 1});
    // $('.jcarousel-item a').tipsy();
  }
  else if ($('.box_objects').length > 0) {
      $('.box_link a').tipsy();
  }
});
