/****************************************************************************
//** Software License Agreement (BSD License)
//** Book Flip slideshow script- © Copyright 2008, Will Jones (coastworx.com)
//** This Script is wholly developed and owned by CoastWorx.com 
//** Copywrite: http://wwww.coastworx.com/
//** You are free to use this script so long as this coptwrite notice 
//** stays intact in its entirety
//** You are NOT Permitted to claim this script as your own or
//** use this script for commercial purposes without the express
//** permission of CoastWorx Technologies!
//** Full credit to Scott Schiller (schillmania.com) for soundManager
//***************************************************************************/

var bkPage_param=gup('bkPage');var pWidth;var pHeight;var isMoving=false;var myBook,isHidden=false,AF;var leftStart=0,rightStart=1;var hideDiv,revealDiv,revealHtmlDiv,hideHtmlDiv,hasPlayed=false,pSound,tempSound,soundManager;var myBook,myBinder,counter=0;var numPixels=20;var allowNavigation=false;var tempPixelsToMove,tempSpeed;var allowPageClick=false;var doIncrementalAutoFlip=false;function flipSoundIni(){if(pSound){if(!soundManager){pSound=false;return false};soundManager.url='soundmanager/soundmanager2.swf';soundManager.debugMode=false;soundManager.consoleOnly=false;soundManager.waitForWindowLoad=true;soundManager.onload=function(){soundManager.createSound({id:'flip',url:'flip.mp3',autoLoad:true})}}}function gup(name){name=name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");var regexS="[\\?&]"+name+"=([^&#]*)";var regex=new RegExp(regexS);var results=regex.exec(window.location.href);if(results==null)return"";else return results[1]}function ini(){if(pSound){flipSoundIni()};if(!document.getElementById("myBook")){return};allowNavigation=selectNavigation;numPixels=numPixelsToMove;if(numPixels>100){numPixels=100};pWidth=myPageW+(pageBorderWidth*2);pHeight=myPageH+(pageBorderWidth*2);myBook=document.getElementById("myBook");myBook.style.width=(pWidth*2)+'px';myBook.style.height=pHeight+'px';myBook.style.position="relative";myBook.style.zIndex="0";for(var i=0;i<myBook.childNodes.length;i++){if(myBook.childNodes[i].nodeType==1){var original=myBook.childNodes[i];var myDiv=document.createElement('div');myDiv.style.position="absolute";myDiv.style.left=pWidth+'px';myDiv.style.top="0px";myDiv.style.width=pWidth+"px";myDiv.style.height=pHeight+"px";myDiv.style.backgroundColor="#ffffff";myDiv.style.overflow="hidden";myDiv.style.zIndex=myBook.childNodes.length-counter;myDiv.setAttribute("id","flipPage"+counter);original.parentNode.replaceChild(myDiv,original);original.setAttribute("id","flipHtml"+counter);original.style.position="absolute";original.style.width=myPageW+"px";original.style.height=myPageH+"px";original.style.top="0px";original.style.left="0px";original.style.overflow="hidden";original.style.borderWidth=pageBorderWidth+"px";original.style.borderColor=pageBorderColor;original.style.borderStyle=pageBorderStyle;if(allowPageClick){if(number_check(counter)){original.onclick=function(e){whichElement(e,true)}}else{original.onclick=function(e){whichElement(e,false)}}}myDiv.appendChild(original);if(allowNavigation&&document.getElementById("flipSelect")){var y=document.createElement('option');if(counter==0){if(original.getAttribute("name")){y.text=original.getAttribute("name")}else{y.text="Cover "}}else{if(original.getAttribute("name")){y.text=original.getAttribute("name")}else{y.text=counter}}y.value=counter;var x=document.getElementById("flipSelect");x.style.display="";x.onchange=function(){this.blur();document.body.focus();autoFlip(this.value)};try{x.add(y,null)}catch(ex){x.add(y)}}counter++}}if(showBinder){myBinder=document.createElement('div');myBinder.style.width=binderWidth+"px";myBinder.style.height=pHeight+'px';myBinder.style.position="absolute";myBinder.style.top="0px";myBinder.style.left=pWidth-(binderWidth/2)+"px";myBinder.style.background="transparent url('"+binderImage+"') top left repeat-y";myBinder.style.zIndex="200";myBook.appendChild(myBinder)}myBook.style.display=""}function figureAuto(){if(bkPage_param>1&&bkPage_param<35){autoFlip(bkPage_param)}else if(bkPage_param==35){autoFlip(bkPage_param);goprev()}else{autoFlip(1)}}function figureAuto2(){if(bkPage_param==1){autoFlip(1);gonext()}else if(bkPage_param>1&&bkPage_param<25){autoFlip(bkPage_param)}else if(bkPage_param==25){autoFlip(bkPage_param);goprev()}else{autoFlip(3)}}function figureAuto3(){if(bkPage_param==1){autoFlip(1);gonext()}else if(bkPage_param>1&&bkPage_param<39){autoFlip(bkPage_param)}else if(bkPage_param==39){autoFlip(bkPage_param);goprev()}else{autoFlip(3)}}function figureAuto4(){if(bkPage_param==1){autoFlip(1);gonext()}else if(bkPage_param>1){autoFlip(bkPage_param)}else{autoFlip(3)}}function number_check(value){return(1-(value%2))}function autoFlip(topage){currentLeft=leftStart-1;if(topage>(currentLeft+1)){cycles=topage-currentLeft;if(number_check(cycles)){cycles=cycles/2}else{cycles=(cycles-1)/2}if(doIncrementalAutoFlip){tempSound=pSound;pSound=false;tempPixelsToMove=numPixels;tempSpeed=pSpeed;pSpeed=0;numPixels=(pWidth/4);doAutoFlip(cycles,true)}else{rightDirectFlip(cycles)}}else if(topage==currentLeft||topage==currentLeft+1){return}else{cycles=currentLeft-topage;if(number_check(cycles)){cycles=cycles/2}else{cycles=(cycles+1)/2}if(doIncrementalAutoFlip){tempSound=pSound;pSound=false;tempPixelsToMove=numPixels;tempSpeed=pSpeed;pSpeed=0;numPixels=(pWidth/4);doAutoFlip(cycles,false)}else{leftDirectFlip(cycles)}}}function doAutoFlip(num,dir){if(num==0){AF=window.clearTimeout(AF);numPixels=tempPixelsToMove;pSpeed=tempSpeed;pSound=tempSound;return};if(dir){gonext()}else{goprev()}num--;AF=window.setTimeout('doAutoFlip('+num+','+dir+')',100)}function rightDirectFlip(num){for(var i=0;i<num;i++){if(!document.getElementById("flipPage"+rightStart)){return};hideDiv=document.getElementById("flipPage"+leftStart);hideHtmlDiv=document.getElementById("flipHtml"+leftStart);revealDiv=document.getElementById("flipPage"+rightStart);revealHtmlDiv=document.getElementById("flipHtml"+rightStart);revealDiv.style.left=0+'px';revealDiv.style.width=pWidth+'px';revealDiv.style.zIndex=0;hideDiv.style.left="";hideDiv.style.right="0px";hideDiv.style.width="0px";hideHtmlDiv.style.left="";hideHtmlDiv.style.right="0px";revealHtmlDiv.style.left="";revealHtmlDiv.style.right="0px";leftStart=leftStart+2;rightStart=rightStart+2}}function leftDirectFlip(num){for(var i=0;i<num;i++){if(!document.getElementById("flipPage"+(leftStart-2))){return false};leftStart=leftStart-2;rightStart=rightStart-2;hideDiv=document.getElementById("flipPage"+rightStart);hideHtmlDiv=document.getElementById("flipHtml"+rightStart);revealDiv=document.getElementById("flipPage"+leftStart);revealHtmlDiv=document.getElementById("flipHtml"+leftStart);hideDiv.style.left="";hideDiv.style.right=pWidth+"px";hideDiv.style.width=0+'px';revealDiv.style.left=pWidth+"px";revealDiv.style.width=pWidth+"px";revealHtmlDiv.style.left="0px";hideHtmlDiv.style.left="0px"}}function gonext(){if(isMoving){return};if(!document.getElementById("flipPage"+rightStart)){return}isMoving=true;hideDiv=document.getElementById("flipPage"+leftStart);hideHtmlDiv=document.getElementById("flipHtml"+leftStart);revealDiv=document.getElementById("flipPage"+rightStart);revealHtmlDiv=document.getElementById("flipHtml"+rightStart);revealDiv.style.width="0px";revealDiv.style.left=pWidth*2+'px';revealDiv.style.zIndex=99;goright(pWidth*2,0)}function goright(currLeft,currWidth){if(currLeft<=numPixels*2){window.clearTimeout(ID);revealDiv.style.left=0+'px';revealDiv.style.width=pWidth+'px';revealDiv.style.zIndex=revealDiv.style.zIndex-99;hideHtmlDiv.style.left="";hideHtmlDiv.style.right="0px";revealHtmlDiv.style.left="";revealHtmlDiv.style.right="0px";leftStart=leftStart+2;rightStart=rightStart+2;isHidden=false;isMoving=false;if(showBinder){myBinder.style.zIndex="100"};if(allowNavigation&&document.getElementById("flipSelect")){document.getElementById("flipSelect").selectedIndex=leftStart-1}hasPlayed=false;return}currLeft=currLeft-(numPixels*2);currWidth=currWidth+numPixels;revealDiv.style.left=currLeft+'px';revealDiv.style.width=currWidth+'px';hideWidth=currLeft-pWidth;if(hideWidth>0){hideDiv.style.width=hideWidth+'px'}else{if(!isHidden){hideDiv.style.width=0+'px';isHidden=true}}if(currLeft<(pWidth+binderWidth+numPixels)&&!hasPlayed){if(showBinder){myBinder.style.zIndex="0"};if(pSound){soundManager.play('flip')}hasPlayed=true}ID=window.setTimeout('goright('+currLeft+','+currWidth+')',pSpeed)}function goprev(){if(isMoving){return};if(!document.getElementById("flipPage"+(leftStart-2))){return false}isMoving=true;leftStart=leftStart-2;rightStart=rightStart-2;hideDiv=document.getElementById("flipPage"+rightStart);hideHtmlDiv=document.getElementById("flipHtml"+rightStart);revealDiv=document.getElementById("flipPage"+leftStart);revealHtmlDiv=document.getElementById("flipHtml"+leftStart);revealDiv.style.left="0px";revealDiv.style.width="0px";hideDiv.style.left="";hideDiv.style.right=pWidth+"px";goleft(0,0)}function goleft(currLeft,currWidth){if(currLeft>=(pWidth-(numPixels*2))){window.clearTimeout(ID);revealDiv.style.left=pWidth+"px";revealDiv.style.width=pWidth+"px";revealHtmlDiv.style.left="0px";hideHtmlDiv.style.left="0px";isHidden=false;isMoving=false;if(showBinder){myBinder.style.zIndex="100"};if(allowNavigation&&document.getElementById("flipSelect")){if(leftStart-1>0){document.getElementById("flipSelect").selectedIndex=leftStart-1}else{document.getElementById("flipSelect").selectedIndex=leftStart}}hasPlayed=false;return}currLeft=currLeft+numPixels;currWidth=currWidth+numPixels;revealDiv.style.width=currWidth+'px';revealDiv.style.left=currLeft+'px';hideWidth=pWidth-currWidth;if(hideWidth>(pWidth/2)){hideDiv.style.width=hideWidth-numPixels+'px'}else{if(!isHidden){hideDiv.style.width=0+'px';isHidden=true}}if(currLeft>((pWidth/2)-numPixels)&&!hasPlayed){if(showBinder){myBinder.style.zIndex="0"};if(pSound){soundManager.play('flip')}hasPlayed=true}ID=window.setTimeout('goleft('+currLeft+','+currWidth+')',pSpeed)}function whichElement(e,dir){var targ;if(!e){var e=window.event}if(e.target){targ=e.target}else if(e.srcElement){targ=e.srcElement}if(targ.nodeType==3){targ=targ.parentNode}pname=targ.parentNode.tagName;tname=targ.tagName;if(tname=="A"||tname=="INPUT"||pname=="A"||pname=="INPUT"){return false}else{if(dir){return gonext()}else{return goprev()}}}function toggleBinder(){showBinder=(showBinder!=false?false:true);if(showBinder){myBinder.style.display=""}else{myBinder.style.display="none"}}function toggleSound(){pSound=(pSound!=false?false:true)}
