/*
 * Requires: jquery.modal.js, jquery.center.js
 * Open a modal window with a youTube video embed.
 * Link href is the video src.
 */
(function($){

    /*$.fn.buildEmbedObject = function(options){
        var objectTag = document.createElement('object'),
            movieParam = document.createElement('param'),
            allowFullScreen = document.createElement('param'),
            allowScriptAccess = document.createElement('param'),
            embed = document.createElement('embed');
            $(objectTag).css({'width' : options.elWidth, 'height' : options.elHeight});
            $(movieParam).attr({'name' : 'movie', 'value' : options.elSrc});
            $(allowFullScreen).attr({'name' : 'allowFullScreen', 'value' : options.allowFullScreen});
            $(allowScriptAccess).attr({'name' : 'allowScriptAccess', 'value' : options.allowScriptAccess});
            $(embed).attr({'src' : options.elSrc, 'type' : 'application/x-shockwave-flash', 'allowFullScreen' : options.allowFullScreen, 'allowScriptAccess' : options.allowScriptAccess, 'width' : options.elWidth, 'height' : options.elHeight});
            $(objectTag).append(movieParam);
            $(objectTag).append(allowFullScreen);
            $(objectTag).append(allowScriptAccess);
            $(objectTag).append(embed);

            return objectTag;
    };*/

    $.fn.openVideo = function(options){
        //private vars
        var linkElement = $(this),
            embedEl;

        //set the default popup options
        var defaults = {
            elHeight: '344px',
            elWidth: '455px',
            allowFullScreen: 'true',
            allowScriptAccess: 'always',
            vTitle : ''
        };

        //extend options with defaults
        options = $.extend(defaults, options);
        options.elSrc = $(this).attr('href');

        embedEl = linkElement.siblings('.videoEmbed').html();

        $().modal({popContent : embedEl, windowTitle : options.vTitle});


    };

})(jQuery);

$(document).ready(function(){
    $('.videos li a:not(.nopop)').click(function(e){
        e.preventDefault();
        var vidTitle = ($(this).children('img').size()) ? $(this).children('img').attr('alt') : $(this).html(),
        titleEl = document.createElement('h3');
        $(titleEl).attr('class', 'vidTitle');
        $(titleEl).text(vidTitle);
        $(this).openVideo({vTitle : titleEl});
    });
});

/* EXAMPLE EMBED
    <object style="height: 344px; width: 425px">
        <param name="movie" value="http://www.youtube.com/v/6y4Nzu8kYvQ">
        <param name="allowFullScreen" value="true">
        <param name="allowScriptAccess" value="always">
        <embed src="http://www.youtube.com/v/6y4Nzu8kYvQ" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344">
    </object>
*/
