          /* licensed under the Creative Commons Attribution-Noncommercial 3.0 License by BetterPhoto.com
          for non-commercial use is fine, just keep this block.  If you come up with something cool, mail it to me.
          http://creativecommons.org/licenses/by-nc/3.0/
          Contact BetterPhoto.com for commercial use (collin@betterphoto.com) */
          
          
            //Defaults that need to be over-ridden 
            var SSEffect = 1;
            var CatName = '';
            var Ord =  0;
            var sD = 6000;
            var IB = 0;
            var CapAdj = 0;
            var sBP = '';
            var sServerName = ''; 
            var SSTitles = 0;
            
            // globals
            var zIA = new Array();
            var zIA2 = new Array();
            var mArray = new Array();
            var pID = new Array();
            var tA = new Array();
            var sIA = new Array();
            var MaxH = 600;
            var MaxW = 1000;
            var SSRandom = 0;
            var tf1 = 0; // nav
            var tf2 = 0; // verifyimage
            var tf3 = 0; // do the twean
            var tf4 = 0; // fades
            var tf5 = 0;
            var cH = 50;
            var cW = 50;
            var iH = 0;
            var iW = 0;
            var wStep = 0;
            var hStep = 0;
            var tH = 0;
            var tW = 0;
            var tCtr = 1;
            var tOCtr2 = 20;
            var tOCtr = 1;
            var LoadAttempts = 10;
            var cImg = new Image();
            var bPlaying = true;
            var bPaused = false;
            var bClicked = false;
            var node1;
            var node2;
            var node3;
            var node4;
            var bSAway = false;
            
            // image preload             
            var ss = "http://www.betterphoto.com/_img/ss/";
            for (var i = 0;i<10;i++) {sIA[i] = new Image();}
            sIA[0].src = ss + "tl.gif";
            sIA[1].src = ss + "tr.gif";
            sIA[2].src = ss + "loading.gif";
            sIA[3].src = ss + "icoRW.gif";
            sIA[4].src = ss + "icoBack.gif";
            sIA[5].src = ss + "icoPlay.gif";
            sIA[6].src = ss + "icoPause.gif";
            sIA[7].src = ss + "icoForward.gif";
            sIA[8].src = ss + "icoFF.gif";
            sIA[9].src = ss + "icoClose.gif";
            
            // effects array
            var IEF = new Array();
            IEF[2] = "Morphing:";
            IEF[0] = "None";
            IEF[1] = "Fade";
            IEF[3] = "MorphWH";
            IEF[4] = "MorphHW";
            IEF[5] = "ShinkGrow";
            IEF[6] = "ShrinkWidth";
            IEF[7] = "ShrinkHeight";
                  
            
            IEF[50] = "Barn";
            IEF[51] = "Blinds";
            IEF[52] = "Checkerboard";
            IEF[53] = "GradientWipe";
            IEF[54] = "Inset";
            IEF[55] = "Iris";
            IEF[56] = "Pixelate";
            IEF[57] = "RadialWipe";
            IEF[58] = "RandomBars";
            IEF[59] = "RandomDissolve";
            IEF[60] = "Slide";
            IEF[61] = "Spiral";
            IEF[62] = "Stretch";
            IEF[63] = "Strips";
            IEF[64] = "Wheel";
            IEF[65] = "ZigZag";
            
            IEF[90] = "RandwIE";
            IEF[91] = "RandNoIE";
            IEF[92] = "RandOnlyIE";
                
            /* IE Filters */
            function UpDownRL()
            { 
                var i = zeroRnd(4);  
                if (i == 0) return "down";
                if (i == 1) return "up";
                if (i == 2) return "left";
                if (i == 3) return "right";
            }
            function TopBottomRL() { var i = zeroRnd(4);  return ((i == 0) ? "bottom" : ((i == 1) ? "top" : ((i == 2) ?  "left" : "right" )));}
            function HorzVert() { return zeroRnd(2) == 0 ? "horizontal" : "vertical"; }
            function InOut() {return zeroRnd(2) == 0 ? "in" : "out"; }
            function IEFilterMe(w)
            {
                if (w == "Barn") return w + "( motion=" + InOut() + ",orientation=" + HorzVert() + ")"; 
                if (w == "Blinds") return w + "( Bands=" + (zeroRnd(10) + 1) + ",direction=" + UpDownRL() + ")";
                if (w == "Checkerboard") return w + "( Direction=" + TopBottomRL() + ",SquaresX=" + (zeroRnd(50) + 1) + ",SquaresY=" + (zeroRnd(50) + 1) + ")";
                if (w == "GradientWipe") return w + "( GradientSize=" + (.25 * zeroRnd(5)) + ",wipestyle=" + zeroRnd(2) + ",motion=" + (zeroRnd(2) == 0 ? "forward" : "reverse") + ")";
                if (w == "Inset") return w + "()";
                if (w == "Iris")
                {
                    var i = zeroRnd(6)
                    var tta = new Array();
                    tta[0] = "DIAMOND";
                    tta[1] = "CIRCLE";
                    tta[2] = "CROSS";
                    tta[3] = "PLUS";
                    tta[4] = "SQUARE";
                    tta[5] = "STAR";
                    return w + "(Iris(irisstyle=" + tta[i] + ",motion=" + InOut() + ")";
                 }
                 if (w == "Pixelate") return w + "(MaxSquare=" + (zeroRnd(50) + 1) + ")"; 
                 if (w == "RadialWipe") 
                 {
                    w += "(wipestyle=";
                    var i = zeroRnd(3);
                    if (i == 0) w += "WEDGE)";
                    if (i == 1) w += "RADIAL)";
                    if (i == 2) w += "CLOCK)";
                    return w;
                 
                 }
                 if (w == "RandomBars") return w + "(orientation=" + HorzVert() + ")";
                 if (w == "RandomDissolve") return w + "(Duration=3)";
                 if (w == "Slide") 
                 {
                    w += "(slidestyle=";
                    var i = zeroRnd(3);
                    if (i == 0) w+= "HIDE";
                    if (i == 1) w+= "PUSH";
                    if (i == 2) w+= "SWAP";
                    return w + ",Bands=" + (zeroRnd(50) + 1) + ")";
                 }
                 if (w == "Spiral") return w + "(GridSizeX=" + (zeroRnd(64) + 1) + ",GridSizeY=" + (zeroRnd(64) + 1) + ")";
                 if (w == "Stretch") 
                 {
                    w += "(stretchstyle=";
                    var i = zeroRnd(3);
                    if (i == 0) w += "SPIN";
                    if (i == 1) w += "PUSH";
                    if (i == 2) w += "HIDE";
                    return w + ")";
                 }
                 if (w == "Strips")
                 {
                    w += "(motion=";
                    var i = zeroRnd(4)
                    if (i == 0) w += "leftup";
                    if (i == 1) w += "leftdown";
                    if (i == 2) w += "rightup";
                    if (i == 3) w += "leftdown";
                    return w + ")";
                 }
                 if (w == "Wheel") return w + "(spokes=" + (zeroRnd(10) + 1) + ")";
                 if (w == "ZigZag") return w + "(GridSizeX=" + (zeroRnd(64) + 1) + ",GridSizeY=" + (zeroRnd(64) + 1) + ")";
                 
            }
            
            
            
            /* slide show functions */
            function zeroRnd(top) {return Math.floor(Math.random()* top); }
            function ClearTOs() {for (var i = 1;i<5;i++) {clearTimeout(eval("tf" + i)); }}
            function PreLoadmArray() { for (var i = 0;i<5;i++) { PreLoadMeSpecific(mArray[i]); }}
            function $(v) { return(document.getElementById(v)); }
            function RunSlide()
            {
               CheckCB()
                
                node1 = $('zimg');
                node2 = node1.style;
                setTimeout("PreLoadMe()",25);
                InitImgs();
                setTimeout("Nav(0)",2000);
            }
            function PreLoadMe()
            {
                PreLoadMeSpecific(0);
                if (zIA.length > 1) 
                {
                    PreLoadMeSpecific(zIA.length-1);
                    for (var i = 1;i<zIA.length-1;i++) { PreLoadMeSpecific(i); }
                }
            }
            function PreLoadMeSpecific(w)
            {
                if (zIA2[w])
                {
                  if (typeof(zIA2[w]) != 'object')
                  {
                    var zImg = new Image();
                    zImg.src = zIA[w];
                    zImg["l"]=0;
                    zImg["l"].onload = function(){this["l"]=1;}
                    zIA2[w] = zImg;
                  }
                }
                else
                {
                    var zImg = new Image();
                    zImg.src = zIA[w];
                    zIA2[w] = zImg;
                }
                
            }
            function InitImgs()
            {
                for (var i = 0;i<5;i++) { mArray[i] = 0;}
                if (Ord == 0)
                {
                    mArray[3] = (zIA.length > 1) ? 1 : 0;
                    mArray[4] = (zIA.length > 2) ? 2 : mArray[3];
                 }
                 if (Ord == 1)
                 {
                    if (zIA.length == 2)
                    {
                        mArray[0]=0;mArray[1]=1;mArray[2]=0;mArray[3]=1;mArray[4]=0;
                    }
                    if (zIA.length  > 2)
                    {
                        for (var i = 0;i<5;i++)
                        {
                           mArray[i] =zeroRnd(zIA.length);
                        }
                        for (var i = 1;i<5;i++)
                        {
                            while (mArray[i] == mArray[i-1]) {mArray[i] =zeroRnd(zIA.length); }       
                        }
                    }
                }
             }
            
           function Nav(h)
            {
                
                if (bSAway == true)return;
                //if (!bPlaying) return;
                ClearTOs(); 
                if (bPaused)
                {
                    tf1  = setTimeout("Nav(" + h + ")",1000);
                    return;
                }  
               
                if (Ord == 1)
                {
                    if (h == -1) GetRndImage(-1);
                    else GetRndImage(1);
                }
                else
                {
                    if (h == 0) InitImgs();
                    else if (h == 'e')
                    {
                        mArray[4] = zIA.length - 1;
                        mArray[3] = zIA.length - 1;
                        mArray[2] = zIA.length - 1;  
                        mArray[1] = (zIA.length > 1) ? zIA.length - 2 : zIA.length-1;
                        mArray[0] = (zIA.length > 2) ? zIA.length - 3 : mArray[1]; 
                    }
                    else if (h == 1)
                    {
                        for (var i = 0;i<5;i++)
                        {
                            mArray[i] = (mArray[i]++ >= zIA.length-1) ? 0 : mArray[i]++;
                        }
                    
                    }
                    else if (h == -1)
                    {
                        for (var i = 0;i<5;i++)
                        {
                             mArray[i] = (mArray[i]-- <= 0) ? 0 : mArray[i]--;
                        }
                    }
                }
                PreLoadMeSpecific(mArray[2]);
                cImg = zIA2[mArray[2]];
                setTimeout("PreLoadmArray()",25);
                VerifyImage();
              
            }
            function GetRndImage(h)
            {
                if (h == -1)
                {
                    mArray[4] = mArray[3];
                    mArray[3] = mArray[2];
                    mArray[2] = mArray[1];
                    mArray[1] = mArray[0];
                    if (zIA.length == 1) mArray[0] = 0;
                    else while (mArray[1] == mArray[0]) { mArray[0] = zeroRnd(zIA.length); }
                } 
                if (h == 1)
                {
                    mArray[0] = mArray[1];
                    mArray[1] = mArray[2];
                    mArray[2] = mArray[3];
                    mArray[3] = mArray[4];
                    if (zIA.length == 1) mArray[4] = 0;
                    else while (mArray[4] == mArray[3]) { mArray[4] = zeroRnd(zIA.length); }
                 }    
             }
            
             function VerifyImage()
             {
                var bGood = true;
                if (!cImg["l"] == 0 && isNaN(cImg.width)) bGood = false;
                if (bGood) { if (!cImg.width) bGood = false; }
                if (bGood) { if (isNaN(cImg.width)) bGood = false;}
                if (bGood) { if (cImg.width < 2 || cImg.width == 28) bGood = false;}
                if (!bGood)
                {
                    LoadAttempts--;
                    if (LoadAttempts < 1)
                    {
                        LoadAttempts = 10;
                        ClearTOs();
                        Nav(1);
                        return;
                    }
                    else  {ClearTOs(); tf2 = setTimeout("VerifyImage()",500); } 
                }
                else 
                {
                    LoadAttempts = 10;
                    DoTheEffect();
                }
            }
            
            
            function SetTheImage()
            {
            
                iH = cImg.height;
                iW = cImg.width;
                NormalizeSize();
                tH = iH +  CapAdj;
                tW = iW;
                node2.height = tH + "px";
                node2.width = tW + "px";
             }
             
            function LoadTheImage(h)
            {
                var s = "";
                if (SSTitles == 1) s+='<div id="dImgTitle"></div>';
                s+='<a href="#"><img id="dimg" style="" ';
                if (h == 1) s+= 'class="trans" '; 
                s+= 'src="'+ cImg.src + '" height=' + (iH)  + ' width=' + (iW) + ' align="absmiddle" border=0 /></a>'    
                if (SSTitles == 2) s+='<div id="dImgTitle"></div>';
                node1.innerHTML = s;
                $("imgct").innerHTML = "Image " + GetSpacers() + (mArray[2] + 1)  + " of " + (zIA.length);
                CreateTitle();
             }
         
            function DoTheEffect()
            {
                var Eff = SSEffect;
                
                if (navigator.appVersion.indexOf("MSIE")==-1)
                {
                    if (Eff ==92 || Eff == 90) Eff = 91;
                    if (Eff > 49 && Eff < 90) Eff = 2;
                }
                if (Eff == 90)
                {
                    Eff = zeroRnd(23) + 1;
                    if (Eff > 7) Eff = Eff + 42;
                }
                else if (Eff == 91)
                {
                    Eff = zeroRnd(7) + 1;
                }
                else if (Eff == 92)
                {
                    Eff = zeroRnd(16) + 50;
                }
                if (Eff == 1) 
                {
                    //MorphEffects(1,0);
                    Eff = 2;
                }
                
                if (Eff == 0) 
                {
                    
                    SetTheImage();
                    LoadTheImage(0);
                    ClearTOs();
                    if (bPlaying) tf1 = setTimeout("Nav(1)",sD);      
                }
                if (Eff > 49 && Eff < 90)
                {
                    ClearTOs();
                    node2.filter="progid:DXImageTransform.Microsoft." + IEFilterMe(IEF[Eff]); 
                    node1.filters[0].apply();
                    SetTheImage();
                    LoadTheImage(0);
                    node1.filters[0].play();
                    if (bPlaying) tf1 = setTimeout("Nav(1)",sD);   
                 }
                 if (Eff > 0 && Eff < 50)
                 {
                    MorphEffects(1,Eff);
                 }
             
            }
            
            
            function StartTheTwean(step,w)
            {
                node1.innerHTML = "";
                cH = parseInt(node2.height);
                cW = parseInt(node2.width);
                if (w == 2 || step > 3)
                {
                    iH = cImg.height;
                    iW = cImg.width;
                    NormalizeSize();
                    tH = iH +  CapAdj;
                    tW = iW;
                }
                if ((w == 3 || w == 6) && step == 2)
                {
                    tH = cH
                    tW = 1;
                }
                if ((w == 4 || w == 7) && step == 2)
                {
                    tH = 1;
                    tW = cW
                }
                if ((w == 3 || w == 4) && step == 3)
                {
                    tW = 1;
                    tH = 1;    
                }
                if (w == 3 && step == 4)
                {
                    tW = 1;    
                }
                if (w == 4 && step == 4)
                {
                    tH = 1;    
                }
                if (w == 5 && step == 2 ) 
                {
                    tH = 1;
                    tW = 1;
                }
                wStep = (cW - tW) / 20;
                hStep = (cH - tH) / 20;
                tf3 = setTimeout("DoTheTwean(" + step + "," + w + ")",5);
             }
            
            
            
            function MorphEffects(step,w)
            {
                
                if (step == 1 && w > 0) FadeMeOut(step,w);
                if (w == 2)
                {
                    if (step == 2)StartTheTwean(step,w);
                    if (step == 3){LoadTheImage(1); FadeMeIn(step,w);}
                }
                if (w == 3 || w == 4)
                {
                    if (step == 2) StartTheTwean(step,w);
                    if (step == 3) StartTheTwean(step,w);
                    if (step == 4) tf5 = setTimeout("StartTheTwean(" + step + "," + w + ")",250);
                    if (step == 5) StartTheTwean(step,w);
                    if (step == 6){LoadTheImage(1); FadeMeIn(step,w);}
                 }
                 if (w == 5 || w == 6 || w == 7)
                 {
                    if (step == 2)StartTheTwean(step,w);
                    if (step == 3) tf5 = setTimeout("StartTheTwean(" + (step + 1) + "," + w + ")",250);
                    if (step == 5){LoadTheImage(1); FadeMeIn(step,w);}
                 }
                 
             }
            
          
            function CreateTitle()
            {
                if (SSTitles != 0) $("dImgTitle").innerHTML= ((CatName != '') ? CatName + ": " : "") + ((tA[mArray[2]] != '') ? tA[mArray[2]] : "Image #" + pID[mArray[2]].split(":")[0]);
            }
              
            
            function FadeMeIn(step,w)
            {
                
                var zo = tOCtr * 5;
                if (zo >= 100)
                {
                    
                    clearTimeout(tf4);
                    tOCtr = 1;
                    if (bPlaying) tf1 = setTimeout("Nav(1)",sD);   
                    return;
                }
                else
                {
                    tOCtr++;
                    changeOpac(zo, "dimg"); 
                    tf4 = setTimeout("FadeMeIn(" + step + "," + w + ")",25);
                }
            }
    
            function FadeMeOut(step,w)
            {
                var zo = tOCtr2 * 5;
                if (zo < 0)
                {
                    clearTimeout(tf4);
                    tOCtr2 = 20;
                    MorphEffects((step + 1),w);
                }
                else
                {
                    tOCtr2--;
                    changeOpac(zo, "dimg"); 
                    tf4 = setTimeout("FadeMeOut(" + step + "," + w +")",25);
                }
            }

            function changeOpac(opacity, id) 
            { 
                if ($(id)) { if ($(id).style) {
                var o = $(id).style; 
                o.opacity = (opacity / 100); 
                o.MozOpacity = (opacity / 100); 
                o.KhtmlOpacity = (opacity / 100); 
                o.filter = "alpha(opacity=" + opacity + ")"; 
                if (opacity == 100) o.filter = null; //
                }}
            } 
   
            function GetSpacers()
	        {
	            var z = zIA.length;
	            var s = "";
	            var i = 0;
	            if (z > 9) i++;
	            if (z > 99) i++;
	            if (z > 999) i++;
	            for(var j = i;j>0;j--)
	            {
	                if ((mArray[2]+1) < (j * 10)) s+= "0";
                }
	            return s;
	        }
            
            function DoTheTwean(step,w)
            {
                tCtr++;
                if (tCtr >= 20)
                {
                    node2.height = tH + "px";
                    node2.width = tW + "px"; 
                    tCtr = 0;
                    clearTimeout(tf3); 
                    MorphEffects((step + 1),w);
                }
                else
                {
                    node2.height = (cH - (hStep * tCtr)) + "px";
                    node2.width = (cW - (wStep * tCtr)) + "px";
                    tf3 = setTimeout("DoTheTwean(" + step + "," + w + ")",5);
                  }
            }
                    
            function NormalizeSize()
            {
                var c = 1;
                if (iW > MaxW)
                {
                    c = MaxW / iW;
                    iW = iW * c;
                    iH = iH * c;
                    c = 1;
                } 
                if (iH > MaxH)
                {
                    c =MaxH / iH;
                    iW =iW * c;
                    iH = iH * c;
                }
                
                iW = Math.round(iW);
                iH = Math.round(iH);  
            }
            
            
            function BuyImage()
            {
                if (bPlaying) SP();
                var z = pID[mArray[2]].split(':');
                if (z[1] == 0)
                {
                    if (confirm("This image is currently not for sale.  Would you like to inquire about the purchase of this image anyway?")) 
                    {
                        parent.GoSomeWhere('contact.asp?photoID=' + z[0]);
                    }
                }
                if (z[1] == 1) 
                {
                    if (confirm("You are about to nagivate away from this slideshow.")) 
                    {
                        parent.GoSomeWhere('buy.asp?photoID=' + z[0]);
                    }
                }
               
            }
            
                        
            function GiveKudo()
            {
                if (bPlaying) SP();
                if (confirm("Would you like to leave the photographer of this picture a Kudo?"))
                {
                    if (window.XMLHttpRequest) {
                        req = new XMLHttpRequest();
                    } else if (window.ActiveXObject) {
                        req = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    if (req != undefined) 
                    {
                        var z = pID[mArray[2]].split(':');
                        req.onreadystatechange = function() {AjaxRS()};
                        req.open("GET", sServerName + '/_shared/GiveKudo.asp?PhotoID=' + z[0], true);
                        req.send("");
                    } else alert("Unable to give Kudo's right now for some reason.");
                }
            }
            
            function AjaxRS() 
            {
                if (req.readyState == 4) { if (req.status == 200) { alert(req.responseText); } }
            }    
                
                
           
            
            function ContactGal()
            {
                if (bPlaying) SP();
                var z = pID[mArray[2]].split(':');
                if (confirm("You are about to leave the slide show and contact the gallery owner(s).")) 
                {
                    parent.GoSomeWhere('contact.asp?photoID=' + z[0]);
                }
             }
             
             function CloseMe()
             {
                if (bClicked) {bClicked = false;return;}
                parent.hidePopWin(null);
             }
             
             function ImageInfo() {bClicked = true;}
             function SP()
             {
                if (bSAway == true)return;
                if (bPlaying)
                {
                   $('iP').src = ss + "icoStopped.gif";
                    bPlaying = false;
                    bPaused = false;
                    return;
                }
                else if (bPaused || !bPlaying)
                {
                   $('iP').src = ss + "icoPlay.gif";
                    bPlaying = true;
                    bPaused = false;
                }
                if (bPlaying) 
                {
                    ClearTOs();               
                    tf1 = setTimeout("Nav(1)",1500);
                }
             }
             
             function PauseIt(h)
             {
                if (bSAway == true)return;
                if (!bPlaying) return;
                if (h == 1)
                {
                    bPaused = true;
                    $('iP').src = ss + "icoPaused.gif";
                
                }
                if (h == 0)
                {
                    bPaused = false;
                    $('iP').src = ss + "icoPlay.gif";
                }
            }
             
             function CheckCB()
             {
                var d = $('ControlBar');
                if (parseInt(d.offSetTop) < 10) return;
                if (parseInt(d.offsetTop) == parseInt((window.innerHeight) ? window.innerHeight : document.body.offsetHeight))
                {
                    setInterval(AdjCB,200);
                }
                
              }  
                
                
                function AdjCB()
                {
                    var d = $('ControlBar').style;
                    var a = parseInt((window.innerHeight) ? window.innerHeight : document.body.offsetHeight);
                    a = a - 70;
                    if (a < 0) a = 0;
                    d.position = "absolute";
                    d.top = a + "px";
                }

            
