var isSVGZoomAction = false;
$(function() { //9949

	$('svg').each(function(d, i) {
		var svg = $(this);

		var scale = 0;

	        var width = svg.width();
	        var height = svg.height();

	        var scale = 1;

		//svg.on('mousewheel', function(event) {
		var onWheel = function(event) {

			if (!event.ctrlKey)
				return

			event.preventDefault();

			var delta = event.originalEvent.wheelDelta || -event.originalEvent.deltaY; // deltaY - firefox

			if (delta >= 0) {
				scale = scale * 1.1;
			}
			else {
				scale = scale * 0.9;
			}

			svg.width(width * scale);
			isSVGZoomAction = true;
			$( window ).resize();
		};

		svg.on('wheel', onWheel);
	});

	var curDown = false,
		curMove = false,
		curYPos = 0,
		curXPos = 0;
	
	$(window).mousemove(function(m){
		if(curDown){
			curMove = true;
			$('html').css('cursor', 'move');
			prevscrollX = window.scrollX;
			prevscrollY = window.scrollY;
			window.scrollBy((curXPos - m.pageX), (curYPos - m.pageY));
			if (prevscrollX == window.scrollX) {
				curXPos = m.pageX;
			}
			if (prevscrollY == window.scrollY) {
				curYPos = m.pageY;
			}
		}
	});
	$( "a" ).click(function( event ) {
		if (curMove)
			event.preventDefault();
	});

	$('svg').mousedown(function(m){
		var pr = false;
		var except = ["a", "button", "input"];
		$(m.target).parentsUntil( "svg" ).each(function() {
			var tagName = $( this ).prop("tagName").toLowerCase();
			if (tagName == "a" || tagName == "button" || tagName == "input") {
				pr = true;
			}
		});
		var include = except[m.target.nodeName.toLowerCase()];
		if (typeof include === "undefined" && !pr) {
			curYPos = m.pageY;
			curXPos = m.pageX;
			curDown = true;
		} 
	});
	
	$(window).mouseup(function(m){
		$('html').css('cursor', 'auto');
		curMove = false;
		curDown = false;
	});
	
	
	//59670
	$("svg").css("-webkit-touch-callout", "none").css("-webkit-user-select", "none").css("-khtml-user-select", "none").css("-moz-user-select", "none").css("-ms-user-select", "none").css("user-select", "none");
})
