var currentShown=null;
function showNews(oNews) {
	if(navigator.appName=='Microsoft Internet Explorer')
	{
		if(currentShown) {
			currentShown.nextSibling.style.display='none';
			currentShown.style.display="block";
			currentShown.previousSibling.style.display="block";
		}
		var oParagraph=oNews.nextSibling;
		oParagraph.style.display='block';
		currentShown=oNews;
		oNews.style.display='none';
		var oShort=oNews.previousSibling;
		oShort.style.display="none";
	}
	else
	{
		if(currentShown) {
			currentShown.nextSibling.nextSibling.style.display='none';
			currentShown.style.display="block";
			currentShown.previousSibling.previousSibling.style.display="block";
		}
		var oParagraph=oNews.nextSibling.nextSibling;
		oParagraph.style.display='block';
		currentShown=oNews;
		oNews.style.display='none';
		var oShort=oNews.previousSibling.previousSibling;
		oShort.style.display="none";
	}
}

$(document).ready(function(){
  scrollNews.init();
});

var scrollNews = {
  elements: null,

  settings: {
    speed: 2
  },

  init: function() {
    scrollNews.elements = $('#homepage_main div.home_block ul.news');
    if (scrollNews.elements.length > 0) {
      scrollNews.elements.each(function(i, el) {
        scrollNews.autoscroll($(el));
      });
    }
  },

  /*
   * inspired by http://plugins.jquery.com/project/autoScroller
   * element is a jQuery object
   */
  autoscroll: function(element) {
    // double make sure the autoScroller-container has the correct css position and overflow property
    element.parent().css({
      position: 'relative',
      overflow: 'hidden'
    });

    // set element style
    element.css({
      position: 'absolute',
      top:      0
    });
    // get element height
    contentDivHeight = element.height();

    // call periodical
    element.everyTime(100, function(i){
      if (scrollNews.settings.speed != 0) {
        if (parseInt($(this).css('top')) > (contentDivHeight * (-1) + 8)) {
          // move scroller upwards
          offset = parseInt($(this).css('top')) - scrollNews.settings.speed + "px";
          $(this).css({'top':offset});
        }
        else {
          // reset to original position
          offset = parseInt($(this).parent().height()) + 8 + "px";
          $(this).css({
            top: offset
          });
        }
      }
    });

    // on mouse over event, pause the scroller
    element.bind('mouseover', function() {
      speed = scrollNews.settings.speed;
      scrollNews.settings.speed = 0;
    });

    // on mouse out event, start the scroller
    element.bind('mouseout', function() {
      scrollNews.settings.speed = speed;
    });
  }
}
