random_performers = new Array();
var perfRedirect;
var wait4preview;
var cycle;
var last_perf = null;

function tryPreview () {
	if (user_arr.length) {
		clearTimeout(wait4preview);
		cyclePreview(w, h);
	} else {
		wait4preview = setTimeout(tryPreview, 500);
	}
}

function clearCycle(w, h){
        clearTimeout(cycle);
        cyclePreview(w, h);
}

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 (w, h) { 
	if(!user_arr) {
          no_perf();
	  return;
	}
	var count=0;
	var arr = new Array();
	for(perf in user_arr) {
		if(user_arr[perf].session_type=='110' && user_arr[perf].test_flag!=1){
			count++;
			if(perf!=last_perf){
			   arr.push(perf);
			} 
		}
	}

	var perf = '';
	if(arr.length > 0) {
		var index = Math.floor(Math.random() * arr.length);
		perf = arr[index];
		if(arr.length==1){
			perf = arr[0];
		}
	}
	if(count == 1 && arr.length == 0) {
		perf = last_perf;
	}
	if(count == 0 && arr.length == 0) {
         	no_perf();
		return;
	}
 
	clearTimeout(wait4preview);
	var perfName = document.getElementById('namehere');
	var copyRight = "Copyright (c) Caribbeancomgirl.com";
	perfRedirect = perf
	while (perfName.hasChildNodes()) {
		perfName.removeChild(perfName.firstChild)
	}
	perfName.innerHTML = '<a href="javascript:;" onClick=openProfile("'+perf+'") style="text-decoration: none;">'+perf+'</a>';
        var previewTD = document.getElementById('vidPlayerHere');
	last_perf = perf;
	var uid = user_arr[perf].user_id;
	var src = ccg_url+'flash/chat/freePreview20.swf';
	var str = '';
    if (w == undefined) {
        w = '156';
    }
    if (h == undefined) {
        h = '117';
    }
	
	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="channel='+perf+'&performerID='+uid+'&userType=&sessionType=110&langID=jp&userSiteID=1003332&skinName=skin0&ban=0" />';
  	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="channel='+perf+'&performerID='+uid+'&userType=&sessionType=110&langID=jp&webID=A&userSiteID=1003332&skinName=skin0&ban=0" 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 += '<embed src="'+src+'" salign="LT" FlashVars="channel='+perf+'&performerID='+uid+'&userType=&sessionType=110&langID=jp&webID=A&userSiteID=1003332&skinName=skin0&ban=0&photo=http://image.caribbeancomgirl.com/WebArchive/'+perf+'/flash/LinkedImage.jpg" quality="high" bgcolor="#006666" width="156"  height="117" name="video_chat" align="" allowScriptAccess="sameDomain" 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 + ')',20000);

}

function redirect(flashPerformerName , flashPerformerId)
{
  openProfile(flashPerformerName);
}

