    
    /*
     * iame.js
     * I am Episcopalian
     *
     * version 1.0
     * 2009
     *
     */
    
    
    // configuration
    var _carouselName_ = 'ul#carousel';
    
    
    //Shadowbox.loadSkin('DFMS', '/lib/js/shadowbox/src/skin');
    Shadowbox.loadSkin('classic', '/lib/js/shadowbox/src/skin');
    Shadowbox.loadLanguage('en', '/lib/js/shadowbox/src/lang');
    
    // some other players that might be helpful in the future
    //Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], '/lib/js/shadowbox/src/player');
    Shadowbox.loadPlayer(['flv', 'html', 'swf'], '/lib/js/shadowbox/src/player');
    
    window.onload = function(){
        Shadowbox.init({
            // skip the automatic setup because we don't have any
            // properly configured link elements on the page
            skipSetup: true
        });
    };
    
    
    
    var embedCode = '<embed src="http://www.iamepiscopalian.org/player.swf" ' +
                    'height="403" ' +
                    'width="550" ' +
                    'bgcolor="111111" ' +
                    'allowscriptaccess="always" ' +
                    'allowfullscreen="true" ' +
                    'autostart="false" ' +
                    'flashvars="stretching=fill&skin="' +
                        'http://www.iamepiscopalian.org/css/modieus.swf' +
                        '&playlistsize=200' +
                        '&bufferlength=3' +
                        '&frontcolor=999999' +
                        '&autostart=false' +
                        '&file=' + self.href + '" />';
    
    
    /*
    try {
        console.log( 'using EMBED code: ' + escape(embedCode) );
    }
    catch (e) {}*/
    
    
    
    $(document).ready( function() {
        
        $("#carousel").jCarouselLite({
            btnNext: "#slide-right",
            btnPrev: "#slide-left",
            scroll: 2,
            mouseWheel: true,
            circular: true,
            visible: 4
        });
        
        $("#carousel ul li a img").mouseout( function() {
            $('#iameHoverName').html( '' );
        });
        
        
        
        $("#carousel ul li a").click( function() {
            var self = this;
            Shadowbox.open({ //width: 550px; height: 425px; (measured in Firebug)
                player:     'html',
                title:      '',
                content:    '<div id="iamePlayer"><div id="iamePlayerInner"></div></div>',
                width:      550,
                height:     410
            },
            {
                onFinish:   function() {
                    var flashVars = {
                        file: self.href,
                        bufferlength: '3',
                        backcolor: '111111',
                        frontcolor: '999999',
                        lightcolor: 'ffffff',
                        autostart: 'true',
                        playlistsize: '200',
                        stretching: 'fill',
                        skin: 'css/modieus.swf',
                        plugins: 'viral-1',
                        'viral.embed': escape(embedCode),
                        'viral.link': 'http://www.iamepiscopalian.org/?playVideo=' + self.href
                    };
                    var playerParams = {
                        allowscriptaccess: 'always',
                        allowfullscreen:  'true',
                        allownetworking: 'all',
                        play:   'true',
                        quality: 'best',
                        bgcolor: '#000000',
                        loop: 'false'
                    };
                    
                    //swfobject.embedSWF(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj)
                    
                    swfobject.embedSWF('player.swf', 'iamePlayerInner', '550', '403', '6', false, flashVars, playerParams, {});
                }
            });
            $(self).blur();
            return false;
        });
        
        
        
        
        
        /*
         * attach main handlers
         *
         */
        $("ul#links #upload").click( function() {
            launchUpload('', '');
            // don't actually follow the link
            return false;
        });
        
        $('a').click( function() {
            $(this).blur();
        });
        
        
        
        
        /*
         * attach social networking handlers
         *
         */
        $("li.link#share").mouseover( function() {
            $("div#share-inner").show();
        });
        $("li.link#share").mouseout( function() {
            $("div#share-inner").hide();
        });
        
        //var u = location.href;
        var u = "http://www.iamepiscopalian.org/";
        var t = document.title;
        
        $("li.link#share a.shareicon#facebook").click( function() {
        	window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'resizable=1,scrollbars=1,toolbar=0,status=0,width=626,height=436');
        	return false;
        });
        $("li.link#share a.shareicon#digg").click( function() {
        	window.open('http://digg.com/submit?url=' + encodeURIComponent(u) + '&title=' + encodeURIComponent(t) + '&bodytext=IAMEPISCOPALIAN&media=video&topic=TOPIC', 'Digg I Am Episcopalian', 'resizable=1,scrollbars=1,toolbar=0,status=0,width=995,height=560');
        	return false;
        });
        $("li.link#share a.shareicon#delicious").click( function() {
        	window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=' + encodeURIComponent(location.href) + '&amp;title=' + encodeURIComponent(document.title), 'delicious', 'resizable=1,scrollbars=1,toolbar=no,width=550,height=550');
        	return false;
        });
        $("li.link#share a.shareicon#reddit").click( function() {
        	window.open('http://www.reddit.com/submit?url=' + encodeURIComponent(window.location), 'Share I Am Episcopalian', 'resizable=1,scrollbars=1,toolbar=0,status=0,width=750,height=436');
        	return false;
        });
        
        
    }); // end document.ready
    
    
    
    
    function launchUpload( errorCode, errorMessage ) {
            
            // first get the form HTML
        var uploadForm = $.get( 'uploadForm.php', {silent: 'true', eCode: errorCode, eMsg: errorMessage}, function() {
            // show the returned HTML in the lightbox
            Shadowbox.open({
                player: 'html',
                title: '',
                width: 591,
                height: 344,
                modal: true,
                content: uploadForm.responseText
            },
            {
                onFinish: function() {
                    $('a img.close').click( function() {
                        Shadowbox.close();
                    });
                    handleUploadDefaults(); // registers the handlers for clearing the default form values
                }
            })
            
        });
        
    }
    
    
    
    
    function launchVideo(vid) {
        
        var self = this;
        
        Shadowbox.open({
            player:     'html',
            title:      '',
            content:    '<div id="iamePlayer"><div id="iamePlayerInner"></div></div>',
            width:      550,
            height:     410
        },
        {
            onFinish:   function() {
                //var embed = escape('<script type="text/javascript" id="iameWidget" src="http://localhost/iameShare.js?video=' + getFileName(self.href) + '"></script>');
                var flashVars = { // just so we can see better
                    file: ( (vid.indexOf("/approved") <= 0) ? ('videos/approved/' + vid) : vid ),
                    bufferlength: '3',
                    backcolor: '111111',
                    frontcolor: '999999',
                    lightcolor: 'ffffff',
                    autostart: 'true',
                    playlistsize: '200',
                    stretching: 'fill',
                    skin: 'css/modieus.swf',
                    plugins: 'viral-1',
                    'viral.embed': escape(embedCode),
                    'viral.link': 'http://www.iamepiscopalian.org/?playVideo=' + self.href
                };
                var playerParams = {
                    allowscriptaccess: 'always',
                    allowfullscreen:  'true',
                    allownetworking: 'all',
                    play:   'true',
                    quality: 'best',
                    bgcolor: '#000000',
                    loop: 'false'
                };
                
                swfobject.embedSWF('player.swf', 'iamePlayerInner', '550', '403', '6', false, flashVars, playerParams, {});
                
            }
        });
        return false;
    }
    
    
    
    
    
    
    function getFileName(n) {
        return n.substring(0, n.indexOf('.'));
    }
    
    
    
    
