/* $Id: shared.js,v 1.9 2011/10/02 22:02:43 sap Exp $ */

$(document).ready(function () { 
    var VW = 480;
    var VH = 380;

    /* video div popup */
    $('.playme').click(function(e){
        $('#vpop_bg').show();
        $('#vpop_wrapper').show();
        $('#vpop').show();
        $('#player1').jwPlayer('destroy');
        
        var v = $(this).attr('fileref');
        var t = $(this).attr('titleref');
        var idref = $(this).attr('idref');
        var imgref = $(this).attr('imgref');
        var embedokref = $(this).attr('embedokref');
        var s = "rtmp://stream2.pwcs.edu/vod/media/"; // vod
        if (v == 'flashlive.flv') s = "rtmp://stream2.pwcs.edu/live/instance1/";

        $('#player1').jwPlayer({
            swf: '/inc/player.swf',
            height: VH,
            width: VW,
            flashvars: {
                'autostart': true,
                'streamer': s,
                'file': v
            }
        });

        $('#vpop h3').html(t);
        $('#vpop h3').attr('strref', s);
        $('#vpop h3').attr('fileref', v);
        
            if (embedokref == '1') {
                //$(.addthis_toolbox).attr('addthis:url', "http://pwcstv.com/episode.php?id=" + idref);
                //$(.addthis_toolbox).attr('addthis:title', t);
                var iurlstr = '';
                iurlstr += '?fileref=' + v;
                iurlstr += '&imgref=' + imgref;
                var emcode = '';
                emcode += '<iframe';
                emcode += ' src="http://' + location.hostname + '/vidembed.php' + iurlstr + '"';
                emcode += ' scrolling="no"';
                emcode += ' width="480"';
                emcode += ' height="410"';
                emcode += ' frameborder="0"';
                emcode += ' marginheight="0"';
                emcode += ' marginwidth="0"';
                emcode += '></iframe>';

                $('#embed_code').text(emcode);
                $('#share_links').show();
            }
        
        $('#player1').jwPlayer('load', v);
        $('#player1').jwPlayer('play');
        return false;
    });
    
    /* close the video */
    $('#closer').click(function(e){
        $('#player1').jwPlayer('destroy');
        $('#vpop_bg').hide();
        $('#vpop_wrapper').hide();
        $('#vpop').hide();
        return false;
    });
    
    /* show textarea with embed code */
    $('#show_embed_code').toggle(function(e){
            $('#embed_code').show();
            return false;
        }, function(e){
            $('#embed_code').hide();
            return false;
    });
    
    /* kill video div popup and open video in new window */
    $('#vpop #vidwin_opener').live('click', function(e){
        $('#player1').jwPlayer('stop');
        var nwopts = 'status=no,toolbar=no,location=no,height=490,width=560';
        var fileref = $('#vpop h3').attr('fileref');
        var strref = $('#vpop h3').attr('strref');
        var title = $('#vpop h3').html();
        var earl = '/vidwin.php?fileref=' + encodeURI(fileref) + 
                    '&strref=' + encodeURI(strref) + 
                    '&title=' + encodeURI(title);
        var nw = window.open (earl, 'vidwin', nwopts);
        $('#player1').jwPlayer('destroy');
        $('#vpop_bg').hide();
        $('#vpop_wrapper').hide();
        $('#vpop').hide();
        return false;
    });
    
    /* other */
    $('#search-kw').focus(function(){
        if ($(this).val() == 'Search') $(this).val('');
    });

    $('#search-kw').blur(function(){
        if ($(this).val() == '') $(this).val('Search');
    });     
});

