
/*  comments as of 4/29/10

Regarding Width and Height:
The videos are scaled before embedding.
Currently, all videos are being scaled to the same width. (see loadArea1())
Therefore, for width and height, it is sufficient use the aspect ratio,
  barring any slight imperfection in the video encoding.
If using the embedding parameters obtained from the host,
  note that Youtube adds 25px to the height to account for the controlbar
  which displays *under* the video. Since the video is being scaled before
  embedding, the 25px should be subtracted here. It is added back in
  after the scaling. (Obviously, if Youtube introduces a new player for
  embedded videos, the height of its controlbar should be ascertained.)
  Currently, there is no problem with Vimeo because their controlbar overlays
  the video.
The heights of the Youtube(25px) and Local (24px) controlbars are hard-coded
in loadArea1(). The local player is JW Player; if an alternate skin is used,
check the height of the controlbar.

Regarding Hosts: youtube vs. vimeo vs. local 
Currently, all videos are being downloaded from Vimeo.
The last straw was when Youtube decided that a click on a running video
would jump the user to Youtube. That's SICK!
We already needed Vimeo to host videos longer than 10 min; Youtube provides some
features that are nice, but none that we absolutely need.
The biggest advantage of Youtube over Vimeo is that it converts videos
to multiple formats (360p, 480p, 720p, 1080p), downloads the lowest,
and lets the user pick a higher one. Vimeo converts all its non-HD videos
to one format only, which is higher quality than Youtube's 480p.
My original idea was to use Youtube for all videos <10 min and download
in 420p, which used to be possible using an undocumented feature. But that
stopped working and now it's impossible to force a download in 420p.
So ... as of now, it's all Vimeo.
All the code is in place to download directly from VeccVideography ("local").
The JW Player is used. The player controlbar is displayed under the video,
so the comments in the "Width and Height" section (above) regarding Youtube
also apply to Local. (Use the aspect ratio for width and height.)
The Local option was tested and it was found that the Yahoo! server is MUCH
slower than either Youtube or Vimeo. (It also does not support HTTP or RTMP 
streaming, but, as far as I can figure, neither does Vimeo.)
 
*/
  

/*
Dynamic Video Management doc
Vimeo videos can be added to the video menu at runtime.
The parameters necessary to embed the video can be fetched from Vimeo.
Videos can also be moved, hidden, or unhidden using the following commands. 
Each command on  new line.
name | hide
name | show
name | move | [ afterName, #first, #last ]
name | add | vimeoID | [ afterName, #first, #last ] 
In the video Title, colons are replaced with new lines (and leading and trailing spaces are removed).
No HTML allowed in video Description (a Vimeo restriction).
Name of thumbnail is video name + .jpg
Location of thumbnail is http://veccvideography.com/images/thumbnails/
Thumbnail will be scaled to 80 x 80.

*/


