function launchCenteredWin(url, name, width, height, otherfeatures)
{
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  newwin = window.open(url, name, str + ',' + otherfeatures);
  if(parseInt(navigator.appVersion) >= 4)
  {
 	setTimeout('newwin.focus();',250);
  }
}

function play(clip){
pageUrl=location.href;
lastSlash=pageUrl.lastIndexOf('/')+1;
pageUrl=pageUrl.substring(0,lastSlash);
//AudioPop()
launchCenteredWin('/media/player/play.php?clip='+pageUrl+clip,'player',406,160,'');
}

function vPlay(clip,title){
pageUrl=location.href;
lastSlash=pageUrl.lastIndexOf('/')+1;
pageUrl=pageUrl.substring(0,lastSlash);
//alert(clip);
//AudioPop()
//alert('/media/player/vPlay.php?clip='+pageUrl+clip);
if(filetype(clip)=="flv" ||filetype(clip)=="swf"){
	launchCenteredWin('/media/player/flvplay.php?clip='+pageUrl+clip+'&title='+urlencode(title),'player',550,400,'');
}else{
	launchCenteredWin('/media/player/vPlay.php?clip='+pageUrl+clip+'&title='+urlencode(title),'player',550,400,'');
	}
}
function filetype(clip){
	return (clip.substring(clip.length-3, clip.length));
}
function download(file){
    pageUrl=location.href;
	lastSlash=pageUrl.lastIndexOf('/')+1;
	pageUrl=pageUrl.substring(0,lastSlash);
	location.href='/media/player/download.php?file='+pageUrl+file;
}

function urlencode (str) {
 
    var hexStr = function (dec) {
        return '%' + dec.toString(16).toUpperCase();
    };
 
    var ret = '',
            unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();
 
    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            // Reserved assumed to be in UTF-8, as in PHP
            if (code === 32) {
                ret += '+'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048 && code < 65536) { // 3 bytes
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 65536) { // 4 bytes
                ret += hexStr((code >> 18) | 0xF0);
                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}
