// JavaScript Document



//===================  GENERAL   FUNCTIONS   ====================================================================
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function setOpac(value, element)
{
	document.getElementById(element).style.opacity = "" + (value / 100);
	document.getElementById(element).style.MozOpacity = "" + (value / 100);
	document.getElementById(element).style.KhtmlOpacity = "" + (value / 100);
	document.getElementById(element).style.filter = "alpha(opacity=" + value +")";
	//document.getElementById(element).setAttribute("filter", "alpha(opacity=" + value + ")");
	return;
}

function velate(btn)
{
	velo=document.getElementById('velate');
	if(btn == true)
	{
		velo.style.display="block";
		velo.style.width=($('body').getWidth()) + "px";
		velo.style.height=($('body').getHeight()) + "px";
	}
	if(btn == false)
	{
		velo.style.display="none";
		velo.style.width="0px";
		velo.style.height="0px";
	}
return;
}

//===================  GENERAL   FUNCTIONS   ====================================================================









//===================  SPECIFIC   FUNCTIONS   ====================================================================

panelTimer = 0;

function dynPos(width,height,div_opening)
{
  var top = (f_clientHeight() / 2) + f_scrollTop() - (Math.ceil(height / 2));
  var left = (f_clientWidth() / 2) + f_scrollLeft() - (Math.ceil(width / 2));
  document.getElementById(div_opening).style.top= top + "px";
  document.getElementById(div_opening).style.left = left + "px";	
}

function openPanel(width, height, div_opening)
{
  panelTimer = setInterval("dynPos(" + width + "," + height + ", '" + div_opening + "')",50);
  document.getElementById(div_opening).style.width=width + "px";
  document.getElementById(div_opening).style.height=height + "px";
}

function closePanel(div, text_space)
{
  document.getElementById(div).style.top= "0px"
  document.getElementById(div).style.left = "0px"
  document.getElementById(div).style.width="0px"
  document.getElementById(div).style.height="0px"
  document.getElementById('poster').src="template/blank.gif"
  if(text_space != "") document.getElementById(text_space).innerHTML = "";
  velate(false);
  clearInterval(panelTimer);
}

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		do {
			  curleft += obj.offsetLeft;
			  curtop += obj.offsetTop;
		   }
		while (obj = obj.offsetParent);
	}
return new Array(curleft,curtop);
}	
	
//===================  SPECIFIC   FUNCTIONS   ====================================================================








// ======================   POSTER   CONTROL   =============================================================


control_poster = 0;
control_image = 0;
function showPoster(image)
{
    velate(true);
	posterView = document.getElementById('poster_view');
	document.getElementById('poster').src = "thumbnail.php?image=" + image + "&width=640&height=480";
	var img_h = $('poster').getHeight();
	getDimensionPoster('poster');
    control_image = setInterval("waitForImage(img_h)", 10);
}

function waitForImage(img_h)
{
	if(img_h != 1) 
	{
		h_spacer = Math.ceil((480 - img_h) / 2);
		document.getElementById('spacer').style.height = h_spacer + "px";
		clearInterval(control_image);
	}
}

function getDimensionPoster(poster)
{
	width = 680;
	height = 540;
	if(width != 0 && height != 0) openPanel(width,height,"poster_view");
}

function closePoster()
{
	closePanel("poster_view", "");
	velate(false);
}

// ======================   POSTER   CONTROL   =============================================================
