<?php
/*
 * Created on May 19, 2006
 *
 * SmartIT
 * http://SmartIT.pl
 */

$uri = $_SERVER['QUERY_STRING'];
$uri = ereg_replace("lang=pl&", "", $uri);
$uri = ereg_replace("lang=pl", "", $uri);
$uri = ereg_replace("lang=en&", "", $uri);
$uri = ereg_replace("lang=en", "", $uri);
$uri = ereg_replace("lang=de", "", $uri);
$uri = ereg_replace("lang=de&", "", $uri);
switch ($_GET['lang']) {
	case 'pl':
		$lang = "pl";
		include("../descriptions/siteDescriptionsPL.inc.php5");
	break;
	case 'en':
		$lang = "en";
		include("../descriptions/siteDescriptionsEN.inc.php5");
	break;
	case 'de':
		$lang = "de";
		include("../descriptions/siteDescriptionsDE.inc.php5");
	break;
	default:
		$lang = "pl";
		include("../descriptions/siteDescriptionsPL.inc.php5");
	break;
}
?>

var viewImagesArray;
var viewImagesPosition;

function viewImage( images, pos )
{
	if( !pos )
	{
		pos = 0;
	}

	/* dane obowiazkowe */

	if( !images[pos] )
	{
		if( !images[0] )
		{
			return;
		}
		else
		{
			pos = 0;
		}
	}

	viewImagesArray = images;
	viewImagesPosition = pos;

	/* nalezy sprawdzic czy elementy nie zostaly juz otworzone */

	if( document.getElementById( 'viewImageBgDiv' ) || document.getElementById( 'viewImageMainDiv' ))
	{
		closeViewImage();
	}


	/* ustanowienie elementu DIV bedacego czesciowo przezroczystym tlem */
	var winInHt = Math.max(document.body.clientHeight, (document.documentElement? document.documentElement.clientHeight : 0));
	//

	var html = '<div id="viewImageBgDiv" style="position:absolute;left:0;top:0;width:100%;height:' + winInHt +'px;background-color:#000;filter:alpha(opacity=70);-moz-opacity: 0.70;">&nbsp;</div>';



	var pos_y;
	var pos_x;

	var client_Height = f_clientHeight();
	var client_Width = f_clientWidth();


	if( client_Height <= images[pos][2] + 45 )
	{
		pos_y = f_scrollTop();
		alert(client_Height);
	}
	else
	{
		pos_y = f_scrollTop() + Math.round( ( client_Height - images[pos][2] - 45 ) / 2 );
	}

	if( client_Width <= images[pos][1] + 10 )
	{
		pos_x = f_scrollLeft();
	}
	else
	{
		pos_x = f_scrollLeft() + Math.round( ( client_Width - images[pos][1] - 10 ) / 2 );
	}

	html += '<div id="viewImageMainDiv" style="position: absolute;left: ' + pos_x+ 'px;top: ' + pos_y + 'px">';
	html += '<a href="javascript:void(0)" onclick="closeViewImage()" class="closeViewImage"><img src="img/closeicon.png" alt="<?php print CLOSE; ?>" title="<?php print CLOSE; ?>" /></a>';
	html += '<img alt="" id="imageViewerImg" />';

	if( images.length > 1 )
	{
		html += '<table id="viewImageNav" style="width: ' + images[pos][1] + 'px"><tr><td class="viewImageNavPrevious"><a href="javascript:void(0)" onclick="toggleImage(-1)">&laquo; <?php print PREVIOUS; ?></a></td><td class="viewImageNavNext"><a href="javascript:void(0)" onclick="toggleImage(1)"><?php print NEXT; ?> &raquo;</a></td></tr></table>';
	}
	html += '</div>';

	var newDiv = document.createElement('DIV');
	newDiv.setAttribute('id','imageViewerContainer');
	newDiv.innerHTML = html;
	document.body.appendChild(newDiv);

	actualImageSrc = images[pos][0];
	window.setTimeout(function() { document.getElementById("imageViewerImg").src = actualImageSrc }, 100);
}


function toggleImage( direction )
{
	if( !viewImagesArray )
	{
		return;
	}

	var pos = viewImagesPosition + direction;

	if( pos >= viewImagesArray.length )
	{
		pos = 0;
	}
	else
	{
		if( pos < 0 )
		{
			pos = viewImagesArray.length - 1;
		}
	}

	closeViewImage();
	viewImage( viewImagesArray, pos );
	return;
}

function closeViewImage()
{
	/*
	document.getElementById('viewImageBgDiv') ? document.body.removeChild(document.getElementById('viewImageBgDiv')) : void(0);
	document.getElementById('viewImageMainDiv') ? document.body.removeChild(document.getElementById('viewImageMainDiv')) : void(0);
	*/
	document.body.removeChild( document.getElementById('imageViewerContainer'));
	return;
}


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;
	*/
	return n_docel;
}

