/* (c) Gustavo Coll 2010 */
function slides(containerID,waitTime,fadeSpeed,wipeSpeed){this.fade=function (){if (!document.getElementById || !document.createElement)return;effectName='f';_NextPicture();};this.wipe=function (){if (!document.getElementById || !document.createElement)return;effectName='w';_NextPicture();};this.door=function (){if (!document.getElementById || !document.createElement)return;effectName='d';_NextPicture();};this.tile=function (){if (!document.getElementById || !document.createElement)return;effectName='t';_NextPicture();};this.poof=function (){if (!document.getElementById || !document.createElement)return;effectName='p';_NextPicture();};this.none=function (){if (!document.getElementById || !document.createElement)return;effectName='n';_NextPicture();};this.random=function (){if (!document.getElementById || !document.createElement)return;effectName='r';_NextPicture();};this.stop=function (){if (!document.getElementById || !document.createElement)return;if (timerObj != null)clearTimeout(timerObj);_ResetPic();};var changeFactor=3000,fadeFactor=.10,tileFactor=25,wipeFactor=30;var wipeWidth,wipeMaxWidth;var tileArray,tileTop,tileLeft,tileWidth,tileHeight,tileHeightFactor,tileWidthFactor;var poofHeight,poofWidth,oldSource,poofSource;var containerObj;var imageList;var imageIndex;var timerObj;var effectName;function _Slides(containerID,waitTime,fadeSpeed,wipeSpeed){containerObj=document.getElementById(containerID);if(waitTime != null)changeFactor=waitTime;if(fadeSpeed != null)fadeFactor=fadeSpeed;if(wipeSpeed != null)wipeFactor=wipeSpeed;imageList=new Array();var tmp=containerObj.getElementsByTagName("img");for(var i=0;i<tmp.length;i++){imageList.splice(i,1,tmp[i]);}imageIndex=0;wipeMaxWidth=containerObj.offsetWidth - wipeFactor;_InitTile();poofSource="images/poof.png";}function _SetOpacity(obj){if(obj.xOpacity > 1.00){obj.xOpacity=1.00;return;}obj.style.opacity=obj.style.MozOpacity=obj.xOpacity;obj.style.filter="alpha(opacity=" + (obj.xOpacity*100) + ")";}function _SetWipe(nextImg,prevImg){wipeWidth+=wipeFactor;nextImg.style.display="block";nextImg.style.width=wipeWidth+'px';nextImg.style.zIndex=10;nextImg.xOpacity=1.00;_SetOpacity(nextImg);prevImg.style.zIndex=9;}function _CreateTile(height,width,id){var newDiv=document.createElement('img');newDiv.setAttribute('id','tile~~~'+id);newDiv.style.zIndex=12+id;newDiv.style.position="absolute";newDiv.style.display='none';newDiv.style.width=width+'px';newDiv.style.height=height+'px';containerObj.appendChild(newDiv);return newDiv;}function _InitTile(){containerObj.style.overflow = 'hidden';var tileMaxWidth=containerObj.offsetWidth ;var tileMaxHeight=containerObj.offsetHeight;tileWidth=tileMaxWidth / 2;tileHeight=tileMaxHeight / 2;tileArray=new Array(4);tileHeightFactor=tileHeight / tileFactor,tileWidthFactor=tileWidth  / tileFactor;tileArray[0]=_CreateTile(tileMaxHeight,tileMaxWidth,0);tileArray[1]=_CreateTile(tileMaxHeight,tileMaxWidth,1);tileArray[2]=_CreateTile(tileMaxHeight,tileMaxWidth,2);tileArray[3]=_CreateTile(tileMaxHeight,tileMaxWidth,3);tileArray[0].style.clip='rect(0px '+tileWidth+'px '+tileHeight+'px 0px)';tileArray[1].style.clip='rect(0px '+tileMaxWidth+'px '+tileHeight+'px '+tileWidth+'px)';tileArray[2].style.clip='rect('+tileHeight+'px '+tileWidth+'px '+tileMaxHeight+'px 0px)';tileArray[3].style.clip=
'rect('+tileHeight+'px '+tileMaxWidth+'px '+tileMaxHeight+'px '+tileWidth+'px)';}function _ResetPic(){var nIndex=imageList[imageIndex+1] ? imageIndex+1 : 0;wipeWidth=0;poofHeight=tileHeight * 2;poofWidth=tileWidth * 2;tileTop=tileLeft=1;for(var i=0;i<tileArray.length;i++){tileArray[i].style.display='none';}if(oldSource != null){imageList[imageIndex].src=oldSource;oldSource=null;}imageList[imageIndex].style.zIndex='';imageList[imageIndex].style.display='none';imageList[imageIndex].style.top=imageList[imageIndex].style.left=imageList[imageIndex].style.height=imageList[imageIndex].style.width="";imageList[imageIndex].xOpacity=1.00;_SetOpacity(imageList[imageIndex]);imageList[imageIndex].xOpacity=0;imageIndex=nIndex;imageList[imageIndex].style.zIndex=10;imageList[imageIndex].style.display='';imageList[imageIndex].style.top=imageList[imageIndex].style.left=imageList[imageIndex].style.height=imageList[imageIndex].style.width="";imageList[imageIndex].xOpacity=1.00;_SetOpacity(imageList[imageIndex]);}function _NextPicture(){var functionSelected=null;switch (effectName){case 'f' : functionSelected=_Fade;break;case 'w' : functionSelected=_Wipe;break;case 'd' : functionSelected=_Door;break;case 't' : functionSelected=_Tile;break;case 'p' : functionSelected=_Poof;break;case 'n' : functionSelected=_None;break;case 'r' : var randNumber = Math.floor(Math.random()*5);switch (randNumber) {case 0  : functionSelected = _Fade;break;case 1  : functionSelected = _Tile;break;case 2  : functionSelected = _Wipe;break;case 3  : functionSelected = _Poof;break;default : functionSelected=_Door;break;}break;}timerObj=setTimeout(functionSelected,changeFactor);}function _Init(){for (var i=0; i<imageList.length; i++){imageList[i].xOpacity=1.00;_SetOpacity(imageList[i]);imageList[i].xOpacity=0;imageList[i].style.display="none";}imageList[imageIndex].xOpacity=1.00;imageList[imageIndex].style.display="";imageList[imageIndex].style.zIndex=10;wipeWidth=0;tileTop=tileLeft=1;poofHeight=tileHeight * 2;poofWidth=tileWidth * 2;}function _Fade(){var cOpacity=imageList[imageIndex].xOpacity;var nIndex=imageList[imageIndex+1] ? imageIndex+1 : 0;var nOpacity=imageList[nIndex].xOpacity;cOpacity -= fadeFactor;nOpacity += fadeFactor;imageList[nIndex].style.display="";imageList[nIndex].xOpacity=nOpacity;imageList[imageIndex].xOpacity=cOpacity;_SetOpacity(imageList[imageIndex]);_SetOpacity(imageList[nIndex]);if(cOpacity<=0){_ResetPic();_NextPicture();}else{timerObj=setTimeout(_Fade, 50);}}function _Wipe(){var nIndex=imageList[imageIndex+1] ? imageIndex+1 : 0;if(wipeWidth < wipeMaxWidth){_SetWipe(imageList[nIndex], imageList[imageIndex]);timerObj=setTimeout(_Wipe, 35);}else{_ResetPic();_NextPicture();}}function _Door(){var nIndex=imageList[imageIndex+1] ? imageIndex+1 : 0;if(wipeWidth < wipeMaxWidth){imageList[nIndex].style.left=((wipeMaxWidth - wipeWidth) / 2) + 'px';_SetWipe(imageList[nIndex],imageList[imageIndex]);timerObj=setTimeout(_Door, 35);}else{_ResetPic();_NextPicture();}}function _Tile(){if(tileLeft < 2 && tileTop < 2){for(var i=0; i<tileArray.length; i++){tileArray[i].src=imageList[imageIndex].src;tileArray[i].style.display='';}var nIndex=imageList[imageIndex+1] ? imageIndex+1 : 0;imageList[nIndex].style.zIndex=11;imageList[nIndex].style.display='';}if(tileLeft < tileWidth  &&  tileTop < tileHeight)
{tileArray[0].style.top='-'+tileTop+'px';tileArray[1].style.left=tileLeft+'px';tileArray[2].style.left='-'+tileLeft+'px';tileArray[3].style.top=tileTop+'px';tileTop+=tileHeightFactor;tileLeft+=tileWidthFactor;timerObj=setTimeout(_Tile, 50);}else{_ResetPic();_NextPicture();}}function _None(){var nIndex=imageList[imageIndex+1] ? imageIndex+1 : 0;imageList[nIndex].style.zIndex=10;imageList[nIndex].style.display='';imageList[imageIndex].style.zIndex='';imageList[imageIndex].style.display='none';imageIndex=nIndex;_NextPicture();}function _Poof(){var nIndex=imageList[imageIndex+1] ? imageIndex+1 : 0;imageList[imageIndex].style.zIndex=11;imageList[nIndex].style.zIndex=10;imageList[nIndex].style.display='';if(poofHeight > 30 && poofWidth > 30){imageList[imageIndex].style.top=tileTop+'px';imageList[imageIndex].style.left=tileLeft+'px';imageList[imageIndex].style.height=poofHeight+'px';imageList[imageIndex].style.width=poofWidth+'px';poofHeight-=tileHeightFactor;poofWidth-=tileWidthFactor;tileTop+=tileHeightFactor/2;tileLeft+=tileWidthFactor/2;timerObj=setTimeout(_Poof, 50);}else if(oldSource == null){oldSource=imageList[imageIndex].src;imageList[imageIndex].src=poofSource;timerObj=setTimeout(_Poof, 80);}else{_ResetPic();_NextPicture();}}_Slides(containerID,waitTime,fadeSpeed,wipeSpeed);_Init();}
