var op;
var src;
var fi;
var TimerID;
LI = new Array();
var pic;
var dir;
var LM = 0;
var LV = 0;
var LL = 0;
var SL;
function ChangeImage(s)
{
	src = s;
	s = s.replace(/\//ig,"\\\/");
	pic = new Image();
	pic.src = '/img/gallery/'+s;
//	src = pic.src;
	
	if (pic.addEventListener)
		pic.addEventListener("DOMContentLoaded", L, true);
	else
		pic.onload = L;
	op = 10;
	if(!document.getElementById('BigPicture').src.match(eval('/'+s+'$/')))
		FadeOut(op);

}

function L()
{
	LI[src] = 1;
//	alert('1');
}

function ShowImage()
{
	if(document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1] >= 5.5)
		document.getElementById('BigPicture').style.filter = ''
	document.getElementById('BigPicture').src = '/img/gallery/'+src;
}

function FadeOut()
{
	if(TimerID)
		clearTimeout(TimerID);
	op = op - 1;
	if(document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1] >= 5.5)
		document.getElementById('BigPicture').style.filter = 'alpha(opacity = '+ (op * 10) +')'
	else if (typeof document.body.style.MozOpacity == 'string')
		document.getElementById('BigPicture').style.MozOpacity = op/10;
	else if (typeof document.body.style.opacity == 'string')
		document.getElementById('BigPicture').style.opacity = op/10;
	if(op >= 0)
		TimerID = setTimeout("FadeOut("+op+")",70);
	else
	{
		document.getElementById('BigPicture').src = '/img/gallery/'+src;
		FadeIn();
	}
}

function FadeIn()
{
	if(TimerID)
		clearTimeout(TimerID);
	if(LI[src] == 1 || pic.addEventListener)
	{
		op = op + 1;
		if(document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1] >= 5.5)
			document.getElementById('BigPicture').style.filter = 'alpha(opacity = '+ (op * 10) +')'
		else if (typeof document.body.style.MozOpacity == 'string')
			document.getElementById('BigPicture').style.MozOpacity = op/10;
		else if (typeof document.body.style.opacity == 'string')
			document.getElementById('BigPicture').style.opacity = op/10;
		if(op <= 10)
			TimerID = setTimeout("FadeIn("+op+")",70);
		else
		{
			op = 10;
			ShowImage();
		}
//		alert('ddd');
	}
	else
	{
		TimerID = setTimeout("FadeIn()",50);
	}
}

function GenerateBar(q,d)
{
	dir = d;
//	LL = q * 100;
	document.write('<div id="slider" style="float:left;text-align:center;"><nobr>');
	for(i = q; i >= 1 ;--i)
	{
		document.write('<img src="/img/gallery/'+d+'/t_'+i+'.jpg" class="preview_img" onClick="ChangeImage(\''+d+'/'+i+'.jpg\')" />');
	}
	document.write('</nobr></div>');
}

function MakeSlide()
{
	if(TimerID)
		clearTimeout(TimerID);
	LM += LV;
	if(SL && LM <= 0 && document.getElementById('slider').scrollWidth >= 500 && LM >= (500 - document.getElementById('slider').scrollWidth - 20))
	{
		document.getElementById('slider').style.marginLeft = LM + 'px';
		TimerID = setTimeout("MakeSlide()",1);
	}
}

function SlideLeft()
{
	LV = 4;
	SL = 1;
	TimerID = setTimeout("MakeSlide()",1);
}

function SlideRight()
{
	LV = -4;
	SL = 1;
	TimerID = setTimeout("MakeSlide()",1);
}

function StopSlide()
{
	SL = 0;
	LV = 0;
//	clearTimeout(TimerID);
}

