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/models/'+s;
	pic.onload = L;
	op = 10;
	if(!document.getElementById('BigPicture').src.match(eval('/'+s+'$/')))
		FadeOut(op);

}

function L()
{
	LI[src] = 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/models/'+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/models/'+src;
		FadeIn();
	}
}

function FadeIn()
{
	if(TimerID)
		clearTimeout(TimerID);
	if(LI[src] == 1)
	{
		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();
		}
	}
	else
	{
		TimerID = setTimeout("FadeIn()",50);
	}
}

function GenerateBar(q,id)
{
	LL = q * 165;
	document.write('<div id="slider" style="width:'+LL+'px;position:block;float:center;text-align:center;">');
	for(i=1;i<=q;i++)
	{
		document.write('<img src="/img/models/tn'+id+'_'+i+'.jpg" class="bar" onClick="ChangeImage(\''+id+'_'+i+'.jpg\')"/>');
	}
	document.write('</div>');
}

function MakeSlide()
{
	if(TimerID)
		clearTimeout(TimerID);
	LM += LV;
	if(SL && LM <= 0 && LL >= 530 && LM >= (530 - LL - 40))
	{
		document.getElementById('slider').style.marginLeft = LM + 'px';
		TimerID = setTimeout("MakeSlide()",1);
	}
}

function SlideLeft()
{
	LV = 2;
	SL = 1;
	TimerID = setTimeout("MakeSlide()",1);
}

function SlideRight()
{
	LV = -2;
	SL = 1;
	TimerID = setTimeout("MakeSlide()",1);
}

function StopSlide()
{
	SL = 0;
	LV = 0;
//	clearTimeout(TimerID);
}
