var pth    	= "images/";
var fld_heigh = 600;
var pn_top_lst 	= new Array(2);
var pn_dwn_lst 	= new Array(2);
var pn_top_top;
var pn_dwn_top;

var act_scren = 0;
var sld_scren = 0;
var max_screns = 8;
var show_scren;
var hide_scren;
var show_val;
var scr_del = 10;
var scr_step = 10;
var close_sld = false;
var slide_del = 5000;
var logo_top;
var descr_left_pos = -10, descr_left_acc, descr_right_pos, descr_right_acc;
var show_descr = false;
var displ_gallery = false;

var anim_start = true, anim_gallery = false, anim_descr = false;

function on(name)
{
	document.images[name].src = pth + name + '_on.jpg';
	return true;
}

function off(name)
{
	document.images[name].src = pth + name + '_off.jpg';
	return true;
}

function ShowEngine()
{
	stop = false;
	
	if(document.all(pn_top_lst[0]).style.posHeight > 1)
	{
		pn_top_top += 5
		if(pn_top_top >= 0)
		{
			stop = true;
			pn_top_top = 0;
		}
		
		for(j=0;j<2;j++)
		{
			document.all(pn_top_lst[j]).style.top = pn_top_top + "px";
		}
	}
	
	if(document.all(pn_dwn_lst[0]).style.posHeight > 1)
	{
		pn_dwn_top -= 5;
		if(pn_dwn_top <= (fld_heigh - document.all(pn_dwn_lst[0]).style.posHeight))
		{
			stop = true;
			pn_dwn_top = fld_heigh - document.all(pn_dwn_lst[0]).style.posHeight;
		}
		for(j=0;j<2;j++)
		{
			document.all(pn_dwn_lst[j]).style.top = pn_dwn_top + "px";
		}
	}
	
	if(stop)
	{
		clearInterval(showit);
		if(logo_top == -100)
		{
			document.all("sm_logo").style.top		= logo_top + "px";
			logo_anim = setInterval("LogoEngine()", 10);
		}
		
		if(pn_dwn_lst[1] == "sld_panel_top")
		{
			close_sld	= false;
			anim_gallery = false;
			NextScreen();
		}
		else
		{
			document.all("legend").style.display	= "block";
			document.all("bg_legend").style.display	= "block";
			legendit = setInterval("LegendEngineShow()", 10);
		}
	}
}

function HideEngine()
{
	stop = false;
	
	if(document.all(pn_top_lst[0]).style.posHeight > 1)
	{
		pn_top_top -= 5;
		if(pn_top_top <= -document.all(pn_top_lst[0]).style.posHeight)
		{
			stop = true;
			pn_top_top = -document.all(pn_top_lst[0]).style.posHeight;
		}
		
		for(j=0;j<2;j++)
		{
			document.all(pn_top_lst[j]).style.top = pn_top_top + "px";
		}
	}
	
	if(document.all(pn_dwn_lst[0]).style.posHeight > 1)
	{
		pn_dwn_top += 5;
		if(pn_dwn_top >= fld_heigh)
		{
			stop = true;
			pn_dwn_top = fld_heigh;
		}
		for(j=0;j<2;j++)
		{
			document.all(pn_dwn_lst[j]).style.top = pn_dwn_top + "px";
		}
	}
	
	if(stop)
	{
		clearInterval(hideit);
		
		if(document.all(pn_top_lst[0]).style.posHeight > 1)
		{
			for(j=0;j<2;j++)
			{
				document.all(pn_top_lst[j]).style.display		= "none";
			}
		}
		
		if(document.all(pn_dwn_lst[0]).style.posHeight > 1)
		{
			for(j=0;j<2;j++)
			{
				document.all(pn_dwn_lst[j]).style.display		= "none";
			}
		}
		
		if(pn_dwn_lst[1] == "tp_panel_down")
		{
			Show(0, "", 24, "sld_panel_top");
		}else if(pn_dwn_lst[1] == "sld_panel_top")
		{
			Show(95, "tp_panel_top", 95, "tp_panel_down");
		}
	}
}

function Show(top_hg, top_name, dwn_hg, dwn_name)
{
	pn_top_lst[0] = "gr_panel_top";
	pn_top_lst[1] = top_name;

	pn_dwn_lst[0] = "gr_panel_down";
	pn_dwn_lst[1] = dwn_name;
	
	showit = setInterval("ShowEngine()", 10);
	if(top_hg > 0)
	{
		pn_top_top = -top_hg;
		for(j=0;j<2;j++)
		{
			document.all(pn_top_lst[j]).style.posHeight			= top_hg;
			document.all(pn_top_lst[j]).style.top				= pn_top_top + "px";
			document.all(pn_top_lst[j]).style.display			= "block";
		}
	}
	else
	{
		document.all(pn_top_lst[0]).style.posHeight			= 1;
		document.all(pn_top_lst[0]).style.display			= "none";
	}

	if(dwn_hg > 0)
	{
		pn_dwn_top = fld_heigh;
		for(j=0;j<2;j++)
		{
			document.all(pn_dwn_lst[j]).style.top				= pn_dwn_top + "px";
			document.all(pn_dwn_lst[j]).style.posHeight			= dwn_hg;
			document.all(pn_dwn_lst[j]).style.display			= "block";
		}
	}
	else
	{
		document.all(pn_dwn_lst[0]).style.posHeight			= 1;
		document.all(pn_dwn_lst[0]).style.display			= "none";
	}
}

