	var activePop;
	var player;

	function updateSocialFilters() {
	 	var category = document.socialFiltersForm.category.value;
    	var filter = document.socialFiltersForm.filter.value;
    	var timePeriod = document.socialFiltersForm.timePeriod.value;
    	
	 	var gender = 'both';
	 	var genderNodes = document.socialFiltersForm.gender;
	 	for (var i = 0; i < genderNodes.length; ++i) {
      		if (genderNodes[i].checked)
        		gender = genderNodes[i].value;
    	}
    	
    	var minAge = document.socialFiltersForm.minAge.value;
    	var maxAge = document.socialFiltersForm.maxAge.value;
    	var distance = document.socialFiltersForm.distance.value;
		var zipCode = document.socialFiltersForm.zipCode.value;
		var membersOnly = document.socialFiltersForm.membersOnly.value;
		var friendsOnly = document.socialFiltersForm.friendsOnly.value;
		var privateOnly = document.socialFiltersForm.privateOnly.value;
		var publicCamOff = document.socialFiltersForm.publicCamOff.value;
    	
	 	var newLocation = '/liveStream.do';
    	if (filter == 'friends' && loggedIn)
    	    	newLocation = '/member/liveStream.do';
	 	newLocation += '?category='+category+'&filter='+filter+'&socialFilters=yes&gender=' + gender;
	 		
	 	if (minAge != null && minAge != '') {
	 		if (minAge < 18) {minAge = 18;}
		 	newLocation += '&minAge=' + minAge;
		}
		 	
		if (maxAge != null && maxAge != '') {
			if (maxAge < 18) {maxAge = 18;}
		 	newLocation += '&maxAge=' + maxAge;
		 }
		 	
		if (distance != null && distance != '')
		 	newLocation += '&distance=' + distance;
		 	
		if (zipCode != null && zipCode != '')
		 	newLocation += '&zipCode=' + zipCode;
		 	
		if (document.socialFiltersForm.membersOnly.checked)
		 	newLocation += '&membersOnly=' + membersOnly;
		 	
		if (document.socialFiltersForm.friendsOnly.checked)
		 	newLocation += '&friendsOnly=' + friendsOnly;	 	
		 	
		if (document.socialFiltersForm.privateOnly.checked)
		 	newLocation += '&privateOnly=' + privateOnly;	
		 	
		if (document.socialFiltersForm.publicCamOff.checked)
		 	newLocation += '&publicCamOff=' + publicCamOff;	 	
		
		 document.location = newLocation;
	}
	 
	function showPop(pop) {
		if (activePop) {
			hidePop();
		}
		activePop = pop;
	 	setPlayer();
	 	activePop.style.display = 'block';
	}
	 	 
	function hidePop() {
	 	player.innerHTML = '';
	 	activePop.style.display = 'none';
	 	activePop = null;
	}	 
	 
	function setPlayer() {	
		var playerHtml = ''; 
		var userId = activePop.getAttribute("userId");
		var videoWidth = 320;
		var videoHeight = 240
		if (activePop.getAttribute("wideScreen") == 'true')
			videoWidth = 427;
			
		player = document.getElementById("player"+userId);
		
		var adcategories = 'show,music,radio,technology,fashion,comedy,fashion,social,mobile,gaming,tv';
		var addescription = 'live streaming shows, backstage, live concerts, socializing';
		var adkeywords = 'chat,chatroom,stream,blog,concert,payperliv,prank,game,friends,feed,social network,concerts,movies,ringtone,student,college,travel,download,school,career';
		
		playerHtml += '<object id="streamViewer" width="'+videoWidth+'" height="'+videoHeight+'" align="" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
		playerHtml += '<param value="'+playerUrl+'?app=stickam_simple_video_player.swf" name="movie"/>'; 
		playerHtml += '<param value="userID='+userId+'&videoWidth='+videoWidth+'&videoHeight='+videoHeight+'" name="FlashVars"/>'; 
		playerHtml += '<param value="always" name="allowScriptAccess"/>'; 
		playerHtml += '<param value="true" name="allowFullScreen"/>'; 
		playerHtml += '<param value="high" name="quality"/>'; 
		playerHtml += '<param value="BCBCBC" name="bgcolor"/>'; 
		playerHtml += '<param value="noscale" name="scale"/>'; 
		playerHtml += '<param value="transparent" name="wmode"/>'; 
		playerHtml += '<param name="adcategories" value="'+adcategories+'">';
		playerHtml += '<param name="addescription" value="'+addescription+'">';
		playerHtml += '<param name="adkeywords" value="'+adkeywords+'">';
		playerHtml += '<embed id="streamViewer" width="'+videoWidth+'" height="'+videoHeight+'" wmode="transparent" type="application/x-shockwave-flash" bgcolor="BCBCBC" quality="high" scale="noscale" allowfullscreen="true" allowscriptaccess="always" flashvars="userID='+userId+'&videoWidth='+videoWidth+'&videoHeight='+videoHeight+'" src="'+playerUrl+'?app=stickam_simple_video_player.swf&adcategories='+adcategories+'&addescription='+addescription+'&adkeywords='+adkeywords+'"/>'; 
		playerHtml += '</object>'; 
				
		player.innerHTML = playerHtml;
	}
	
	function sendToJavaScript(type, value) {
		var userId = activePop.getAttribute("userId");
		if(type == 'views'){
			document.getElementById("currentViewers"+userId).innerHTML = value.format('000,000');
		}else if(type == 'total'){
			document.getElementById("sessionViewers"+userId).innerHTML = value.format('000,000');
		}else{
			alert(value);
		}
	}
	
	var featuredArray = new Array();
 	var profileImgDiv2;
 	var rightDiv2;
 	var currentIndex = -1;
	
	// make ajax call to get channel surfer list
 	function loadChannelSwitcherJSONCallback(data) {
		var liveSessions = data.liveSessions;
		jQuery.each(liveSessions, function(i, val) {
			// find featured users and store them in array
			if (val[6]) { 
				featuredArray.push(val);
			}
		});

		if (featuredArray.length > 0) {
			displayFeaturedUser(0);
			window.setTimeout(switchBanner, 10000);
		}
 	}
	
	function switchBanner() {
		var index = Math.floor(Math.random()*featuredArray.length);
		if (index == currentIndex) {
			// skip displaying new banner since it's the same
		} else {
			displayFeaturedUser(index);
		}
		window.setTimeout(switchBanner, 10000);
	}
	
	function loadChannelSwitcherJSON() {
	 	featuredArray = new Array();
		$.getJSON("/servlet/flash/channelSurfer?category=top", loadChannelSwitcherJSONCallback);
	}
	
	function displayFeaturedUser(index) {
		currentIndex = index;
	 
	 	var userId = featuredArray[index][0];
	 	var imgFile = featuredArray[index][4];
	 	var userName = featuredArray[index][1];
	 	var bio = featuredArray[index][12];
	 	var numViewers = featuredArray[index][7];
		var displayName = featuredArray[index][2];
		// pre load the profile image
		jQuery("<img>").attr("src", staticImgPath + getUserIdPath(userId) + '/' + imgFile);
	 
		var profileImg = document.createElement('img');
		profileImg.setAttribute('src', staticImgPath + getUserIdPath(userId) + '/' + imgFile);
		profileImg.setAttribute('border', '0');
		var profileLink = document.createElement('a');
		profileLink.setAttribute('href', '/' + userName + '?rf=lsftr');
		profileLink.appendChild(profileImg);
		var profileImgDiv = document.createElement('div');
		profileImgDiv.setAttribute('class', 'flbLT');
		profileImgDiv.setAttribute('className', 'flbLT');
		profileImgDiv.appendChild(profileLink);
		var profileLink2 = document.createElement('a');
	 	profileLink2.setAttribute('href', '/' + userName + '?rf=lsftr');
	 	profileLink2.appendChild(document.createTextNode(displayName));
	 
	 	var profileLinkDiv = document.createElement('div');
		profileLinkDiv.setAttribute('class', 'flbTitle');
		profileLinkDiv.setAttribute('className', 'flbTitle');	 
		profileLinkDiv.appendChild(document.createTextNode('Featured: '));
	 	profileLinkDiv.appendChild(profileLink2);
		var bioDiv = document.createElement('div');
	 	bioDiv.setAttribute('class', 'flbTxt');
	 	bioDiv.setAttribute('className', 'flbTxt');	 	
		if (bio && bio != '') {
			bio = bio.replace(/&#034;/g, '"');
		}
	 
	 	bioDiv.appendChild(document.createTextNode(bio));
		var profileLink3 = document.createElement('a');
	 	profileLink3.setAttribute('href', '/' + userName + '?rf=lsftr');
	 	profileLink3.appendChild(document.createTextNode('Watch Now'));
	 	 
	 	var profileButtonDiv = document.createElement('div');	 
	 	profileButtonDiv.setAttribute('class', 'flbBtn');
	 	profileButtonDiv.setAttribute('className', 'flbBtn');
	 
	 	profileButtonDiv.appendChild(profileLink3);
	 	var liveViewerDiv = document.createElement('div');
		liveViewerDiv.setAttribute('class', 'flbLiveTime');
		liveViewerDiv.setAttribute('className', 'flbLiveTime');
	 
		liveViewerDiv.appendChild(document.createTextNode('Live Now: ' + numViewers + ' Viewers'));
	 
	 	var rightDiv = document.createElement('div');
	 	rightDiv.setAttribute('class', 'flbRT');
		rightDiv.setAttribute('className', 'flbRT');
	 	 
		rightDiv.appendChild(profileLinkDiv);
		rightDiv.appendChild(bioDiv);
		rightDiv.appendChild(profileButtonDiv);
		rightDiv.appendChild(liveViewerDiv);
		profileImgDiv2 = profileImgDiv;
		rightDiv2 = rightDiv;
	    
	 	// display
	 	if ($("#howToBox").is(':visible')) {	
			$("#howToBox").fadeOut("slow", fadeMeBack);
		} else {
			$("#featuredLiveBox").fadeOut("slow", fadeMeBack);
		}
	}
	
	function fadeMeBack() {
	  	$("#featuredLiveBox").empty();
	 	$("#featuredLiveBox").append(profileImgDiv2);
	 	$("#featuredLiveBox").append(rightDiv2);
		$("#featuredLiveBox").fadeIn("slow");
	}	 	
	
	
	function getUserIdPath(userId) {
		var separator = "/";
		var path = new String();
		var groupingSize = 4;
		while (userId.length >= 3) {
			path = path.concat(separator, userId.substr(0, groupingSize));
			userId = userId.substr(groupingSize);
		}
		if (userId.length > 0) {
			path = path.concat(separator, userId);
		}
		return path;	
	}