    // JavaScript to put random success stories on the home page.
    // This script assumes that the images are GIF files stored under
    // images/home/happy/ 

    // To add a billboard into the rotation:
    //
    // 1)  add an imageName item.  Increment the array subscript
    //     and set it equal to the filename of the image without
    //     the file extension.
    // 2)  add a storyName item.   Increment the array subscript
    //     and set it to the filename of the success story, including
    //     the file extension.
    // 3)  add the Height of the image. Increment the Height array subscript
    //     and set it to the height of the image.
    // 4)  if the link goes offsite, set isOffsite to true; otherwise set
    //     isOffsite to false. This determines whether clicking the image
    //     opens the link in a separate window.

    // To delete a billboard from the rotation:
    //
    // 1)  Remove the appropriate imageName item.  Renumber subsequent
    //     imageName items as required to maintain linear continuity.
    // 2)  Remove the appropriate storyName item.  Renumber subsequent
    //     storyName items as required to maintain linear continuity.
    // 3)  Remove the appropriate Height item. Renumber subsequent
    //     Height items as required to maintain linear continuity.
    // 4)  Remove the appropriate isOffsite value for the item. 
    //     Renumber as previously described.

       var doForce = true;  // under normal operation, 'doForce' is false, and we cycle the banners.
                             // if doForce is true, we force one banner to appear more frequently.
                             // The forced banner, and the frequency, is set in 

       var imageName = new Array(); // Array to hold image filenames
       var storyName = new Array(); // Array to hold success story filenames
       var altPhrase = new Array(); // Array to hold image alt tags
       var Height = new Array(); // Array to hold different image heights, should be 234px
       // All image Widths need to be 680px in this implementation.
       var isOffsite = new Array();

    // Initialize the arrays; make sure to keep the arrays in sync with each
    // other, i.e. make sure the right success story is paired up with the
    // correct image.

       imageName[0] = "blog_banner.jpg"
       imageName[1] = "18_stars_promo.gif"
       imageName[2] = "multimedia_banner.jpg"
       imageName[3] = "p4scout_banner.jpg"
       imageName[4] = "nikon_infoweek_banner.jpg"
       imageName[5] = "agile_roadshow.jpg"
  	   imageName[6] = "nvidia_banner.jpg"
       imageName[7] = "smartbear_banner.jpg"
       imageName[8] = "biorad_banner.jpg"
       imageName[9] = "europe2010_conf.jpg"
       
       storyName[0] = "http://blog.perforce.com"
       storyName[1] = "perforce/gamedev/index.html"
       storyName[2] = "perforce/media_library/index.html"
       storyName[3] = "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=308030938&mt=8"
       storyName[4] = "http://www.informationweek.com/news/software/development/showArticle.jhtml?articleID=217701937&pgno=4#Nikon"
       storyName[5] = "http://www.electric-cloud.com/lp/road-show_P4.php"
       storyName[6] = "http://filehost.perforce.com/downloads/media/userconftalks/2009/Nvidia/nvidia.html"
       storyName[7] = "http://filehost.perforce.com/downloads/media/userconftalks/2009/Smartbear/perforcesmartbear.html"
       storyName[8] = "http://filehost.perforce.com/downloads/media/userconftalks/2009/BioRad/bioradlabs.html"
       storyName[9] = "perforce/conferences/eu/2010/index.html"
       
       altPhrase[0] = "Perforce Blog";
       altPhrase[1] = "18 of Game Developer's 'Top 20 Publishers' develop with Perforce";
       altPhrase[2] = "Check out the Perforce Multimedia Library - All your favorite titles, no late fees.";
       altPhrase[3] = "Check out P4Scout, the new Perforce iPhone app.";
       altPhrase[4] = "Nikon's Wilken Rivera discusses Perforce in InformationWeek.";
       altPhrase[5] = "Agile in Action Road Show";
       altPhrase[6] = "Strategic branching video";
       altPhrase[7] = "Code review video";
       altPhrase[8] = "Achieving Agility video";
       altPhrase[9] = "Come join us at the 2010 Perforce User Conference, held May 11-12 in Windsor, UK.";

       Height[0] = "234";
       Height[1] = "234";
       Height[2] = "234";
       Height[3] = "234";
       Height[4] = "234";
       Height[5] = "234";
       Height[6] = "234";
       Height[7] = "234";
       Height[8] = "234";
       Height[9] = "234";

       isOffsite[0] = false;
       isOffsite[1] = false;
       isOffsite[2] = false;
       isOffsite[3] = true;
       isOffsite[4] = true;
       isOffsite[5] = true;
       isOffsite[6] = false;
       isOffsite[7] = false;
       isOffsite[8] = false;
       isOffsite[9] = false;
       
       // Set counter to length of array containing images for use in 'cycleBanner'.
       ctr = imageName.length;

    // Force a particular banner to display more often than others.
    // Used only when we want to highlight a particular event, award, etc.
    // Set "doForce" (above) to true to force a banner.
    function forceBanner()
    {
        whichBanner = 5;   // number of banner to be forced.
        forceTimes = 1/2;  // what percentage of the time do you want to force the banner?
                           // use 1 to always force it
       // Note that the forced banner actually appears MORE than forceTimes,
       // since it also appears when we cycle.
       if (pickRandom(Math.round(1/forceTimes)) == 0)
        {
            return whichBanner;
        }   else   {
            return cycleBanner();
        }
    }

    // Cycle through all the banners for a particular user, via. 
    // Starts at banner 0 and cycles through all banners.
    // Saves previous banner used via cookie.
    function cycleBanner()
    {  
        cookieName = 'whichBanner';    // The name of the cookie used to store the banner
        numDays = 7;                   // How many days before this auto-resets?

        lastBanner = readCookie(cookieName);
        if ( lastBanner == null )  {    // can't use lastBanner as a Boolean 'cause it could be 0
            nextBanner = pickRandom(ctr);    // which banner do they see the first time?
        }   else    {
            lastBanner = parseInt(lastBanner);
            nextBanner = (lastBanner + 1) % ctr;
        }

        createCookie(cookieName, String(nextBanner), numDays);
        return nextBanner;
    }

    // pickRandom - Which banner do they see the first time?
    //   Return a random number in a given range. If we're running
    //   on an older browser that doesn't support 'Math.random()', we can fake
    //   it by using the current time.

    function pickRandom(range) {
        if (Math.random)
            return Math.round(Math.random() * (range-1));
        else {
            var now = new Date();
            return (now.getTime() / 1000) % range;
        }
    }

    // Three cookie utility functions called by chooseBanner.
    // Code is from http://www.quirksmode.org/js/cookies.html

    function createCookie(name,value,days)
    {
        if (days)
        {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }

    function readCookie(name)
    {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++)
        {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }

    function eraseCookie(name)
    {
        createCookie(name,"",-1);
    }

    // During testing, uncomment the following line to give a clean start on the
    //   banner.

    // eraseCookie('whichBanner')

    // Create the image and href tags for the selected banner
    if (doForce)
    {
      var choice = forceBanner();
    } else {
      var choice = cycleBanner();
    }

    hrefString = storyName[choice];
    imgString='images/home/' + imageName[choice] 
    altString='\"' + altPhrase[choice] + '\"'
    heightString='\"' + Height[choice] + '\"'

    if ( ! isOffsite[choice] )
    {
        document.write('<a href=\"' + hrefString + '\" onclick=\"javascript:pageTracker._trackPageview(\'/' + imgString + '\');\">');
        document.write('<img src=\"' + imgString + '\" alt=' + altString + ' width=\"680\" height=' + heightString + ' border="0"></a>');
    } else {
        document.write('<a onclick=\"javascript:pageTracker._trackPageview(\'/' + imgString + '\'); window.open(\'' + hrefString + '\');return false;\");');
        document.write(' href=\"' + hrefString + '\"><img src=\"' + imgString + '\" alt=' + altString + ' width=\"680\" height=' + heightString + ' border="0"></a>');
    }
