$(document).ready(function(){
	rules_webcam.evento_ini_webcam();
});
		
		





rules_webcam = {
	
	evento_ini_webcam : function(){
		//Concatenamos ventana de webcam al cuerpo del body
		$("body").append('<div class="webcam" id="popupComWebcam" style="display:none;position:absolute;z-index:10000"></div>');
		$("#popupComWebcam .cerrar").click(rules_webcam.evento_cerrar_webcam);
		$("a.linkwebcam").click(rules_webcam.evento_abrir_webcam);
		},
	
	evento_cerrar_webcam: function(){
			if (repeticionWebCam != undefined)
				clearTimeout(repeticionWebCam);
			$("#popupComWebcam").popDown();
			return false;
		},
	evento_abrir_webcam: function (){
				var ventana = rules_webcam.devuelve_ventana_webcam();
				$("#popupComWebcam").html(ventana)
				var url = this.href;
				rules_webcam.envia_url(url);
				$("#popupComWebcam").popUp();
				return false; // necesario para que no ejecute el link
			},
	
	devuelve_ventana_webcam : function (){
		return '<div class="caja"><a class="cerrar" href="?modulo=COMEncuentrosEntrevistaPreguntarOU&encuentro=5000">cerrar</a>	<h2><img class="titulares" alt="webcam" src="/txt/web_cam.gif"/></h2><div class="videowebcam" id="imgWebCam"><img alt="webcam" src="/img/artista_250.jpg"/></div><a href="#"><img class="izq noborde" alt="" src="/img/ico_reproduciendo_trans.gif"/></a>	</div>';
		},
	
	envia_url : function (urlFoto){
		if ($("#imgWebCam img").length > 0){
			var img = new Image();
			img.onload = function(imagen){
				if ($("#imgWebCam img").length > 0)
					$("#imgWebCam img")[0].src = this.src;
					$("#imgWebCam img").attr('width','320');
				}

			var fecha = new Date();
			indexInt = urlFoto.indexOf('?');
			if ( indexInt < 0 )
				img.src = urlFoto+"?tmp="+fecha.getTime();
			else if ( urlFoto.substr(-1, -1) != '&')
				img.src = urlFoto+"&tmp="+fecha.getTime();
			else img.src = urlFoto+"tmp="+fecha.getTime();
			
			repeticionWebCam = setTimeout("rules_webcam.envia_url(\""+urlFoto+"\")",5000);	
		}
		}
		
	
	
}
