'
s+='
'
s+=wrap({tag:'btn',style:'width:90px; z-index:44;',fn:'optPop()'},'Restart')
s+=wrap({tag:'btn',style:'width:90px; z-index:44;',fn:'moreBtn()'},'Jigsaws')
s+=wrap({id:'imageBtn',tag:'btn',class:'hi',style:'width:90px; z-index:44;',fn:'toggleImg()'},'Image')
s+=getPopHTML()
s+='
'
s+='
'
s+='
'
s+='
'
s+=wrap({cls:'copyrt',pos:'abs',style:'left:5px; bottom:3px'},`© 2021 MathsIsFun.com v${version}`)
s+='
'
docInsert(s)
my.can=new Can('canvasId',1000,1000,1)
my.jig=document.getElementById('jig')
my.fileName='passiflora.html'
let imgName=getQueryVariable('img')
if(imgName){imgName=decodeURIComponent(imgName)
imgName=imgName.replace(/[^0-9A-Za-z\-\.]+/g,'')
my.fileName=imgName}
console.log('fileName',my.fileName)
my.imgHome=(document.domain=='localhost'?'/mathsisfun':'')+'/puzzles/images/jigsaw/'
my.rowN=4
my.colN=4
my.pWd=100
my.pHt=100
my.animN=0
my.animTp=0
my.imgQ=true
my.p=[]
window.addEventListener('mousedown',mouseDown,false)
my.touchSelPiece=null
my.touchPt=null
my.jig.addEventListener('touchstart',ontouchstart,false)
my.jig.addEventListener('touchmove',ontouchmove,false)
my.jig.addEventListener('touchend',ontouchend,false)
optPop()}
function toggleImg(){my.imgQ=!my.imgQ
if(my.imgQ){loadImg(0.5,false)}else{loadImg(0,false)}
toggleBtn('imageBtn',my.imgQ)}
function toggleBtn(btn,onq){if(onq){document.getElementById(btn).classList.add('hi')
document.getElementById(btn).classList.remove('lo')}else{document.getElementById(btn).classList.add('lo')
document.getElementById(btn).classList.remove('hi')}}
function ontouchstart(evt){evt.preventDefault()
let touch=evt.targetTouches[0]
startIt(touch.clientX,touch.clientY)}
function ontouchmove(evt){let touch=evt.targetTouches[0]
my.touchSelPiece.moveTo(touch.pageX-my.touchPt.x,touch.pageY-my.touchPt.y)
my.touchPt=new Point(touch.pageX,touch.pageY)
evt.preventDefault()}
function ontouchend(evt){finishIt()
evt.preventDefault()}
function moreBtn(){window.location.href='http://www.mathsisfun.com/puzzles/jigsaw-puzzles-index.html'}
function optPop(){let pop=document.getElementById('optpop')
pop.style.transitionDuration='0.3s'
pop.style.opacity=1
pop.style.zIndex=12
pop.style.left='120px'
pop.style.top='20px'}
function userUpdate(){}
function getPopHTML(){let s=''
s+=''
let opts=[]
for(let i=3;i<=12;i++){opts.push({name:i,descr:i})}
s+=wrap({id:'rowN',tag:'sel',lbl:'Rows:',txt:'6',opts:opts})
s+=' '
s+=wrap({id:'colN',tag:'sel',lbl:'Cols:',txt:'6',opts:opts})
s+='
'
s+=''
s+='
'
s+='
'
return s}
function editYes(){let pop=document.getElementById('optpop')
pop.style.opacity=0
pop.style.zIndex=1
pop.style.left='-500px'
my.rowN=document.getElementById('rowN').value
my.rowN=Math.max(3,Math.min(my.rowN>>0,12))
my.colN=document.getElementById('colN').value
my.colN=Math.max(3,Math.min(my.colN>>0,12))
if(my.imgQ){loadImg(0.5,true)}else{loadImg(0,true)}}
function doAnim(){let pc=my.p[my.animN]
if(my.animTp%2==0){pc.left=pc.canvas.style.left
let left=parseFloat(pc.canvas.style.left)
pc.canvas.style.left=left-(Math.random()-0.5)*60+'px'
pc.top=pc.canvas.style.top
let top=parseFloat(pc.canvas.style.top)
pc.canvas.style.top=top-(Math.random()-0.5)*60+'px'}else{pc.canvas.style.left=pc.left
pc.canvas.style.top=pc.top}
my.animN++
if(my.animN