var i, n, m, k, size, winH, winW, ss, ow, oh;
var curleft = curtop = 0;
var temp = new Image();
n=0;
k=0;

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
}

function getPageSize()
{
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	winH = windowHeight;
	winW = windowWidth;
}

function expand(name)
{
	clearInterval(i);
	temp = new Image();
	obj = document.getElementById('i' + name);
	//orientation check
	ow = obj.width;
	oh = obj.height;
	c = document.getElementById('carrier');
	c.style.visibility='hidden';
	c.style.width='0px';
	c.style.height='0px';
	im = document.getElementById('img');

	im.src = "img/loading.gif";
	curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	ss=getPageScroll();
	getPageSize();
 	n = 0;
	m = 0;
	c.style.top = curtop  + 15 + 'px';
	c.style.left = curleft + 15 + 'px';
	c.style.width=ow + 'px';
	c.style.height=oh + 'px';
	c.style.visibility='visible';
	im.style.width= ow + 'px';
	im.style.height= oh + 'px';

	if(winH<=602)
	{
		size=800;
	}
	else
		size=1024;
	n = curtop-ss + 15;
	m = curleft + 15;
	temp.onload=function(){
			im.src=temp.src;
			i = setInterval("dresize(c)", 10);
	}
	temp.src = 'galeria/' + size + '/' + name + '.JPG';
}
function dresize(c)
{
	im = document.getElementById('img');
	if(parseInt(im.style.height) < winH)
	{
		x = Math.round((n)*18/(winH-oh));
		if(parseInt(c.style.top)-curtop<18&&parseInt(c.style.top)-ss>-18&&Math.abs(x)>Math.abs(parseInt(c.style.top)-ss))
		{
			c.style.top = ss + "px";
		}
		else
		{
			c.style.top = parseInt(c.style.top)-x + "px";
		}
		y = Math.round(((winW-winH*ow/oh)/2-m)*18/(winH-oh));
		c.style.left = parseInt(c.style.left)+y + "px";
		c.style.height = parseInt(c.style.height)+18 + "px";
		im.style.height = parseInt(im.style.height)+18 + "px";
		if(ow/oh>1)
		dd = 24;
		else
		dd = 13;
		c.style.width = parseInt(c.style.width)+dd + "px";
		im.style.width = parseInt(im.style.width)+dd + "px";

	}
	else
	{
		clearInterval(i);
	}
}
function iclose()
{
	clearInterval(i);
	c = document.getElementById('carrier');
	c.style.visibility='hidden';
	c.style.width='0px';
	c.style.height='0px';
	im = document.getElementById('img');
	im.src = "img/loading.gif";
}