var catNumber;
var roomType;

$(document).ready(function(){

	catNumber = $("#roomVars input[name='catNumber']").attr("value");
	roomType = $("#roomVars input[name='roomType']").attr("value"); 
	
	$('div.room, div.roomVip').click(function(){ 
		
		openRoom($(this).attr('id'),$(this).attr('box'),roomType); 
	});
	
	setTimeout(function(){ getBox(); }, 5000);
});


function getBox() {
	
	var b = 0;

	$.ajax({
		dataType:'json',
		data:'catNumber='+ catNumber,
		url: 'http://www.kwekker.nl/includes/api/common.php',
		success: function(data) {
			
			$.each( $('#room_container div.roomVip, #room_container div.room') , function(i, lorem){
			
				b++;
					
				if(data[$(this).attr("id")]){
					
					$(this).attr("title", "Klik om met mij te chatten");								
					$(this).attr("box", "client");
					
					$(' .roomText1', $(this)).text(" :: "+data[$(this).attr("id")].username + " (" + data[$(this).attr("id")].age + ")");											
					$(' .roomImg, .roomImgVip', $(this)).html("<div id=\"room"+b+"\" class=\"test\"></div>");
					$(' .flashcode', $(this)).html("<script type=\"text/javascript\">var FO = { movie:\"flash/movie_player_1.swf?random="+Math.floor(Math.random()*1000000)+"\", width:\"110\", height:\"82\", majorversion:\"8\", build:\"0\", flashvars:\"room_id=room_"+catNumber+"_"+b+"&host_name=&location=internet\" }; UFO.create(FO, \"room"+b+"\"); </script>");
					
					
					if(data[$(this).attr("id")].vip == 1){
						$(' .roomText3', $(this)).text("vip");						
					}
					else{
						$(' .roomText3', $(this)).text("");
					}		
				}
				
				else{
					
					$(this).attr("title", "Klik om plaats te nemen in deze room");
					$(this).attr("box", "host");
					
					$(' .roomText1', $(this)).text(":: Vrij");					
					$(' .roomImg ,.roomImgVip', $(this)).html("<div class=\"roomNoHost\"><strong>VRIJ!</strong><br />neem plaats...</div>");					
					$("	 div.flashcode *", $(this) ).remove();
				}
				
			});
				
			setTimeout(function(){ getBox(); }, 60000);
		}
		,error: function(data){
			setTimeout(function(){ getBox(); }, 60000);
		}
	});
}
