$(document).ready(function () {
  $("a.blanktarget").attr('target', '_blank');
  $('#im_newsticker div.news').each(function() {
    $(this).click(function() {
			var a = $(this).find("h5 a");
			var href= a.attr('href');
			if ($(a).attr('target').toLowerCase() == '_blank' || $(a).attr('target').toLowerCase() == 'blank') {
			  window.open(href);
			}else {
			  window.location = href;
			}
    });
    imnewsticker.init('#im_newsticker');
  });
  var row = {elems: [], maxh: 0};
  var newrow = false;
  var cols = 3;
  var acol = 0;
  $('div.modul_preview h3').each(function() {
    row.elems.push($(this));
    row.maxh = Math.max(row.maxh, $(this).height());
    if (++acol == cols) {
      acol = 1;
      imcommon.adjustheight(row.elems, row.maxh);
      row = {elems: [], maxh: 0};
    }
  });
  if (row.elems.length > 1) imcommon.adjustheight(row.elems, row.maxh);
  
});
var imnewsticker = {
  ms: 40,
  step: 1,
  id: null,
  h: null,
  ho: null,
  iid: null,
  init: function(id) {
    this.id = id;
    this.h = $(this.id+" .inner").height();
    this.ho = $(this.id).height();
    $(this.id).mouseover(this.pause);
    $(this.id).mouseout(this.animate);
    this.reset();
    this.animate();
  },
  reset: function() {
    $(imnewsticker.id+" .inner").css('top', imnewsticker.ho);
  },
  pause: function() {
    clearInterval(imnewsticker.iid);
  },
  animate: function() {
    clearInterval(imnewsticker.iid);
    imnewsticker.iid = window.setInterval(imnewsticker.move, imnewsticker.ms);
  },
  move: function() {
    var tpx = $(imnewsticker.id+" .inner").css('top');
    tpx = tpx.substr(0, tpx.length-2);
    if ((tpx*-1) > imnewsticker.h) {
      imnewsticker.reset();
    } else {
      $(imnewsticker.id+" .inner").css('top', tpx-imnewsticker.step);
    }
  }
}
var imcommon = {
  adjustheight: function(elems, h) {
    for(var j in elems) $(elems[j]).css('height', h);
  }
}
