random_performers = new Array();
var perfRedirect;
var wait4preview;
var cycle;
var last_perf = null;
var keys = new Array();
var i =0;
var vctp_url = "http://aff-en.dxlive.com";




function tryPreview () {
	if (performers.list.length) {
		clearTimeout(wait4preview);
		cyclePreview(w, h);
	} else {
		wait4preview = setTimeout(tryPreview, 500);
	}
}

function nextVideo(w,h){
	clearTimeout(cycle);
	cyclePreview(w,h);
}

function no_perf(){
    clearTimeout(wait4preview);
    var perfName = document.getElementById('namehere');
    while (perfName.hasChildNodes()) {
        perfName.removeChild(perfName.firstChild)
    }
    perfName.appendChild(document.createTextNode(''));
    return;
}

function cyclePreview(affid){
    cyclePreview(156,80);
}

function param( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

var aff_id = param('affid');
  // for debugging
  //alert("affid is "+aff_id);

  
function cyclePreview (w, h) {
    for (var perf in free_performers.performers) {
        keys[i++] = perf;
    }
    keys.sort(randomizeOrder);    
    var perf =( free_performers.performers[keys[0]]).username;    
	clearTimeout(wait4preview);
	var perfName = document.getElementById('namehere');
	var copyRight = configuration.Copyright;
	perfRedirect = perf;
	while (perfName.hasChildNodes()) {
        perfName.removeChild(perfName.firstChild)
	}
    perfName.appendChild(document.createTextNode(perf));
	var aff_id = param('affid');
    var prevlink = document.getElementById('preview2preview');
    prevlink.setAttribute('href', 'http://click.dtiserv2.com/Direct/9354004-354-' + aff_id + '/' + perf + '/preview.shtml');
    var performer = perf;
	perfName.innerHTML = '<a href="javascript:;" onClick=openProfile("'+perf+'") style="text-decoration: none;">'+perf+'</a>';
    var previewTD = document.getElementById('vidPlayerHere');
    last_perf = perf;
    var uid =  (free_performers.performers[keys[0]]).user_id;
	var vctp_url = "http://aff-en.dxlive.com";
	var src = vctp_url + '/flash/chat/freePreview20_vctp.swf';
	var str = '';
    if (w == undefined) {
        w = '156';
    }
    if (h == undefined) {
        h = '80';
    }

    var flashVars = 'channel='+perf+'&performerID='+uid+'&userType=&sessionType=110&userSiteID=1003332&skinName=skin0&ban=0&vctp_url=' + vctp_url +'&ip_arg='+configuration.Ip+'&copyright_arg='+configuration.Copyright+'&server_arg='+configuration.Server+'&langID='+configuration.Language+'&photo=http://imageup.dxlive.com/WebArchive/'+perf+'/flash/LinkedImage.jpg';

	str += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + w + '" height="' + h + '" id="video_chat" align="">';
  	str += '<param name="allowScriptAccess" value="always" />';
  	str += '<PARAM name="movie" value="'+src+'">';
  	str += '<param name=FlashVars value="'+flashVars+'" />';
  	str += '<PARAM name="salign" value="LT">';
  	str += '<PARAM name="quality" value="high">';
  	str += '<PARAM name="bgcolor" value="#006666">';
    str += '<embed src="'+src+'" salign="LT" FlashVars="'+flashVars+'" quality="high" bgcolor="#006666" width="' + w + '"  height="' + h + '" name="video_chat" align="" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
  	str += '</OBJECT>';

	global_pf_name = perf;
    previewTD.innerHTML = str;
    cycle = setTimeout('cyclePreview(' + w + ',' + h + ')',30000);

}

function redirect(thiscaller) {
if (thiscaller=='randompreview') {	
    var w = window.open('/randpreviewclick.shtml?'+perfRedirect, 'preview', 'resizable=yes,toolbar=yes,scrollbars=yes,personalbar=yes,menubar=yes,location=yes,status=yes,width=860,height=600');
} else {
	var aff_id = param('affid');
    var w = window.open('http://click.dtiserv2.com/Direct/9354004-354-' + aff_id + '/' + perfRedirect + '/preview.shtml', 'preview', 'resizable=yes,toolbar=yes,scrollbars=yes,personalbar=yes,menubar=yes,location=yes,status=yes,width=860,height=600');
}
  w.focus();
}
