/************************************************************************/
/* Nelsou.com                                                           */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2007 by Nelson (nelsou.com@gmail.com)                  */
/*                                                                      */
/* =========================                                            */
/* $Id: javascripts/nels_box.js,v 1.0 Nelson Exp $                      */
/* File Last Updated:                                                   */
/* 17:02 19/09/2007                                                     */
/************************************************************************/

gl_wiindow = {};
gl_wiindow.height = null;
gl_wiindow.width = null;

function show_image(path, height, width)
{
  photo = new Image();
  photo.src = path;
  photo.onload = function()
  {
    var W, H;
    tmp = screen_size();
    W = tmp[0];
    H = tmp[1];
    var coefX = photo.width / (W - 200);
    var coefY = photo.height / (H - 200);
    var coef = ((coefX > coefY) ? coefX : coefY);
    if (coef < 1)
    {
      newWidth = photo.width;
      newHeight = photo.height;
    }
    else
    {
      newWidth = photo.width / coef;
      newHeight = photo.height / coef;
    } 
  	show_wiindow(newHeight, newWidth);
  	var image = document.createElement('img');
  	image.src = path;
  	image.style.height = newHeight + 'px';
  	image.style.width = newWidth + 'px';
 		$('wiindow_inside').innerHTML = "";
 		$('wiindow_inside').appendChild(image);
  }
  return true;
}

function show_wiindow(height, width)
{
	gl_wiindow.height = height;
	gl_wiindow.width = width;

	init_wiindow(height, width + 40);
	$('wiindow_inside').innerHTML = "<img src=\"images/loading.gif\"> &nbsp; Loading ...";
	$('control_menu').style.display = 'block';
	$('wiindow').style.display = 'block';
	$('overlay').style.display = 'block';
	$('html').style.overflow = 'hidden';
  return true;
}

function hide_wiindow()
{
  control_stop();
	$('wiindow').style.display = 'none';
	$('control_menu').style.display = 'none';
	$('overlay').style.display = 'none';
	$('html').style.overflow = 'auto';
  return true;
}

function init_wiindow(height, width)
{
	tmp = screen_size();
	windowWidth = tmp[0];
  windowHeight = tmp[1];

	newPosX = (windowWidth / 2) - width / 2;
	newPosY = (windowHeight / 2) - height / 2;

  //Morphing($('wiindow'), {left: newPosX, top: newPosY, width: width, height: height}, 0);

	$('wiindow').style.left = newPosX + 'px';
	$('wiindow').style.top = newPosY + 'px';
	$('wiindow').style.width = width - 10 + 'px';
	$('wiindow').style.height = height + 'px';

	$('overlay').onclick = hide_wiindow;
	$('overlay').style.width = windowWidth + 'px';
	$('overlay').style.height = windowHeight + 'px';
  return true;
}
