// Queue functionality
Array.prototype.add = function(pObject)
{
    var curIndex = this.length;
    this.length++;
    this[curIndex] = pObject;
}

Array.prototype.queue = function(pObject)
{
    this.add(pObject);
}

Array.prototype.tail = function()
{
    return (this.length != 0) ? this[0] : null;
}

Array.prototype.dequeue = function()
{
    if (this.length == 0)
        return null;

    if (this.length == 1)
        return this.pop();

    this.reverse();
    var ret = this.pop();
    this.reverse();
    return ret;
}

function _setCookie(sName, sValue)
{
    document.cookie = sName + "=" + escape(sValue)+"; path=/";
}

function _getCookie(sName)
{
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++)
    {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
            return aCrumb[1] ? unescape(aCrumb[1]) : "";
    }

    // a cookie with the requested name does not exist
    return null;
}

function fisherYates ( myArray ) 
{
    var i = myArray.length;
    if ( i == 0 ) return;
    while ( --i ) {
        var j = Math.floor( Math.random() * ( i + 1 ) );
        var tempi = myArray[i];
        var tempj = myArray[j];
        myArray[i] = tempj;
        myArray[j] = tempi;
   }
}

function checkForProperHostName()
{
   var _fromUrl;
   var _toUrl;   
   _fromUrl = ""+window.location;

   _toUrl   = _fromUrl.replace(/flyingdutchie\.smugmug\.com/i, "www.streetsofboston.com");
   _toUrl   = _toUrl.replace(/www\.smugmug\.com/i, "www.streetsofboston.com");
   if (_fromUrl != _toUrl)
      window.location=_toUrl;
}
checkForProperHostName();

/* Begin Main Script */
var g_isLoaded = false;

displaySmugPopular = false;
photoBarDelay = 1;
//SM.PhotoBar.config.position = 'top';

rightClickWarning = "If you just tried to get some more info about the picture, you can send me an e-mail and i'll be glad to provide you this information.\n\nIf you were planning to download this picture to your pc, laptop or device, please note that this may be illegal.\nHowever, if you want to use this picture for 'Fair Use', contact me and we may be able to figure something out.\n \nThese photos are copyrighted by \u00A9 Anton Spaans. All rights reserved. Unauthorized use is prohibited."

function writeEMail(pLinkText, pSubject)
{
    /* my speakeasy e-mail */
    //var v2="826ZTCGEBAWEH6VASTTIJ";
    //var v7=unescape("YAF%3B5-4%05112%24%23S72*z%3A%2C%3E");

    /* anton@streetsofboston.com */
    var v2="5VHYZBDPJGDENF6CJFE4EKY54";
    var v7=unescape("T8%3C64%027%248%22%211%3D%29P%21%2551%5B+e%3AZY");
    var v5=v2.length;var v1="";
    for(var v4=0;v4<v5;v4++)
    {
        v1+=String.fromCharCode(v2.charCodeAt(v4)^v7.charCodeAt(v4));
    }
    document.write('<a href="javascript:void(0)" onclick="window.location=\'mail\u0074o\u003a'+v1+'?subject='+escape(pSubject)+'\'">'+pLinkText+'</a>');
}

var g_rotateCntr = 0;
var g_reqRotStop = false;
var g_rotateStopped = false;
var g_logo = null;
var g_popularList = null;
var g_listsMerged = false;

var g_logoImgs = new Array();
g_logoImgs[g_logoImgs.length] = "/photos/32754872-140x140.jpg"; // Bell Lady
g_logoImgs[g_logoImgs.length] = "/photos/5326745-140x140.jpg";  // Downtown Statue
g_logoImgs[g_logoImgs.length] = "/photos/14910982-140x140.jpg"; // Hyannis Boat
g_logoImgs[g_logoImgs.length] = "/photos/18672452-140x140.jpg"; // Hancock

