// JavaScript Document
(function($) {
	$.alturaTotal=0;
	$.tiposImg = new Array();	
	$.tiposCant = new Array();	
	$.tiposCant['info'] = 0;
	$.tiposCant['error'] = 0;
	$.tiposCant['correccion'] = 0;
	$.tiposCant['url'] = 0;
	$.tiposCant['ajax'] = 0;
	
	$.fn.extend({
		cmDebug:function(configUsu) {
			var config = {
				contenedor: 'cmwDebug',
				tipo: 'info',
				texto: 'Insertar Mensaje',
				fAcomodar: 'cmw.diagramaLiquido()',
				dirImg: cmw.dirImg,
				titulo: 'CristalMedia Debug 1.0',
				maxAlto: 200
			};
	
			var opciones = $.extend(config, configUsu);
			var fecha_actual = new Date();
			var hora = fecha_actual.getHours(); if (hora<10) hora="0"+hora;
			var minutos = fecha_actual.getMinutes(); if (minutos<10) minutos="0"+minutos;
			var segundos = fecha_actual.getSeconds(); if (segundos<10) segundos="0"+segundos;
			var milesimas = fecha_actual.getMilliseconds(); if (milesimas<10) milesimas="0"+milesimas; if (milesimas<100) milesimas="0"+milesimas;
			var horaDebug = hora+":"+minutos+":"+segundos+":"+milesimas;
			
			$.tiposImg['info']=opciones.dirImg+"bug_error.png";
			$.tiposImg['error']=opciones.dirImg+"bug_borrado.png";
			$.tiposImg['correccion']=opciones.dirImg+"bug_ir.png";
			$.tiposImg['url']=opciones.dirImg+"bug_link.png";
			$.tiposImg['ajax']=opciones.dirImg+"bug_agregar.png";		
							
			if(cmw.tipoUsuario == "Super Usuario"){			
			if($("#"+opciones.contenedor).length==0){
				$("body").append("<div id='"+opciones.contenedor+"'></div>");
				
				$("#"+opciones.contenedor).append("<div id='"+opciones.contenedor+"Head'><img src='"+cmw.dirImg+"ojo.png' style='margin:0 5px' align='absmiddle' />"+opciones.titulo+"</div>");
				
				$("#"+opciones.contenedor).append("<div id='"+opciones.contenedor+"Msgs'></div>");
				
				minimizarImg = "<img style='display:none; cursor:pointer;float:right;' src='"+cmw.dirImg+"minimizar.png' id='"+opciones.contenedor+"Minimizar' onclick='";
				minimizarImg+= "$(\"#"+opciones.contenedor+"Msgs\").slideToggle(\"slow\", function(){"+opciones.fAcomodar+"});"; 
				minimizarImg+= "$(\"#"+opciones.contenedor+"Minimizar\").toggle(); ";
				minimizarImg+= "$(\"#"+opciones.contenedor+"Maximizar\").toggle(); ";
				minimizarImg+= "' />";
				
				maximizarImg = "<img src='"+cmw.dirImg+"maximizar.png' style='cursor:pointer;float:right;' id='"+opciones.contenedor+"Maximizar' onclick='";
				maximizarImg+= "$(\"#"+opciones.contenedor+"Msgs\").slideToggle(\"slow\", function(){"+opciones.fAcomodar+"});"; 
				maximizarImg+= "$(\"#"+opciones.contenedor+"Minimizar\").toggle(); ";
				maximizarImg+= "$(\"#"+opciones.contenedor+"Maximizar\").toggle(); ";
				maximizarImg+= "' />";
				
				cants ="<div id='debugInfo'><img src='"+$.tiposImg['info']+"' height = '14' /> <span id='"+opciones.contenedor+"cantInfos'>"+$.tiposCant['info']+"</span> Avisos</div>";
				cants+="<div id='debugError'><img src='"+$.tiposImg['error']+"' height = '14' /> <span id='"+opciones.contenedor+"cantErrores'>"+$.tiposCant['error']+"</span> Errores</div>";
				cants+="<div id='debugCorrec'><img src='"+$.tiposImg['correccion']+"' height = '14' /> <span id='"+opciones.contenedor+"cantCorrecciones'>"+$.tiposCant['correccion']+"</span> Correcciones</div>";
				cants+="<div id='debugUrl'><img src='"+$.tiposImg['url']+"' height = '14' /> <span id='"+opciones.contenedor+"cantUrls'>"+$.tiposCant['url']+"</span> Urls</div>";
				cants+="<div id='debugAjax'><img src='"+$.tiposImg['ajax']+"' height = '14' /> <span id='"+opciones.contenedor+"cantAjax'>"+$.tiposCant['ajax']+"</span> Peticiones Ajax</div>";
				
				$("#"+opciones.contenedor+"Head").append("<div style='float:right; padding-right:20px;'>"+minimizarImg+maximizarImg+cants+"</div>");
								
				$("#"+opciones.contenedor+"Head div").css({
					padding : "0 5px",
					float : "right",
					cursor : "pointer"
				});
				
				$("#"+opciones.contenedor).css({
					width : "100%",
					position : "fixed",
					zIndex : 999999,
					backgroundColor : "#FFF",
					bottom: 0
				});
				
				$("#"+opciones.contenedor+"Head").css({
					width : "100%",
					height : 18,
					paddingTop : 2,
					borderTop : "1px solid #CCC",
					position : "relative",
					backgroundImage : "url("+cmw.dirImg+"listadofFoot.png)",
					backgroundColor : "#FFF"
				});
				
				$("#"+opciones.contenedor+"Msgs").css({
					width : "100%",
					position : "relative",
					maxHeight : 30,
					overflow : "auto",
					font : "11px Arial",
					color : "#666",
					display: "none"
				});
				
			}
			
			$.tiposCant[opciones.tipo]++;
			
			$("#"+opciones.contenedor+"cantInfos").html($.tiposCant['info']);
			$("#"+opciones.contenedor+"cantErrores").html($.tiposCant['error']);
			$("#"+opciones.contenedor+"cantCorrecciones").html($.tiposCant['correccion']);
			$("#"+opciones.contenedor+"cantUrls").html($.tiposCant['url']);
			$("#"+opciones.contenedor+"cantAjax").html($.tiposCant['ajax']);
			
			/*$("#debugInfo").click(function(){
				$("#"+opciones.contenedor+"Head div").each(function(){
					$(this).css({
						backgroundColor : "none",
						color : "#000"
					});
				});
				$(this).css({
					backgroundColor : "#666",
					color : "FFF"
				});
				$(this).corner();
				$("#"+opciones.contenedor+"Msgs div").each(function(){
					if ($(this).hasClass("info")) $(this).show();
					else $(this).hide();
				});
			});
			
			$("#debugAjax").click(function(){
				$("#"+opciones.contenedor+"Head div").each(function(){
					$(this).css({
						backgroundColor : "none",
						color : "#000"
					});
				});
				$(this).css({
					backgroundColor : "#666",
					color : "FFF"
				});
				$(this).corner();
				$("#"+opciones.contenedor+"Msgs div").each(function(){
					if ($(this).hasClass("ajax")) $(this).show();
					else $(this).hide();
				});
			});
			
			$("#debugCorrec").click(function(){
				$("#"+opciones.contenedor+"Head div").each(function(){
					$(this).css({
						backgroundColor : "none",
						color : "#000"
					});
				});
				$(this).css({
					backgroundColor : "#666",
					color : "FFF"
				});
				$(this).corner();
				$("#"+opciones.contenedor+"Msgs div").each(function(){
					if ($(this).hasClass("correccion")) $(this).show();
					else $(this).hide();
				});
			});
			
			$("#debugError").click(function(){
				$("#"+opciones.contenedor+"Head div").each(function(){
					$(this).css({
						backgroundColor : "none",
						color : "#000"
					});
				});
				$(this).css({
					backgroundColor : "#666",
					color : "FFF"
				});
				$(this).corner();
				$("#"+opciones.contenedor+"Msgs div").each(function(){
					if ($(this).hasClass("error")) $(this).show();
					else $(this).hide();
				});
			});
			
			$("#debugUrl").click(function(){
				$("#"+opciones.contenedor+"Head div").each(function(){
					$(this).css({
						backgroundColor : "none",
						color : "#000"
					});
				});
				$(this).css({
					backgroundColor : "#666",
					color : "FFF"
				});
				$(this).corner();
				$("#"+opciones.contenedor+"Msgs div").each(function(){
					if ($(this).hasClass("url")) $(this).show();
					else $(this).hide();
				});
			});*/
			
			$("#"+opciones.contenedor+"Msgs").prepend("<div class='"+opciones.tipo+"'><img src='"+$.tiposImg[opciones.tipo]+"' height='14' /> <strong>"+horaDebug+" - </strong>"+opciones.texto+"</div>");
			$("#"+opciones.contenedor+"Msgs div:even").css({
					borderTop : "1px solid #CCC",
					backgroundColor : "#EEE"
				});
			$("#"+opciones.contenedor+"Msgs div:odd").css({
					width : "100%",
					borderTop : "1px solid #CCC",
					backgroundColor : "#FFF"
				});
			
			$.alturaTotal+=20;
			
			if($.alturaTotal < opciones.maxAlto){
			
				$("#"+opciones.contenedor+"Msgs").stop().animate({
					maxHeight: $.alturaTotal
				},250);
				
			}
			}
			return this;
			
		}
	});

})(jQuery);
