/*
 * KIMONO 2.4.1 - New Javascript
 *
 * Copyright (c) 2008 Maximiliano Garcia (kimono.com.ar)
 * GPL LICENSE
 *
 * $Date: 2009-02-16 00:00:00 -0200
 *
 */

/*
 * Function en el cual se carga una ventana fullscreen
 * con el contenido dentro de un iframe, div, img, etc.
 */
function getWindow(archivo, ancho, alto)
{
	var plantilla;
	var etiqueta;
	var posi_close;
	var ban;

	/*
	 * Cargo la ventana, tapando el fondo
	 */

	/*
	 * Seteo de etiqueta(DIV) principal en donde se cargara la ventana
	 */
	 
	 
	alto = new Number(alto);
	ancho = new Number(ancho);
	
	if ($.browser['msie'] && $.browser['version'] == "6.0")
	{
		alto = alto + 25;
		ancho = ancho + 30;
	}
	 
	etiqueta = "kimono";

	$("#"+etiqueta).remove();
	$("#window").remove();

	/*
	 * Creo la etiqueta de forma dinamica
	 */
	$("body").append("<div id=\""+ etiqueta +"\"></div>");
	
	$("#"+etiqueta).fadeTo("fast", 0.40);

	
	ext = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();

	arr_img = [".gif", ".jpg", ".png"];
	arr_flash = [".swf", ".flv"];

	if ($.inArray(ext, arr_img)>=0) {

		content = "<img src=\""+archivo+"\" width=\""+ancho+"\" height=\""+alto+"\" border=\"0\">";

	}else if ($.inArray(ext, arr_flash)>=0) {

		content = "<script type=\"text/javascript\">";
		content = content + "swfobject.embedSWF(\""+archivo+"\", \"myContent\", \""+ancho+"\", \""+alto+"\", \"9.0.0\")";
		content = content + "</script>";
		content = content + "<div id=\"myContent\">Codigo alternativo</div>";

	}else{

		content = "<iframe src=\""+archivo+"\" marginwidth=\"0\" marginheight=\"0\" hspace=\"0\" allowtransparency=\"false\" frameborder=\"0\" width=\""+ancho+"\" height=\""+alto+"\"></iframe>";

	}

	/*
	 * Armado de plantilla en donde se muestran los contenidos
	 */
	plantilla = "<div id=\"window\">";
	plantilla = plantilla + "<div id=\"close\"></div>";
	plantilla = plantilla + content;
	plantilla = plantilla + "</div>";

	/*
	 * Cargo un div fullscreen, tapando el fondo
	 */
	$("#"+etiqueta).fadeIn("slow");

	/*
	 * Cargo la ventana, sobre el centro de la pagina
	 */
	$("body").append(plantilla);

	/*
	 * Cierro ventana desde el boton cerrar
	 */
	$("#close").click(function() {
		$("#"+etiqueta).fadeOut("fast", function(){
			$("#"+etiqueta).remove();
		});
		$("#window").remove();
	});

	/*
	 * Cierro ventana haciendo clic en el fondo
	 */
	$("#"+etiqueta).click(function() {
		$("#"+etiqueta).fadeOut("show", function(){
			$("#"+etiqueta).remove();
		});
		$("#window").remove();
	});

	/*
	 * Seteo de coordenadas del boton cerrar
	 */
	posi_close = (($("#"+etiqueta).height()/2)-(alto/2))-10;

	
	function posicionar()
	{
		/*
	 	*	Saco el ancho y el alto de la ventana
	 	*/
		var winWidth = $(window).width();
		var winHeight  = $(window).height();
		
		var docWidth = $(document).width();
		var docHeight  = $(document).height();
		
		window_x = ((winWidth/2)-(ancho/2));
		
		var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
		var dsoctop=document.all? iebody.scrollTop : pageYOffset
		window_y = ((winHeight/2)-(alto/2)) + dsoctop;
		
		/*
	 	* Configuracion de CSS para XXX
	 	*/
		
		$("#window").css("width",""+ancho+"px","height",""+alto+"px");
		$("#window").css("top",""+window_y+"px");
		$("#window").css("left",""+window_x+"px");
		$("#"+etiqueta).css("height",""+docHeight+"px");
	}
	
	posicionar();
	
	$(window).bind("resize scroll", function(e){
		posicionar();
	});
	
}
