function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var bandwidth;
var timer;
var curTime = 0;
var duration = 0;
var NP;

var _mypn;
var _mymlc;
var _mydl;

function _myhbPageView(){
	//alert("Jcall: " + _mypn + ", " + _mymlc + " : " + _hbPageView);
	_hbPageView(_mypn,_mymlc);
}

function _myhbDownload(){
	//alert("Jcall: " +  _mydl);
	_hbDownload(_mydl);
}

//
// Client-side access to querystring name=value pairs
// Usage:
//	var qs = new Querystring();
// qs.get(name[, default_value])
//
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get

	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &

// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name

		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;

	var value=this.params[key]
	if (value==null) value=default_;

	return value
}

function popup(url, w, h, name) {

	screenw = screen.availWidth;
	screenh = screen.availHeight;

	if ((w == "") || (w == null)) {
		// change the width and height of popup here, if those arguments are left out
		if (name == "Chat") {
			w = 735;
			h = 500;
		} else if (name == "Live") {
			w = 782;
			h = 500;
		}
	}

	var leftPos = (screenw-w)/2, topPos = (screenh-h)/2;
	var params = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + w + ",height=" + h + ",top=" + topPos + ",left=" + leftPos;
	newWindow=window.open(url,name, params);
	if (newWindow.opener == null) newWindow.opener = self;
	newWindow.focus();

	//return (newWindow);
}

function popupScroll(url, w, h, name) {

	screenw = screen.availWidth;
	screenh = screen.availHeight;

	if ((w == "") || (w == null)) {
		// change the width and height of popup here, if those arguments are left out
		if (name == "Chat") {
			w = 735;
			h = 500;
		} else if (name == "Live") {
			w = 782;
			h = 500;
		}
	}

	var leftPos = (screenw-w)/2, topPos = (screenh-h)/2;
	var params = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=" + w + ",height=" + h + ",top=" + topPos + ",left=" + leftPos;
	newWindow=window.open(url,name, params);
	if (newWindow.opener == null) newWindow.opener = self;
	newWindow.focus();

	//return (newWindow);
}

function popupfull(url) {
	newWindow=window.open(url);
	if (newWindow.opener == null) newWindow.opener = self;
		newWindow.focus();
}

// ---------------------------------------------------------------------------------------
// NAME: replace
// PARAMETERS: string, text, by
// DESCRIPTION: Searches "string" for "text" and replace it by "by"
// LIMITATIONS: none
// ---------------------------------------------------------------------------------------

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function writeMovieRM () {

	var aMovURL = vidURL_array[currentOrder]
	document.write('<EMBED NAME="movie"');
	document.write(' SRC="' + aMovURL + '"');
	document.write(' TYPE="audio/x-pn-realaudio-plugin"');
	document.write(' WIDTH="570" HEIGHT="204"');
	document.write(' CONTROLS="ImageWindow"');
	document.write(' CONSOLE="one"');
	document.write(' BACKGROUNDCOLOR="black"');
	document.write(' CENTER="true"');
	document.write(' LOOP="true"');
	//document.write(' NOJAVA="false"');
	document.write(' NOJAVA="true"');
	document.write(' AUTOSTART="true">');

}

function writeControlsRM () {
	document.write(' <EMBED NAME="play"');
	document.write(' TYPE="audio/x-pn-realaudio-plugin"');
	document.write(' WIDTH="545" HEIGHT="32"');
	document.write(' CONTROLS="ControlPanel"');
	document.write(' CONSOLE="one"');
	document.write(' BACKGROUNDCOLOR="white"');
	document.write(' CENTER="true">');
}

function writeSWF(fullPath) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,65,0" width="770" height="540" id="amd_06e5" align="middle">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="' + fullPath + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<embed src="'  + fullPath + '" quality="high" bgcolor="#ffffff" width="770" height="540" name="amd_06e5" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');

}

/*****************************************************************************
* Begin Survey Code
****************************************************************************/
// this keeps checking if the pop up has been closed.
// this is only called from the frontDoor page
function ticktock() {
	if (NP.closed){
		if (hasNotSeenSunSurvey()){
			var nth = 1; // 1 in nth people will be selected to get popup
			var rnd = Math.floor(Math.random() * nth) + 1;
			if (rnd == nth) {
				//setCookie();
				openSurvey();
			}
		}
	}else{
		setTimeout('ticktock();',600);
	}
}

// sampling and cookie setting code
function openSurvey() {
	var survwin = "multimedia/survey.html";
	window.open(survwin, "invite","directories=no,innerHeight=415,innerWidth=600,height=415,width=600,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no" );
}

function setCookie() {
	var expireDate = new Date();
	var fortyFiveDaysFromNow = expireDate.getTime() + (45*24*60*60*1000);
	expireDate.setTime(fortyFiveDaysFromNow);
	document.cookie = "SunSurvey=true; expires=" + expireDate + "; path=/; domain=.sun.com";
}

function hasNotSeenSunSurvey() {
	var cookieName = "SunSurvey=";
	var allcookies = document.cookie;
	var offset = allcookies.indexOf(cookieName) + cookieName.length;
	var endOffSet = allcookies.indexOf (";", offset);
	if (endOffSet == -1) {
		endOffSet = allcookies.length;
	}
	var cookieValue = allcookies.substring(offset, endOffSet);
	if (cookieValue == "true") {
		return false;
	} else {
		return true;
	}
}
/*****************************************************************************
* End of Survey Code
****************************************************************************/