function yxxxxxx(observer,eventType,callFunc){if(observer.attachEvent){observer.attachEvent('on'+eventType,callFunc);}else if(observer.addEventListener){observer.addEventListener(eventType,callFunc,false);}}function vrvRemoveEventListener(observer,eventType,callFunc){if(observer.attachEvent){observer.detachEvent('on'+eventType,callFunc);}else if(observer.addEventListener){observer.removeEventListener(eventType,callFunc,false);}}function vrvAddVRView(args){yxxxxxx(window,'load',function(){new VRView(args)} );}var xxyxxxx = function(owner,numImages,initialIndex,urlPrefix,fileExtension){this.init(owner,numImages,initialIndex,urlPrefix,fileExtension);};xxyxxxx.prototype={init: function(owner,numImages,initialIndex,urlPrefix,fileExtension){this.owner=owner;this.totalImages=numImages;this.loadedImages=0;this.ok=true;this.images=new Object();for( var ii=0;ii<numImages;ii++){var iiStr=ii;if(ii<10){iiStr='00'+ii;}else if(ii<100){iiStr='0'+ii;}var fullURL=urlPrefix+iiStr+fileExtension;this.images[ii]=new Image();var self=this;this.images[ii].onload=function(){if(self.ok){self.completeOneImage();}}
this.images[ii].onerror=function(){self.abort();}
this.images[ii].onabort=function(){self.abort();}
this.images[ii].src=fullURL;}},completeOneImage: function(){this.loadedImages++;this.owner.onLoadOneImage(this.loadedImages);if( this.loadedImages==this.totalImages ){this.owner.onLoadAllImages();}},
abort: function(){if(this.ok){this.ok=false;for(var ii=0;ii<this.totalImages;ii++){this.images[ii].src='';}this.owner.onLoadImageFailed();}}};var vrvcs ={x: 0, y: 0,init: function(){this.setEvent('mouse');this.setEvent('touch');},setEvent: function(type){yxxxxxx( document, type+'move', function(e){vrvcs.refresh(e);} );},refresh: function(e){if(!e){e=window.event;}if(e.type=='mousemove'){this.set(e);}else if(e.touches){this.set(e.touches[0]);}},set: function(e){if(e.pageX||e.pageY){this.x=e.pageX;this.y=e.pageY;}else if(e.clientX || e.clientY){this.x = e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;this.y = e.clientY+document.body.scrollTop+document.documentElement.scrollTop;}}};vrvcs.init();var VRV_DragGlider=function(owner,enable){this.init(owner,enable);};VRV_DragGlider.prototype={init: function(owner,enable){this.enable=enable;this.owner=owner;this.size=4;this.idx=0;this.count=0;this.interval=null;this.array=new Array(this.size);for(var ii=0;ii<this.size;ii++){this.array[ii] = {t:0, x:0, y:0}}},clear: function(x,y){if(this.interval!=null){clearInterval(this.interval);}this.interval=null;this.idx=0;this.lastIdx=0;this.count=0;this.vx=0;this.vy=0;this.ax=0;this.ay=0;},set: function(x,y){this.array[this.idx].t= +new Date();this.array[this.idx].x=x;this.array[this.idx].y=y;this.count++;this.lastIdx=this.idx;this.idx++;if(this.idx==this.size){this.idx=0;}},startGlide: function(){var ok=false;if(this.size<=this.count){if(this.timeFromLastMoved()<60){var i0=this.idx;var i1=this.lastIdx;var dt=this.array[i1].t-this.array[i0].t;var vx=(this.array[i1].x-this.array[i0].x)/dt;var vy=(this.array[i1].y-this.array[i0].y)/dt;var v0=Math.sqrt(vx*vx+vy*vy);var a=0.008;this.vx=vx;this.vy=vy;this.ax=a*vx/v0;this.ay=a*vy/v0;var self=this;this.interval=setInterval(function(){self.glidingHandler()},10);ok=true;}}return ok;},glidingHandler: function(){var t= this.timeFromLastMoved(); var vx=this.vx-this.ax*t;var doContinue=((vx<0)==(this.vx<0));if(doContinue){var x=this.array[this.lastIdx].x+this.vx*t-0.5*this.ax*t*t;var y=this.array[this.lastIdx].y+this.vy*t-0.5*this.ay*t*t;doContinue=this.owner.onMoveDrag(x,y);}if(doContinue==false){clearInterval(this.interval);this.owner.onEndDrag();this.interval=null;}},timeFromLastMoved: function(){return +new Date() - this.array[this.lastIdx].t;}};
var xxxyxxx=function(owner,targetDiv,gliding){this.init(owner,targetDiv,gliding);this.addListeners();};xxxyxxx.prototype={init: function(owner,targetDiv,glidingEnable){this.owner=owner;this.targetDiv=targetDiv;this.dragOrigin={x: 0, y: 0};this.prevCurPos={x: 0, y: 0};this.dragging=false;this.loadComplete=false;this.enable=false;this.dragGlider=new VRV_DragGlider(owner,glidingEnable);},addListeners: function(){var self=this;this.targetDiv.onselectstart=function(){return false;}
yxxxxxx( this.targetDiv, 'mousedown', function(e){self.mouseDownHandler(e);} );yxxxxxx( this.targetDiv, 'touchstart', function(e){self.mouseDownHandler(e);} );yxxxxxx( document, 'mousemove', function(e){self.mouseMoveHandler(e);} );yxxxxxx( document, 'touchmove', function(e){self.mouseMoveHandler(e);} );yxxxxxx( document, 'mouseup', function(e){self.documentUpHandler(e);} );yxxxxxx( document, 'touchend', function(e){self.documentUpHandler(e);} );},mouseDownHandler: function(e){if( this.enable){if(this.dragGlider.enable){this.dragGlider.clear();}vrvcs.refresh(e);this.dragOrigin.x=this.prevCurPos.x=vrvcs.x;this.dragOrigin.y=this.prevCurPos.y=vrvcs.y;this.dragging=true;this.preventDefaults(e,true);this.owner.onStartDrag();this.cancelEvent(e);}},mouseMoveHandler: function(e){if(this.dragging){if( vrvcs.x!=this.prevCurPos.x || vrvcs.y!=this.prevCurPos.y ){this.prevCurPos.x = vrvcs.x;this.prevCurPos.y = vrvcs.y;var x=vrvcs.x-this.dragOrigin.x;var y=vrvcs.y-this.dragOrigin.y;if(this.dragGlider.enable){this.dragGlider.set(x,y);}vrvcs.refresh(e);this.owner.onMoveDrag(x,y);}}},documentUpHandler: function(e){if(this.dragging){this.dragging=false;var glidingStart=false;if(this.dragGlider.enable){glidingStart=this.dragGlider.startGlide();}if(glidingStart==false){this.owner.onEndDrag();}}},setEnable: function(){this.enable=true;},preventDefaults: function(e, selection){if(!e){e=window.event;}if(e.preventDefault){e.preventDefault();}e.returnValue = false;if(selection && document.selection){document.selection.empty();}},cancelEvent: function(e){if(!e){e = window.event;}if(e.stopPropagation){e.stopPropagation();}e.cancelBubble = true;}};var VRView = function(args){this.init(args);};VRView.prototype={init: function(args){this.nyd=true;this.targetDiv = this.getOption(args,'targetID','VRView');if(typeof(this.targetDiv) == 'string'){this.targetDiv = document.getElementById(this.targetDiv);}this.wrapAround=this.getOption(args,'wrapAround',false);this.numImages=this.getOption(args,'numImages',1);this.initialIndex=this.getOption(args,'initialIndex',1);this.currentIndex=this.initialIndex;this.dragStartIndex=this.initialIndex;this.dragLength=this.getOption(args,'dragLength',30);this.imagesPerPixel = this.numImages/this.dragLength;var gliding=this.getOption(args,'gliding',false);var fileExtension=this.getOption(args,'fileExtension','.jpg');var urlPrefix=this.getOption(args,'urlPrefix','./');if(args!=undefined&&args['targetWidth']!=undefined){this.targetDiv.style.width=args['targetWidth']+'px';}if(args!=undefined&&args['targetHeight']!=undefined){this.targetDiv.style.height=args['targetHeight']+'px';}this.dragTracker=new xxxyxxx(this,this.targetDiv,gliding);this.preloader=new xxyxxxx(this,this.numImages,this.initialIndex,urlPrefix,fileExtension);},getOption: function(args,name,defaultVal){return (args!=undefined&&args[name]!=undefined)?args[name]:defaultVal;},onLoadImageFailed: function(){this.targetDiv.innerHTML='<div class="vrvPreloadFrame"><div class="vrvPreloadIndicatorText">画像の読み込みに失敗しました</div></div>';alert('画像の読み込みに失敗しました。処理を中止します。');},onLoadOneImage: function(cur){var prog = Math.round( cur*100/this.numImages );if( this.nyd&&this.preloader.images&&this.preloader.images[this.initialIndex]&&this.preloader.images[this.initialIndex].complete ){this.setImage(this.initialIndex);}this.targetDiv.innerHTML='<div class="vrvPreloadFrame"><div class="vrvPreloadIndicatorBack"><div class="vrvPreloadIndicator" style="width:'+prog+'%;"></div></div><div class="vrvPreloadIndicatorText">'+cur+'/'+this.numImages+' '+prog+'%</div></div>';},onLoadAllImages: function(){this.targetDiv.innerHTML='';if( this.nyd ){this.setImage(this.initialIndex);}this.loadComplete=true;this.dragTracker.setEnable();},onStartDrag: function(){this.dragStartIndex=this.currentIndex;},onMoveDrag: function(dx,dy){var doContinue=true;var movedIndex=this.dragStartIndex+Math.round(this.imagesPerPixel*dx);if(movedIndex<0||this.numImages<=movedIndex){if(this.wrapAround){var r=(movedIndex+0.5)/this.numImages;r-=Math.floor(r);movedIndex=Math.floor(r*this.numImages);}else if(movedIndex<0){movedIndex=0;doContinue=false;}else{movedIndex=this.numImages-1;doContinue=false;}}this.currentIndex=movedIndex;this.setImage(movedIndex);return doContinue;},onEndDrag: function(){},setImage: function(ii){if( 0<=ii && ii<this.numImages ){this.targetDiv.style.backgroundImage='url('+this.preloader.images[ii].src+')';this.nyd=false;}}};


