var show_logo_duration = 3000;
var fade_duration 		= 500;
var fade_steps				= 10;
var fade_reload 			= 1;				// showing next twin after x milliseconds
var fade_start_time;
var fade_value;

var bgs = 	[
					["bg01.jpg", 140, 80], 
					["bg02.jpg", 150, 50], 
					["bg03.jpg", 140, 50], 
					["bg04.jpg", 120, 40], 
					["bg05.jpg", 150, 80], 
					["bg06.jpg", 140, 50], 
					["bg07.jpg",  90, 52], 
					["bg08.jpg", 145, 40], 
					["bg09.jpg", 182, 65], 
					["bg10.jpg", 150, 50] 
				];
var bg_idx = 9;

/*--------------------------------------------------------------------------------------------------------------*/

var win1Open = null
var win2Open = null
function openPopUp(windowURL, windowName, windowWidth, windowHeight){
  var winHandle = window.open(windowURL,windowName,"toolbar=no,scrollbars=no,resizable=no,width=" + windowWidth + ",height=" + windowHeight)
  return winHandle
  }
function winClose(){
  if(win1Open != null) win1Open.close()
  if(win2Open != null) win2Open.close()
  }
function openPopUpWindow(){}

function openPopUp(windowURL, windowName, windowWidth, windowHeight){
  var winHandle = window.open(windowURL,windowName,"toolbar=no,scrollbars=no,resizable=no,width=" + windowWidth + ",height=" + windowHeight)
  if(winHandle != null) winHandle.focus() //brings window to top
  return winHandle
  }

/*--------------------------------------------------------------------------------------------------------------*/

function SetBGImg()
{
	bg_idx = Math.ceil (Math.random() * 10);

	document.getElementById ("body").style.left = bgs[bg_idx-1][1];
	document.getElementById ("body").style.bottom = bgs[bg_idx-1][2];
	document.getElementById ("html_body").style.backgroundImage = "url(images/web/" + bgs[bg_idx-1][0] + ")";
}

/*--------------------------------------------------------------------------------------------------------------*/

var init_timeout;
var fade_timeout;

function InitPage()
{
	SetBGImg();
	init_timeout = window.setTimeout (StartContent, show_logo_duration);
}

/*--------------------------------------------------------------------------------------------------------------*/

function FadeDiv (node_id, fade_in, initialize)
{
	var fade_end = fade_in ? 100 : 0;
	if (!show_logo) return;

	if (initialize)
	{
		fade_value = fade_in ? 0 : 100;
		fade_start_time	= new Date();
	}	
	else
	{
		var fade_curr_time 		= new Date();
		var fade_curr_duration	= fade_curr_time - fade_start_time;
		var fade_value				= fade_curr_duration / fade_duration * 100;
		
		if (fade_in)
			fade_value 				= Math.min (fade_value, 100);
		else
			fade_value				= Math.max (fade_value, 0);
	}

	var node = document.getElementById (node_id);
	
	node.style.filter 	= "Alpha(opacity=" + Math.ceil (fade_value) + ", finishopacity=0, style=0)";
	node.style.opacity	= fade_value / 100;
	
	if (fade_value != fade_end) 
	{
		fade_timeout = window.setTimeout ('FadeDiv("' + node_id + '", ' + fade_in + ')', fade_reload);
	}
	else 		show_logo = false;

}

/*--------------------------------------------------------------------------------------------------------------*/

var show_logo = true;

function HideLogo()
{
	if (show_logo)
	{
		show_logo = false;
		window.clearTimeout (init_timeout);
		window.clearTimeout (fade_timeout);
		ShowContent();
	}
}

/*--------------------------------------------------------------------------------------------------------------*/

function StartContent()
{
	FadeDiv ("body", true, true);
	ShowContent();
}

/*--------------------------------------------------------------------------------------------------------------*/

function ShowContent()
{
	document.getElementById ("logo").style.display = "none";
	document.getElementById ("body").style.display = "block";
//	document.getElementById ("shop").style.display = "block";
	Show ('cat_service');
}

/*--------------------------------------------------------------------------------------------------------------*/

function Show (category)
{
	var nodes = document.getElementsByTagName ("DIV");
	var active;
	var a_node;
	for (var i = 0; i < nodes.length; i++)
	{
		if (nodes[i].className.substring (0, 3) == "cat")
		{
			active = (nodes[i].className == category);
			nodes[i].style.display = active ? "block" : "none";
			a_node = document.getElementById (nodes[i].className);
			if (a_node) a_node.className = active ? "active" : "";
		}
	}
	
	nodes = document.getElementsByTagName ("SPAN");
	for (var i = 0; i < nodes.length; i++)
	{
		if (nodes[i].className.substring (0, 3) == "cat")
		{
			active = (nodes[i].className == category);
			a_node = document.getElementById (nodes[i].className);
			nodes[i].style.display = active ? "inline" : "none";
		}
	}
}

/*--------------------------------------------------------------------------------------------------------------*/

function ShowFoto (name)
{
	ToggleGUI (false);
	document.getElementById ("foto_node").src = "images/spacer.gif";
	document.getElementById ("foto_node").src = "images/web/" + name;
	TogglePopup ("foto_container", true);
}

/*--------------------------------------------------------------------------------------------------------------*/

function HideFoto()
{
	ToggleGUI (true);
	TogglePopup ("foto_container", false);
}

/*--------------------------------------------------------------------------------------------------------------*/

function ToggleGUI (onoff)
{
	document.getElementById ("body").style.display = onoff ? "block" : "none";
}

/*--------------------------------------------------------------------------------------------------------------*/

function TogglePopup (popup_id, onoff)
{
	document.getElementById (popup_id).style.display = onoff ? "block" : "none";
}

/*--------------------------------------------------------------------------------------------------------------*/

function ShowPopup (popup_id)
{
	ToggleGUI (false);
	TogglePopup (popup_id, true);
	TogglePopup ("popup_container", true);	
}

/*--------------------------------------------------------------------------------------------------------------*/

function HidePopup (popup_id)
{
	TogglePopup ("popup_container", false);	
	TogglePopup (popup_id, false);
	ToggleGUI (true);
}
