//最后一张图片右键头不可点，第一张图片左箭头不可点
function unactiveViewBtn(){
	$('.viewBtnWrap #viewPrev').removeClass('unactive');
	$('.viewBtnWrap #viewNext').removeClass('unactive');
	if(RichTextUitl.imageViewer.index == 0){
		$('.viewBtnWrap #viewPrev').addClass('unactive');
	}else if(RichTextUitl.imageViewer.index == (RichTextUitl.imageViewer.length-1)){
		$('.viewBtnWrap #viewNext').addClass('unactive');
	}
}
$(document).ready(function() {
	$(window).keydown(function (event) {
		if (event.keyCode == 27) {
			$('.viewBtnWrap').fadeOut();
			if (typeof sendMessageFadeInOrOut == 'function') {
				// 课程那边图片的额外操作
				sendMessageFadeInOrOut(0)
			}
		}
	});
	$('body').on('click','.viewBtnWrap #viewPrev',function() {
		RichTextUitl.imageViewer.prev();
		unactiveViewBtn()
	})
	$('body').on('click','.viewBtnWrap #viewNext',function() {
		RichTextUitl.imageViewer.next();
		unactiveViewBtn()
	})
	$('body').on('click','.viewBtnWrap #viewZoomIn',function() {
		RichTextUitl.imageViewer.zoom(0.1);
	})
	$('body').on('click','.viewBtnWrap #viewZoomOut',function() {
		RichTextUitl.imageViewer.zoom(-0.1);
	})
	$('body').on('click','.viewBtnWrap #viewFlip',function() {
		RichTextUitl.imageViewer.rotate(-90);
	})
	$('body').on('click','.viewBtnWrap #viewDownload',function() {
		var src = RichTextUitl.imageViewer.image.getAttribute('src');
		//http://p.cldisk.com/star3/600_900Q80/c13d749411edd5a213b0ce9078a45340.jpeg?rw=600&rh=900&_fileSize=78728&_orientation=1
		if(src){
			//获取objectId
			var objectId = src.substring(src.lastIndexOf("/")+1,src.lastIndexOf("."));
			if(src.indexOf('star4') > -1){
				objectId = src.substring(src.indexOf("star4") + 6, src.lastIndexOf("/"))
			}
			if(objectId){
				Viewer.isDownloadImg = true;
				//获取云存储下载地址
				YunFileUtil.downloadYunFile('', objectId);
			}
		}
	})

	$('body').on('click','.viewBtnWrap #viewClose',function() {
		RichTextUitl.imageViewer.hide();
		RichTextUitl.imageViewer.destroy();
		$('.viewBtnWrap').fadeOut();

		if (typeof sendMessageFadeInOrOut == 'function') {
			// 课程那边图片的额外操作
			sendMessageFadeInOrOut(0)
		}
	})
	$('body').on('click','.viewer-canvas',function(e){
		if(typeof RichTextUitl.imageViewer != 'undefined' && RichTextUitl.imageViewer){
			RichTextUitl.imageViewer.destroy();
		}
		$('.viewBtnWrap').fadeOut();
		if (typeof sendMessageFadeInOrOut == 'function') {
			// 课程那边图片的额外操作
			sendMessageFadeInOrOut(0)
		}
	});
	$('body').on('click','.viewer-canvas img',function(e){
		e.stopPropagation();
	});
});