g_logoImgs[g_logoImgs.length] = "/photos/4176090-140x140.jpg";  // Cops on bikes
g_logoImgs[g_logoImgs.length] = "/photos/4176108-140x140.jpg";  // Shopping cart
g_logoImgs[g_logoImgs.length] = "/photos/17811594-140x140.jpg"; // Comm Ave. Statue
g_logoImgs[g_logoImgs.length] = "/photos/29763705-140x140.jpg"; // North End bikers
g_logoImgs[g_logoImgs.length] = "/photos/22177394-140x140.jpg"; // France Gites
g_logoImgs[g_logoImgs.length] = "/photos/22177316-140x140.jpg"; // France watertap.
g_logoImgs[g_logoImgs.length] = "/photos/23621107-140x140.jpg"; // 3 brothers
g_logoImgs[g_logoImgs.length] = "/photos/21454706-140x140.jpg"; // Flowers 1
g_logoImgs[g_logoImgs.length] = "/photos/21454705-140x140.jpg"; // Flowers 2
g_logoImgs[g_logoImgs.length] = "/photos/23480903-140x140.jpg"; // Lente
g_logoImgs[g_logoImgs.length] = "/photos/21359831-140x140-1.jpg"; // JamSession.
g_logoImgs[g_logoImgs.length] = "/photos/21787860-140x140.jpg"; // A'dam bike
g_logoImgs[g_logoImgs.length] = "/photos/9902513-140x140.jpg"; // Portugal
g_logoImgs[g_logoImgs.length] = "/photos/9903388-140x140.jpg"; // Aveiro
g_logoImgs[g_logoImgs.length] = "/photos/36203662-140x140.jpg"; // BBQ NLBorrels
g_logoImgs[g_logoImgs.length] = "/photos/32754881-140x140.jpg"; // Kermit on biker
g_logoImgs[g_logoImgs.length] = "/photos/6723308-140x140.jpg"; // Blink 182
g_logoImgs[g_logoImgs.length] = "/photos/15553156-140x140.jpg"; // T Bruschi
g_logoImgs[g_logoImgs.length] = "/photos/38969755-140x140.jpg"; // Elizabeth Hurley
g_logoImgs[g_logoImgs.length] = "/photos/20000733-140x140.jpg"; // Marathon 2005
g_logoImgs[g_logoImgs.length] = "/photos/20000932-140x140.jpg"; // Marathon 2005
g_logoImgs[g_logoImgs.length] = "/photos/17900090-140x140.jpg"; // De Cordova
g_logoImgs[g_logoImgs.length] = "/photos/9011168-140x140.jpg"; // New York
g_logoImgs[g_logoImgs.length] = "/photos/9011140-140x140.jpg"; // Cristina Yotham

var _g_UA = "";
var _g_knownCSS = {
    firefox_1: true,
    msie: true,
    msie_5: true,
    mozilla: true,
    opera: true,

    none: false
};

var g_browserID = null;
var g_errorMsg  = null;

function getBrowserId(doWrite) {
    var browser;
    var ver;
    var minver;
    var verid = "";

    var reOpera   = /(opera).(\d+)\.(\d+)/;
    var reNS      = /(netscape).?\/(\d+).([\d\.]*)/;
    var reFirefox = /(firefox)\/(\d+).([\d\.]*)\s?/;
    var reIE      = /(msie)\s(\d+).(\d+)/;
    var reSafari  = /(safari)\/(\d+)/;
    var reMozilla = /(mozilla)\/5.*\(.*rv:(\d+).([\d\.]*).*\).*gecko\//;

    var ua = navigator.userAgent.toLowerCase();
        //alert(ua);
    var match = ua.match(reOpera);
    if (!match)
        match = ua.match(reNS);
    if (!match)
        match = ua.match(reFirefox);
    if (!match)
        match = ua.match(reIE);
    if (!match)
        match = ua.match(reSafari);
    if (!match)
        match = ua.match(reMozilla);

    if (!match)
    {
        g_errorMsg = "Sorry, your browser is not supported and display issues may occur:\n  "+ua;
        g_browserID = "???_?_?";
        _g_UA       = "???_?_?";
    }
    else
    {
        if (doWrite) document.writeln("<style type=\"text/css\">");
        browser = match[1];
        ver     = match[2];
        minver  = match[3] ? match[3].replace(/\./,"") : "0";

        if (browser)
        {
            verid = browser;
            if (_g_knownCSS[verid])
            {
                _g_UA += verid+"!; ";
                if (doWrite) document.writeln("@import url(http://www.antonspaans.com/"+verid+".css.php);");
            }
            else
                _g_UA += verid+"; ";
        }
        if (ver)
        {
            verid = browser+"_"+ver;
            if (_g_knownCSS[verid])
            {
                _g_UA += verid+"!; ";
                if (doWrite) document.writeln("@import url(http://www.antonspaans.com/"+verid+".css.php);");
            }
            else
                _g_UA += verid+"; ";
        }
        if (minver)
        {
            verid = browser+"_"+ver+"_"+minver;
            if (_g_knownCSS[verid])
            {
                _g_UA += verid+"!; ";
                if (doWrite) document.writeln("@import url(http://www.antonspaans.com/"+verid+".css.php);");
            }
            else
                _g_UA += verid+"; ";
        }
        if (doWrite) document.writeln("</style>");

        g_browserID = verid;

        if (g_browserID < "firefox_1_5")
            g_errorMsg = "For a better browsing experience, update your Firefox browser to at least version 1.5";

    }
}

