function getScrollerWidth() {
	var scr = null;
	var inn = null;
	var wNoScroll = 0;
	var wScroll = 0;

	// Outer scrolling div
	scr = document.createElement('div');
	scr.style.position = 'absolute';
	scr.style.top = '-1000px';
	scr.style.left = '-1000px';
	scr.style.width = '100px';
	scr.style.height = '50px';
	// Start with no scrollbar
	scr.style.overflow = 'hidden';

	// Inner content div
	inn = document.createElement('div');
	inn.style.width = '100%';
	inn.style.height = '200px';

	// Put the inner div in the scrolling div
	scr.appendChild(inn);
	// Append the scrolling div to the doc
	document.body.appendChild(scr);

	// Width of the inner div sans scrollbar
	wNoScroll = inn.offsetWidth;
	// Add the scrollbar
	scr.style.overflow = 'auto';
	// Width of the inner div width scrollbar
	wScroll = inn.offsetWidth;

	// Remove the scrolling div from the doc
	document.body.removeChild(
	document.body.lastChild);

	// Pixel width of the scroller
	return (wNoScroll - wScroll);
}

$(document).ready(function() {
	var area=document.getElementById&&!document.all;
	var isdrag=false;
	var x = 0;
	var y = 0;
	var scrollbarWidth = getScrollerWidth();

	function movemouse(e){	
		if(isdrag){
			document.getElementById('pdfPage').scrollLeft -=  (area ? e.clientX - x : event.clientX - x);
			x = area ? e.clientX: event.clientX;
			document.getElementById('pdfPage').scrollTop -= (area ? e.clientY - y : event.clientY - y);
			y = area ? e.clientY : event.clientY;

			return false;
		}
	}

	function selectmouse(e) {
		x = area ? e.clientX : event.clientX;
		y = area ? e.clientY : event.clientY;
		var container = document.getElementById('pdfPage');
		clickContainerPosX = x - container.offsetLeft;
		clickContainerPosY = y - container.offsetTop;
		//если нажали на скроллбар, то выходим из функции
		if ((clickContainerPosX > parseInt(container.style.width)-scrollbarWidth) || (clickContainerPosY > parseInt(container.style.height)-scrollbarWidth)) {
			return false;
		}
		isdrag = true;
		document.getElementById('pdfPage').onmousemove=movemouse;
		return false;
	}

	function mouseup(e){
		isdrag = false;
	}

	//Настраиеваем изменение курсора при наведении на страницу pdf
	var gecko = navigator.userAgent.indexOf("Gecko/") != -1;
	var opera = navigator.userAgent.indexOf("Opera/") != -1;
		
	if (opera) {
		$('#pdfPage').bind("mousemove", function(){
			$('#pdfPage').css({cursor:'default'});
		}).mousedown(function() {
			$('#pdfPage').css({cursor: 'move'});
		});
	} else if (gecko) {
		$('#pdfPage').bind("mousemove", function(){
			$('#pdfPage').css({cursor:'-moz-grab'});
		}).mousedown(function() {
			$('#pdfPage').css({cursor: '-moz-grabbing'});
		});
	} else {
		$('#pdfPage').bind("mousemove", function(){
			$('#pdfPage').css({cursor:'move'});
		}).mousedown(function() {
			$('#pdfPage').css({cursor: 'move'});
		});
	}

	//Добавляем обработчки на скролл страницы перетаскиванием
	document.getElementById('pdfPage').onmousedown=selectmouse;
	document.onmouseup=mouseup;
});
