// JavaScript Document

function igualarAltos(donde) {
	var maximo = 0;
	$(donde).each(function() {

		maximo = (maximo > $(this).height()) ? maximo : $(this).height();
	}).height(maximo);
}



function createImageViewer() { ////////////////CREA EL FONDO NEGRO Y LA TABLE PARA VER FULLSCREEN
	$("body").append('<div id="fondo_total" style="position:fixed; width:100%; height:100%; background: #000; top:0; left:0;display:none; z-index:1000000;" ></div><table id="table_pantalla" style="position:fixed; width:100%; height:100%; z-index:1000001; display:none; left:0; top:0" ><tr valign="middle"><td align="center"></td></tr></table>');
	$("#table_pantalla").find("td").html("<img src='img/loader.gif'>");
	fotosDefault = null;
}


function fullScreen(obj) {

	$("#fondo_total").fadeTo(400, 0.6);
	$("#table_pantalla").fadeIn(400).find("img").attr('src', 'img/loader.gif');
	
	document.onkeydown = detectar_tecla; 
	var ancho = $(window).width();
	var alto = $(window).height();
	var image = new Image();
			image.src = "image_resizer.php?image=img/uploads/"+$(obj).attr('imagen')+"&width="+ancho+"&height="+alto;

					
					// si la imagen esta en el cache IEfix
					if ((image.complete) || (this.readyState == 'complete')) 
							{
							ponerImagen(image);
							
							}
					else  // si no
							{
							 $(image).load(function () { 
							 ponerImagen(image); });
					}	
					
	
}
	
function cerrarFullScreen() {
	
	$("#fondo_total, #table_pantalla").fadeOut(400, function() {$(this).find("td img").attr('src', 'img/loader.gif');})
	document.onkeydown = null; 
}




function cleverInputs(donde) {
	
	$(donde).each(function() 
						{ 
						$(this).data("default", $(this).val()).
							css("color", "#999").
							bind("focus", function() {
											if ($(this).val() == $(this).data('default')) 
													$(this).val('').css("color", "#000");
												}).
							bind("blur", function() {
											if ($(this).val() == '') 
													 $(this).val($(this).data('default')).css("color", "#999");
												});
							});
}



function getTopLeft(elm)
{

var x, y = 0;
//set x to elm’s offsetLeft
x = elm.offsetLeft;
//set y to elm’s offsetTop
y = elm.offsetTop;
//set elm to its offsetParent
var sc = $(elm).closest(".scroll").scrollTop(); //scroll del scrooll
y -= sc; // a la coordenada top le resta el scroll

elm = elm.offsetParent;
//use while loop to check if elm is null
// if not then add current elm’s offsetLeft to x
//offsetTop to y and set elm to its offsetParent 
while(elm != null)
{
x = parseInt(x) + parseInt(elm.offsetLeft);
y = parseInt(y) + parseInt(elm.offsetTop);
elm = elm.offsetParent;
}
//here is interesting thing
//it return Object with two properties
//Top and Left 
return {Top:y, Left: x}; 

}