function Videos() {

    /*
    "This is a workaround for an error in the ECMAScript Language Specification
    which causes this to be set incorrectly for inner functions."
    -- http://www.crockford.com/javascript/private.html
    */
    var vThis = this ;  // allow private functions to access public members

    var aItems = [

        {
            name: 'andeswedding'
            ,host: 'vimeo'
            ,id: '5512840'
            ,width: 630
            ,height: 425
            ,includeInMenu: true
            ,time: '22:44'
            ,title: 'Wedding Demo'
            ,description: "A wedding and reception in the charming village of Andes, NY."
        }

        ,{
            name: 'cardioclub'
            ,host: 'vimeo'
            ,id: '11301595'
            ,width: 400
            ,height: 225
            ,includeInMenu: true
            ,time: '3:03'
            ,title: 'Small Business Marketing'
            ,description: 'Raegan Reed is the "Fitness Guru of Delaware County." She offers classes for everybody at every level at the <a onclick=\"videoLinkClick();\" href=\"http://www.thecardioclub.com\" target=\"_blank\">Cardio Club</a> on Main St. in Delhi, NY.' 
        }

        ,{
            name: 'burgevinflorist'
            ,host: 'vimeo'
            ,id: '10403211'
            ,width: 400
            ,height: 225
            ,includeInMenu: false
            ,time: '2:48'
            ,title: 'Small Business Marketing'
            ,description: "Lydia Castiglia, Floral Designer and Owner of <a onclick=\"videoLinkClick();\" href=\"http://www.burgevinflorist.com\" target=\"_blank\">Burgevin Florist</a> in Kingston, NY, prepares gorgeous centerpieces for a Christmas gala at the Mohonk Mountain House in New Paltz."
        }

        ,{
            name: 'globaladvisors'
            ,host: 'vimeo'
            ,id: '4733966'
            ,width: 567
            ,height: 425
            ,includeInMenu: true
            ,time: '2:11'
            ,title: 'Corporate Communications'
            ,description: "CIO and Research Director Richard Kang of <a onclick=\"videoLinkClick();\" href=\"http://www.emergingglobaladvisors.com\" target=\"_blank\">Emerging Global Advisors</a> reports on his trip to Asia."
        }

        ,{
            name: 'lumiademo'
            ,host: 'vimeo'
            ,id: '4996903'
            ,width: 567
            ,height: 425
            ,includeInMenu: true
            ,time: '4:12'
            ,title: 'Real Estate - Guided House Tour'
            ,description: "Guided tour of a three-story custom built home on 13 acres. <a onclick=\"videoLinkClick();\" href=\"http://www.franklumiarealestate.com\" target=\"_blank\">Frank Lumia Real Estate</a>, Delhi, NY."
        }

        ,{
            name: 'danpratt'
            ,host: 'vimeo'
            ,id: '4925439'
            ,width: 567
            ,height: 425
            ,includeInMenu: true
            ,time: '14:27'
            ,title: 'Personal Profile /<br>Corporate Communications'
            ,description: "Dan Pratt recounts his long journey as founder and CEO of the popular early childhood development music program, <a onclick=\"videoLinkClick();\" href=\"http://www.kindermusik.com\" target=\"_blank\">Kindermusik</a>. The video was prepared as an address to a conference sponsored by Kindermusik South Africa."
        }

        ,{
            name: 'joekurhajec'
            //,host: 'youtube'
            //,id: 'Rwf7FVeAcZg'
            //,width: 480
            //,height: 270
            ,host: 'vimeo'
            ,id: '11304061'
            ,width: 400
            ,height: 233
            ,includeInMenu: true
            ,time: '4:39'
            ,title: 'Personal Profile / Artist in Profile'
            ,description: "Joe Kurhajec has been making art in New York City, Paris, Merida Mexico and Treadwell NY for over 50 years. Meet Joe at his Treadwell Museum of Art where he talks about the primitive art that has exerted such a strong influence throughout his career."
        }

        ,{
            name: 'ed'
            ,host: 'vimeo'
            ,id: '5832611'
            ,width: 667
            ,height: 450
            ,includeInMenu: true
            ,time: '17:23'
            ,title: 'Personal Profile / Birthday Video'
            ,description: "A retrospective of the long, rich life of Ed: husband, father, WWII vet, and devoted gardener. This video was produced in celebration of Ed's 90th birthday."
        }

        ,{
            name: 'wyncoopholiday'
            ,host: 'vimeo'
            ,id: '4853751'
            ,width: 750
            ,height: 412
            ,includeInMenu: false
            ,time: ''
            ,title: 'Family Video / Christmas Greetings'
            ,description: "In a video produced for Christmas 2008, the Wyncoop family shares memories of an eventful year."
        }

        ,{
            name: 'faironthesquare'
            //,host: 'youtube'
            //,id: 'W9KK0NTFF5M'
            //,width: 16
            //,height: 9
            ,host: 'vimeo'
            ,id: '11187952'
            ,width: 504
            ,height: 284 
            ,includeInMenu: true
            ,time: '3:37'
            ,title: 'Public Event<br>The Fair on the Square - Delhi, NY'
            ,description: "An annual tradition in Delaware County, the Delhi Fair on the Sqaure is held every Friday evening in July. \"Good Food! Good Friends! Good Fun!\""
        }

        ,{
            name: 'woofstock2008'
            ,host: 'vimeo'
            ,id: '4796792'
            ,width: 700
            ,height: 385
            ,includeInMenu: true
            ,time: '9:51'
            ,title: 'Public Event<br>Woofstock 2008'
            ,description: "The <a onclick=\"videoLinkClick();\" href=\"http://www.heartofthecatskills.org\" target=\"_blank\">Heart of the Catskills</a> Humane Society operates a shelter for homeless animals in Delaware County, NY. Their yearly fundraiser is a full day of fun and games for dogs and cats, and people, too."
        }

        ,{
            name: 'odinschickens'
            ,host: 'vimeo'
            ,id: '4576141'
            ,width: 400
            ,height: 300
            ,includeInMenu: false
            ,time: '3:03'
            ,title: "Odin's Chickens"
            ,description: "Two-year old Odin's critique of this video was emphatic: \"More chickens, daddy!\""
        }

        ,{
            name: 'fleischmanns'
            //,host: 'youtube'
            //,id: 'rHQCaoYN58Y'
            //,width: 4
            //,height: 3
            ,host: 'vimeo'
            ,id: '6180950'
            ,width: 504
            ,height: 340
            //,host: 'local'
            //,id: 'FleischmannsTrailer.mp4'  // same as on Vimeo
            //,width: 640
            //,height: 432
            ,preview: 'FleischmannsTrailer.jpg'
            ,includeInMenu: true
            ,time: '3:03'
            ,title: 'Documentary<br>Bienvenidos a Fleischmanns - Trailer '
            ,description: "An intimate portrait of an Hispanic immigrant community living in a small village in rural New York state. Winner of the Best Documentary Award at the 2009 Black Earth Film Festival, and Special Jury Award for Documentary at the 2009 Orlando Hispanic Film Festival." 
        }

        ,{
            name: 'beautifulhouse'
            // also available on youtube
            ,host: 'vimeo'
            ,id: '11198448'
            ,width: 400
            ,height: 225
            ,includeInMenu: true
            ,time: '1:51'
            ,title: 'Beautiful House'
            ,description: "Impressions of a beautiful homestead overlooking a river in Delaware County, NY."
        }

        ,{
            name: 'wilbur'
            //,host: 'youtube'
            //,id: '3zFUohhN4qE'
            //,width: 16
            //,height: 9
            ,host: 'vimeo'
            ,id: '11189339'
            // width increased from 504, 
            // but cannot remove top & bottom defects completely
            ,width: 514.125 
            ,height: 284
            ,includeInMenu: true
            ,time: '1:29'
            ,title: 'Wilbur Plays with the Birds'
            ,description: "Wilbur's official position at Vecc Videography is Mascot. But in this video he tries his hand (paw, actually) at assistant editor."
        }

    ] ;  // end aItems

    this.items = aItems ;

    this.item = function( sName, bRemove ) {
        var oRetval = null ;
        if ( typeof sName != "string" ) return oRetval ;
        if ( typeof bRemove == "undefined" ) bRemove = false ;
        sName = sName.toLowerCase() ;
        for ( var i = 0; i < aItems.length; i++ ) {
            if ( aItems[ i ].name == sName ) {
                oRetval = aItems[ i ] ;
                if ( bRemove ) aItems.splice( i, 1 ) ;
                break ;
            }
        }
        return oRetval ;
    }

    if ( typeof DVM_Commands != "undefined" ) {
        var oDVM = new DVM() ;
        oDVM.exec( this, DVM_Commands, DVM_Videos ) ;
    }

    // IE8 chokes on .default
    this.defaultVideo = null ; 
    function setDefaultVideo() {
        for ( var i = 0; i < vThis.items.length; i++ ) {
            if ( vThis.items[i].includeInMenu ) {
                vThis.defaultVideo = vThis.items[i] ;
                break ;
            } 
        }
    }    
    setDefaultVideo() ;

    this.orderedList = function( sSelectedVideo ) {
        var nIndex = 0 ;
        var aList = [null] ;
        sSelectedVideo = sSelectedVideo.toLowerCase() ;
        for ( var i = 0; i < aItems.length; i++ ) {
            if ( aItems[ i ].name == sSelectedVideo ) {
                aList[ 0 ] = aItems[ i ] ;
                //nIndex = 0 ;  // use this to make the menu roll
            } else {
                nIndex++ ;
                aList.splice( nIndex, 0, aItems[ i ] ) ;
            }
        }
        return aList ;
    }

    this.linksDisplay = {
        none: 0
        ,selected: 1
        ,all: 2
    }

}