function Hide()
{
	hideit = setInterval("HideEngine()", 10);
}

function LogoEngine()
{
	document.all("sm_logo").style.display	= "block";
	logo_top += 10;
	document.all("sm_logo").style.top		= logo_top + "px";
	if(logo_top==0)
	{
		clearInterval(logo_anim);
	}
}

function StartEngine()
{
	clearInterval(startit);
	legend_op = 0;
	SetOpacity("legend", legend_op);
	SetOpacity("bg_legend", legend_op);
	document.all("legend").style.display	= "block";
	document.all("bg_legend").style.display	= "block";
	Show(95, "tp_panel_top", 95, "tp_panel_down");
}

function LegendChangeEngine()
{
	document.all("leg_" + act_leg).style.display	= "none";
	act_leg++;
	if(act_leg>10)
	{
		act_leg = 1;
	}
	document.all("leg_" + act_leg).style.display	= "block";
	document.getElementById("nav_legend_counter").innerHTML = "Legend<br>" + act_leg + "/10";
}

function LegendEngineHide()
{
	legend_op -= 5;
	SetOpacity("legend", legend_op);
	SetOpacity("bg_legend", legend_op/5);
	if(legend_op <= 0)
	{
		document.all("legend").style.display	= "none";
		document.all("bg_legend").style.display	= "none";
		clearInterval(legendit);
	}
}

function LegendEngineShow()
{
	legend_op +=5;
	SetOpacity("legend", legend_op);
	SetOpacity("bg_legend", legend_op/5);
	if(legend_op >= 100)
	{
		anim_start = false;
		anim_gallery = false;
		clearInterval(legendit);
		legendch = setInterval("LegendChangeEngine()", 12000);
	}
}

function PrevLegend()
{
	clearTimeout(legendch);
	legendch = setInterval("LegendChangeEngine()", 12000);
	document.all("leg_" + act_leg).style.display	= "none";
	act_leg--;
	if(act_leg < 1)
	{
		act_leg = 10;
	}
	document.all("leg_" + act_leg).style.display	= "block";
	document.getElementById("nav_legend_counter").innerHTML = "Legend<br>" + act_leg + "/10";
}

function NextLegend()
{
	clearTimeout(legendch);
	legendch = setInterval("LegendChangeEngine()", 12000);
	LegendChangeEngine();
}

function InitLegends()
{
	SetOpacity("nav_legend_counter", 60);
	act_leg = 1;
	document.getElementById("nav_legend_counter").innerHTML = "Legend<br>1/10";
	document.all("leg_1").style.display	= "block";
}

function ShowGallery()
{
	if(!anim_start && !anim_gallery && !anim_descr)
	{
		document.all("get_free").style.display = "none";
		if(show_descr)
		{
			displ_gallery = true;
			ShowDescription();
		}
		else
		{
			legendit = setInterval("LegendEngineHide()", 10);
			clearInterval(legendch);
			anim_gallery = true;
			Hide();
		}
	}
}

function Start()
{
	startit = setInterval("StartEngine()", 1500);
	logo_top = -100;
	InitLegends();
}

// ------------------------------------------------------------------------------

function SetOpacity(name, value)
{
	var targetobject = document.all(name);
		
	targetobject.style.filter="alpha(opacity="+value+")";
	targetobject.style.opacity=(value/100);
}

function ShowScreenEngine()
{
 	show_val += scr_step;
	if(show_val >= 100)
	{
		if(hide_scren)
			document.all('scr_' + hide_scren).style.display = "none";
		show_val = 100;
		clearInterval(hdscrit);
	}
	SetOpacity('scr_' + show_scren, show_val);
}

function HideScreenEngine()
{
 	show_val -= scr_step;
	if(show_val <= 0)
	{
		document.all('scr_' + hide_scren).style.display = "none";
		show_val = 0;
		clearInterval(hdscrit);
		
		if(close_sld)
		{
			hide_scren = 0;
			Hide();
		}
	}
	else
		SetOpacity('scr_' + hide_scren, show_val);
}

