/**
 * PortableSermons.com account page JavaScript
 *
 * @package    Simeon
 * @subpackage UI
 * @copyright  Copyright 2008 Spenlen Media (http://spenlen.com)
 * @version    $Id$
 */


var PS = {};

PS.Listen = {
    playerWindow : null,
    open : function (link)
    {
        if (PS.Listen.playerWindow && (! PS.Listen.playerWindow.closed)) {
            PS.Listen.playerWindow.location = PS.Listen.getHref(link);
            PS.Listen.playerWindow.focus();
            return;
        }
        PS.Listen.playerWindow = window.open(PS.Listen.getHref(link), 'PortableSermonsPlayer',
            'height=110,width=550,location=false,menubar=false,status=false,resizable=false');
    },
    openFull : function (link)
    {
        window.open(PS.Listen.getHref(link));
    },
    getHref : function (link)
    {
        var theLink = link.href;
        /* Even if a question mark is properly URL-encoded (%3F), IE 6 still
         * thinks it is the start of the query fragment, which totally wrecks
         * subsequent requests. The following code works around this bug:
         */
        /*@cc_on@*/
        /*@if(@_jscript_version < 5.7)
            if (theLink.slice(-1) == '?') {
                theLink = theLink.slice(0, -1) + '%3F';
            }
            if (link.search.substring(0, 2) == '??') {
                theLink = theLink.replace(/\?\?(.*)$/, '%3F?$1');
            }
        /*@end@*/
        return theLink;
    }
};
