jQuery(function( $ ){
  disableSelection($('#descriptionPanel').get(0))	
	
	var cursor = document.createElement('div');
	cursor.id = "scrollCursor";
  cursor.style.display = "none";
	document.body.appendChild(cursor);

	var output = document.createElement('input');
	output.id = "output";
	output.style.position = "absolute";
	output.style.top = "0px";
	output.style.left = "0px";
	
	//document.body.appendChild(output);

	
	var scrollSpeed = 0;
	var t = null;
	var scrollStopped = false;

	
	if($('#logoDiv').get(0)) {
	  $('#descriptionPanel').css('top', 178);
	} else {
	  $('#descriptionPanel').css('top', 141);
	}
  $('#descriptionPanel').css('display', 'block');
	
	
	$('#main').mousemove(function(e){
        
    
    if($('#descriptionPanel').css('visibility') == "visible" ) {
      startInterval();
    } else {
      stopInterval();
      return;
    }
    
   
		if($('#descriptionPanel').get(0).scrollHeight <= $('#descriptionPanel').height() ) {
		  return;
		}

    var relX = e.pageX - $('#descriptionPanel').offset().left
    var relY = e.pageY - $('#descriptionPanel').offset().top
    //output.value = relX + "," + relY 

    if(relX < 0 || relX > $('#descriptionPanel').width()) {
		  stopScroll();
      return;
    }

    if(relY < 90 && relY > -50) {
      cursor.style.backgroundPosition = "top right"
      scrollSpeed = -3;
		  startScroll();
    }
    else if(relY > $('#descriptionPanel').height() - 90 && relY < $('#descriptionPanel').height() + 50) {
      cursor.style.backgroundPosition = "top left"
      scrollSpeed = 3;
		  startScroll();
    }
    else {
		  stopScroll();
    }
    
    cursor.style.top = ( e.pageY -10 ) + "px"
    cursor.style.left = ( e.pageX - 60 ) + "px"
		
	});
		
  function startScroll()
  {
    scrollStopped = false;      
    cursor.style.display = "block";
  }
  
  function stopScroll()
  {
    scrollStopped = true;
    cursor.style.display = "none";
  }
  
  function startInterval()
  {
    if(!t) {
      t = setInterval( function(){ 
        output.value = scrollSpeed
        
        if(scrollStopped) {
          scrollSpeed = 0;
        }
        $('#descriptionPanel').get(0).scrollTop += scrollSpeed
      }, 16 );
    }
  }
	
	function stopInterval()
	{
    if(t) {
	    clearInterval(t)
	    t = null;
	  }
	}
	
});




function disableSelection(target){
  if (typeof target.onselectstart!="undefined") //IE route
    target.onselectstart=function(){return false}
  else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
    target.style.MozUserSelect="none"
  else //All other route (ie: Opera)
    target.onmousedown=function(){return false}
  target.style.cursor = "default"
}