function ShowScreen(scr_num)
{
	if ((show_val > 0) && (show_val <100))
	{
		SetOpacity('scr_' + show_scren, 100);
		document.all('scr_' + hide_scren).style.display = "none";
		clearTimeout(hdscrit);
	}

	sld_scren = scr_num;
	if (typeof slideit!="undefined")
		clearTimeout(slideit);
	
	slideit = setInterval("ShowSlideshowEngine()", slide_del);
	
	if((scr_num > act_scren) || (hide_scren == 0))
	{
		show_scren	= scr_num;
		hide_scren	= act_scren;
		act_scren	= scr_num;
		show_val	= 0;
		
		SetOpacity('scr_' + show_scren, show_val);
		document.all('scr_' + show_scren).style.display = "block";
		
		hdscrit = setInterval("ShowScreenEngine()", scr_del);
		document.images["sld_" + show_scren].src = 'images/sld_act.jpg';
		if(hide_scren)
			document.images["sld_" + hide_scren].src = 'images/sld_pas.jpg';
	} else if(scr_num < act_scren)
	{
		show_scren	= scr_num;
		hide_scren	= act_scren;
		act_scren	= scr_num;
		show_val	= 100;
		
		SetOpacity('scr_' + hide_scren, show_val);
		document.all('scr_' + hide_scren).style.display = "block";
		SetOpacity('scr_' + show_scren, show_val);
		document.all('scr_' + show_scren).style.display = "block";
		
		hdscrit = setInterval("HideScreenEngine()", scr_del);
		document.images["sld_" + show_scren].src = 'images/sld_act.jpg';
		document.images["sld_" + hide_scren].src = 'images/sld_pas.jpg';
	}
}

function ShowSlideshowEngine()
{
	sld_scren++;
	if(sld_scren > max_screns)
		sld_scren = 1;
		
	ShowScreen(sld_scren);
}

function PrevScreen()
{
	sld_scren--;
	if(sld_scren<1)
		sld_scren = max_screns;
	
	ShowScreen(sld_scren);
}

function NextScreen()
{
	sld_scren++;
	if(sld_scren>max_screns)
		sld_scren = 1;
	
	ShowScreen(sld_scren);
}

function CloseSlideshow()
{
	if(!anim_gallery)
	{
		anim_gallery = true;
		if (typeof slideit!="undefined")
			clearTimeout(slideit);
		
		show_val	= 100;
		close_sld	= true;
		
		if(hide_scren)
		{
			document.all('scr_' + hide_scren).style.display = "none";
			SetOpacity('scr_' + hide_scren, show_val);
		}
		
		hide_scren = show_scren;
		
		SetOpacity('scr_' + show_scren, show_val);
		document.all('scr_' + show_scren).style.display = "block";
		hdscrit = setInterval("HideScreenEngine()", scr_del);
	}
}

// ------------------------------------------------------------------------------

function DescriptionShowEngine()
{
	lft_st = false;
	rgt_st = false;
	
	if(descr_left_pos < 0)
	{
		descr_left_pos += descr_left_acc;
		descr_left_acc--;
		if(descr_left_pos > 0)
		{
			descr_left_pos = 0;
			lft_st = true;
		}
		document.all("desc_lft").style.left		= descr_left_pos + "px";
	}	
	else
		lft_st = true;

	if(descr_right_pos > 256)
	{
		descr_right_pos -= descr_right_acc;
		descr_right_acc--;
		if(descr_right_pos <= 256)
		{
			descr_right_pos = 256;
			rgt_st = true;
		}
		document.all("desc_rgt").style.left		= descr_right_pos + "px";
	}	
	else
	{
		rgt_st = true;
	}
	
	if(lft_st && rgt_st)
	{
		clearInterval(descrit);
		show_descr = true;
		anim_descr = false;
	}
}

function DescriptionHideEngine()
{
	lft_st = false;
	rgt_st = false;
	
	if(descr_left_pos > -256)
	{
		descr_left_pos -= descr_left_acc;
		descr_left_acc++;
		if(descr_left_pos <= -256)
		{
			descr_left_pos = 256;
			document.all("desc_lft").style.display	= "none";
			lft_st = true;
		}
		document.all("desc_lft").style.left		= descr_left_pos + "px";
	}	
	else
		lft_st = true;

	if(descr_right_pos < 800)
	{
		descr_right_pos += descr_right_acc;
		descr_right_acc++;
		if(descr_right_pos >= 800)
		{
			descr_right_pos = 800;
			document.all("desc_rgt").style.display	= "none";
			rgt_st = true;
		}
		document.all("desc_rgt").style.left		= descr_right_pos + "px";
	}	
	else
	{
		rgt_st = true;
	}
	
	if(lft_st && rgt_st)
	{
		clearInterval(descrit);
		show_descr = false;
		anim_descr = false;
		if(displ_gallery)
		{
			displ_gallery = false;
			ShowGallery();
		}
	}
}

function ShowDescription()
{
	if(!anim_start && !anim_gallery && !anim_descr)
	{
		document.all("get_free").style.display = "none";
		anim_descr = true;
		if(show_descr)
		{
			legendch = setInterval("LegendChangeEngine()", 12000);
			descrit = setInterval("DescriptionHideEngine()", 10);
		}
		else
		{
			descr_left_pos	= -256;
			descr_left_acc	= 25;
			descr_right_pos	= 800;
			descr_right_acc	= 35;
			
			document.all("desc_lft").style.left		= descr_left_pos + "px";
			document.all("desc_rgt").style.left		= descr_right_pos + "px";
			document.all("desc_lft").style.display	= "block";
			document.all("desc_rgt").style.display	= "block";
			
			descrit = setInterval("DescriptionShowEngine()", 10);
			clearInterval(legendch);
		}
	}
}

function GetFree()
{
	if(document.all("get_free").style.display == "block")
		document.all("get_free").style.display = "none";
	else
		document.all("get_free").style.display = "block";
}
