random_performers = new Array();
var perfRedirect;
var wait4preview;
var vctp_url = "http://aff-jp.dxlive.com";

function tryPreview () {
    if (free_performers.length) {
	clearTimeout(wait4preview);
	cyclePreview();
    } else {
	wait4preview = setTimeout(tryPreview, 500);
    }
}

function cyclePreview () { 
	var keys = new Array();
	var i = 0;

    for (var perf in free_performers.performers) {
		keys[i++] = perf;
    }

	var j = Math.floor(Math.random() * i);
    var perf = free_performers.performers[keys[j]];

    var perfName = document.getElementById('namehere');
//    var copyRight = "Copyright (c) DxLive.com";
	perfRedirect = perf;
	var bst = ""; 
	
	if(checkBan(perf)){
		bst = "&ban_arg=true";
	}
	
	if(busy_performers.getPerformer(perf)){
		bst += "&busy_arg=true";
	}
	
//    perfName.appendChild(document.createTextNode(perf));
//    var prevlink = document.getElementById('preview2preview');
//    prevlink.setAttribute('href', '/fcgi/preview.html?username='+perf);
//    prevlink.setAttribute('href', '/preview.shtml?'+perf);
//    var proflink = document.getElementById('preview2profile');
//    proflink.setAttribute('href', '/fcgi/profile.html?username='+perf);
//    proflink.setAttribute('href', '/fast-cgi/profile.fcgi?username='+perf);
	
    var previewTD = document.getElementById('vidPlayerHere');

    previewTD.innerHTML = perf + '<br>';
	previewTD.innerHTML += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="0" height="0" id="video_chat_free" align="">';
    previewTD.innerHTML += '<PARAM name="movie" value="' + vctp_url + '/flash/vctp_live.swf?performer_arg='+ perf +'&vctp_url=' + vctp_url +'&ip_arg='+configuration.Ip+'&copyright_arg='+configuration.Copyright+'&server_arg='+configuration.Server+'&langId_arg='+configuration.Language+'&photo_arg=http://aff-images.dxlive.com'+perf.getAtt('picture')+bst + '">';
    previewTD.innerHTML += '<PARAM name="loop" value="false">';
    previewTD.innerHTML += '<PARAM name="menu" value="false">';
    previewTD.innerHTML += '<PARAM name="quality" value="high">';
    previewTD.innerHTML += '<PARAM name="bgcolor" value="#000000">';
//	 previewTD.innerHTML += '<param name="allowScriptAccess" value="always">');
	
    previewTD.innerHTML += '<EMBED src="' + vctp_url + '/flash/vctp_live.swf?performer_arg='+ perf +'&photo_arg=http://aff-images.dxlive.com'+perf.getAtt('picture')+ '&vctp_url=' + vctp_url + '&ip_arg='+configuration.Ip+'&copyright_arg='+configuration.Copyright+'&server_arg='+configuration.Server+'&langId_arg='+configuration.Language+bst+'" quality="high" bgcolor="#000000" width="160" height="120" name="video_chat" align="" type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always"></EMBED>';
    previewTD.innerHTML += '</OBJECT>';

	statusbar();
}

function redirect() {
  var w = window.open('/preview.shtml?'+perfRedirect, 'preview', 'resizable=yes,toolbar=no,scrollbars=no,personalbar=no,menubar=no,location=no,status=no,width=740,height=587');
  w.focus();
}