function includeBrowserCSS()
{
    getBrowserId(true);
    if (!g_browserID)
        return;

    document.writeln("<style type=\"text/css\">");
    var boxMustShow = _getCookie("T_my_logo");
    if (boxMustShow && boxMustShow == "false")
        document.writeln("#my_logo { display: none; } ");

    boxMustShow = _getCookie("T_featuredBox");
    if (boxMustShow && boxMustShow == "true")
        document.writeln("#featuredBox { display: block; } ");

    boxMustShow = _getCookie("T_galleriesBox");
    if (boxMustShow && boxMustShow == "true")
        document.writeln("#galleriesBox { display: block; } ");

    boxMustShow = _getCookie("T_categoriesBox");
    if (boxMustShow && boxMustShow == "true")
        document.writeln("#categoriesBox { display: block; } ");

    boxMustShow = _getCookie("T_thumbnails");
    if (boxMustShow && boxMustShow == "false" &&
        (g_browserID.indexOf("opera")<0 && g_browserID.indexOf("safari")<0))
    {
        document.writeln("#smugmug #thumbnails, #smugmug_small #thumbnails { display: none; } ");
        document.writeln("#smugmug #albumNav_top .rightColumn, #smugmug_small #albumNav_top .rightColumn { top: 27px; } ");
    }

    getPopularList(false);

    var strRotCntr = _getCookie("R_CNTR");
    var curCntr   = strRotCntr ? parseInt(strRotCntr) : g_rotateCntr;
    if (strRotCntr && strRotCntr.charAt(0)=='-')
    {
        curCntr = -curCntr;
        g_reqRotStop = true;
    }
    else if (strRotCntr)
        curCntr++;

    g_rotateCntr = curCntr;
    doRotate(true);

    document.writeln("</style>");
}

function getPopularList(doFetch)
{
    if (g_popularList)
    {
        mergeLists();
        return;
    }

    var strList = _getCookie("T_popList");
    if (strList && strList.length > 0)
    {
        g_popularList = strList.split(",");
        window.setTimeout("tryRotateLogoImgs()", 250);
                 
        mergeLists();
        return;
    }

    if (doFetch && window.handleCrawlFeed)
        getServerData(null, "/hack/feed.mg?Type=userkeyword&NickName=flyingdutchie&Data=portfolio&format=atom03", 
                      null, handleCrawlFeed);

    g_rotateCntr = 0;
    _setCookie("R_CNTR", "");
}

function tryRotateLogoImgs() {
    var rotateStarted = false;
    if (window.rotateLogoImgs) {
        rotateStarted = rotateLogoImgs();
//        if (rotateStarted)
//            alert("Rotate!");
    }

    if (!rotateStarted) {
        window.setTimeout("tryRotateLogoImgs();", 2500);
//        alert("Try Rotate...");
    }
}

function mergeLists()
{
    if (g_listsMerged)
        return;

    var i;

    for (i = 0; i < g_popularList.length; i++)
    {
        g_logoImgs[g_logoImgs.length] = "/photos/"+g_popularList[i]+"-140x140.jpg";
    }

    var offset = 4;
    var totlen = g_logoImgs.length;

    var idxArray = new Array();
    for (i = 0; i < totlen-offset; i++)
    {
        idxArray[i]=i;
    }
    fisherYates(idxArray);

    var tmpArray = new Array();

    // first 'offset' images will not be shuffled 
    for (i = 0; i < offset; i++)
    {
        tmpArray[i] = g_logoImgs[i];
    }

    // And shuffle the rest of the images.
    for (i = offset; i < totlen; i++)
    {
        tmpArray[i] = g_logoImgs[idxArray[i-offset]+offset];
    }
    g_logoImgs = tmpArray;

    g_listsMerged = true;
}

function doRotate(pWriteInline)
{
    if (!pWriteInline && !g_logo)
        return;

    var aLen = g_logoImgs.length;
    for (var i = 0; i < 4; i++)
    {
        var urlImg = "url("+g_logoImgs[(i+g_rotateCntr)%aLen]+")";
        var imgID  = "ml_"+(i+1);
        if (pWriteInline)
            document.writeln("#"+imgID+" { background-image: "+urlImg+"; } ");
        else
            document.getElementById(imgID).style.backgroundImage = urlImg;
    }
}

/* SmugWidget */
var g_SWidgets = new Array();
function SWidget(pContainerId, pURL, pCols, pRows, pDoShuffle, pCellSize, pMargin)
{
  this.container = pContainerId;
  this.url       = pURL;
  this.cols      = pCols;
  this.rows      = pRows;
  this.doShuffle = pDoShuffle;
  this.cellSize  = pCellSize ? pCellSize : 75;
  this.margin    = pMargin ? pMargin : 1;

  var g_strCellSize = ""+this.cellSize;
  this.replace = [ "Th", g_strCellSize+"x"+g_strCellSize ];
  this.REReplace = new RegExp(this.replace[0]);
  this.imgUrlReplace = function(pURL)
  {
    if (!pURL) return pURL;
		//alert(pURL+":"+this.REReplace+":"+this.replace[1]);
    return pURL.replace(this.REReplace, this.replace[1]);
  }

  g_SWidgets[g_SWidgets.length] = this;
}
/* DON'T CHANGE SCRIPT ABOVE */

/* !!! Change the values or add new SWidgets below !!! */
var g_sending = null;
var g_receiving = null;
var g_busy = "Smugmug Widget Loading...";

/* !!! Begin Change the values or add new SWidgets !!! */

new SWidget("sw_guestbook", "/hack/feed.mg?Type=userkeyword&NickName=flyingdutchie&Data=portfolio&format=atom03",
            7, 1, true, 100, 2);

// new SWidget("sw_yearofdog", "/hack/feed.mg?Type=gallery&Data=1185709&format=rss200",
//             5, 2, true, 100, 1);

/* !!! End Change the values or add new SWidgets !!! */
