var scroller_initHeight;
var scroller_timer;
var scroller_htmlString = "<div id='scroller_div' style='width:45px;height:42px;margin-top:10px;margin-left:170px;'><img id='scroller_up' src='images/scroll_up.png' alt='' style='display:block;' /><img id='scroller_down' src='images/scroll_down.png' alt='' style='display:block;' /></div>";

$(document).ready(function() {
    setTimeout(
      function() {
	scroller_initHeight = $('#content1_scroller').height();
        scroller_resize();
	}
      ,100);
});
$(window).resize(function() {
    scroller_resize();
});

function scroller_resize() {
  windowHeight = $(window).height();
  footerHeight = $('#footer').height();
  maxHeight = windowHeight - footerHeight - 180;
  $('#content1_scroller').get(0).scrollTop = 0;
  /*
  alert(footerHeight);
  alert(windowHeight);
  alert(maxHeight);
  alert(scroller_initHeight);
  */
  if(scroller_initHeight > maxHeight) {
    $('#scroller_div').remove();
    var newHeight = maxHeight - 60;
    if(newHeight < 60) newHeight = 60;
    $('#content1_scroller').height(newHeight);
    $('#content1_scroller').css('overflow','hidden');
    $('#content1').eq(0).append(scroller_htmlString);
    $('#scroller_down').hover(function(){
      clearTimeout(scroller_timer);
      scroller_timer = setInterval(scroller_scrollDown,50);
    },
    function(){
      clearTimeout(scroller_timer);
    });
    $('#scroller_up').hover(function() {
      clearTimeout(scroller_timer);
      scroller_timer = setInterval(scroller_scrollUp,50);
    },
    function() {
      clearTimeout(scroller_timer);
    });
  }
  else {
    $('#scroller_div').remove();
    $('#content1_scroller').height(scroller_initHeight);
  }
  if($('#content1_scroller').height() < 100)
  	 $('#content1_scroller').height(100);
  
}

function scroller_scrollDown() {
  $('#content1_scroller').get(0).scrollTop += 4;
}
function scroller_scrollUp() {
  $('#content1_scroller').get(0).scrollTop -= 4;
}

