var image = new Array();
var over_image = new Array();
function loadImages()
{
	if (document.getElementById)
	{
		document.getElementById('hidepage').style.visibility = 'hidden';
	}
	else
	{

		if (document.layers)
		{
			document.hidepage.visibility = 'hidden';
		}
		else
		{ 
			document.all.hidepage.style.visibility = 'hidden';
		}
	}
	
	image[0] = new Image();
	image[0].src = siteurl + "/images/close.gif";
	over_image[0] = new Image();
	over_image[0].src = siteurl + "/images/close2.gif";

	document.getElementById('table').style.visibility = 'hidden';
	initEffects();
}


function initEffects()
{
	ob_table = new fx.Opacity($("table"), {duration:1000});
	ob_body_menu = new fx.Height($("body_menu"), {duration:500, transition: fx.cubic, onComplete: function(){	
		setTimeout("ob_small_text.toggle()", 300);
	}});
	ob_v_stripe = new fx.Height($("v_stripe"), {duration:450, transition: fx.cubic});
	ob_text_block = new fx.Width($("text_block"), {duration:300, transition: fx.linear, onComplete: function(){
		ob_main_text.toggle();
	}});
	ob_main_text = new fx.Opacity($("main_text"), {duration:500});
	ob_small_text = new fx.Opacity($("small-text"), {duration:500});
	ob_secondary_menu = new fx.Width($("secondary_menu"), {duration:500});
	ob_menu_block = new fx.Width($("menu_block"), {duration:500, transition: fx.linear});
	ob_page_title = new fx.Width($("page_title"), {duration:500, transition: fx.linear, onComplete: function(){
		ob_secondary_menu.custom(20,170);
	}});
	ob_uptodate = new fx.Opacity($("up-to-date"), {duration:500});
	ob_readmore = new fx.Opacity($("readmore"), {duration:500, onComplete: function(){
	}});
	
	start_effect();
}

function start_effect()
{
	ob_table.hide();
	ob_body_menu.hide();
	ob_v_stripe.hide();
	ob_text_block.hide();
	ob_main_text.hide();
	ob_small_text.hide();
	ob_secondary_menu.hide();
	ob_menu_block.hide();
	ob_page_title.hide();
	ob_uptodate.hide();
	ob_readmore.hide();
	step1();
}

function step1()
{
	ob_table.toggle();
	setTimeout("step2()", 1000);
}

function step2()
{
	ob_body_menu.custom(20, 313);
	ob_menu_block.custom(0, 177);		
	setTimeout("step3()", 500);
}

function step3()
{
	ob_v_stripe.custom(0, 313);
	ob_page_title.custom(0, 170);	
	setTimeout("step4()", 450);
}

function step4()
{
	ob_text_block.custom(0, 400);
	setTimeout("step5()", 600);
}

function step5()
{
	ob_uptodate.toggle();
}

function readmore_open()
{
	document.getElementById("flash").style.visibility = "hidden";
	document.getElementById("sound").style.visibility = "hidden";
	ob_readmore.custom(0, 0.8);
	setTimeout('readmore_text_show()', 800);

	document.getElementById("readmore").style.top = y;
	document.getElementById("readmore").style.left = x;		
}

function readmore_hide()
{	
	ob_readmore.toggle();
	document.getElementById("readmore_big_block").style.display = "none";
	setTimeout("flash_show()", 500);
}

function flash_show()
{
	document.getElementById("flash").style.visibility = "visible";
	document.getElementById("sound").style.visibility = "visible";
}

function readmore_text_show()
{
	document.getElementById("readmore_big_block").style.display = "block";

	if (document.getElementById)
	{
		var xx = (viewportwidth / 2) - (document.getElementById('readmore_big_block').offsetWidth / 2);
		var yy = (viewportheight / 2) - (document.getElementById('readmore_big_block').offsetHeight / 2);             
		//document.getElementById('readmore_big_block').style.top = yy;
		document.getElementById('readmore_big_block').style.left = xx;
	}
	else
	{

		var xx = (viewportwidth / 2) - (document.readmore_big_block.offsetWidth / 2);
		var yy = (viewportheight / 2) - (document.readmore_big_block.offsetHeight / 2);              
		//document.readmore_big_block.style.top = yy;
		document.readmore_big_block.style.left = xx;

	}

}

function menu_shift(id)
{
	link_id = id;
	pad = 0;
	start_shift();
}

function start_shift()
{    
	if(pad < 20)
	{
		pad = parseInt(pad);
		pad += 2;
		document.getElementById(link_id).style.paddingLeft = pad + "px";
		moveid2 = setTimeout("start_shift()", 1);
	}
}

function menu_shift_back()
{
	clearTimeout(moveid2);
	document.getElementById(link_id).style.paddingLeft = "0px";
}

function update_main_text(id)
{
	ob_main_text.hide();
	document.getElementById("main_text").scrollTop  = "0";
	document.getElementById("main_text").scrollLeft = "0";
	document.getElementById("text").innerHTML = document.getElementById("main_text_" + id).innerHTML;
	ob_main_text.toggle();
}	

function GetWindowSize()
{
	var size = new Array();
	var myWidth = 0, myHeight = 0;
	if (typeof( window.innerWidth ) == 'number')
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if (document.body && ( document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	size['width'] = myWidth;
	size['height'] = myHeight;
	
	return size;
}  

function contact_validator()
{
	var error = '';
	
	if (document.contact_form.name.value == "") error += 'Enter your name, please. <br>';
	if (document.contact_form.email.value == "") error += 'Enter e-mail name, please. <br>';
	if (document.contact_form.phone.value == "") error += 'Enter your phone, please. <br>';
	if (document.contact_form.message.value == "") error += 'Enter your message, please. <br>';
	if (!document.contact_form.phone.value.match('^([0-9\+-]+)$')) error += 'Incorrect phone! Re-enter, please. <br>';
	if (!document.contact_form.email.value.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$')) error += 'Incorrect email! Re-enter, please. <br>';
	if (error == '')
	{
		document.getElementById('error').innerHTML = '';
		document.contact_form.submit();
	}
	else document.getElementById('error').innerHTML = error;
}

function roll_out(id)
{
	if (document.images)
	{
		document.images['image_' + id].src = image[id].src;
	}	
}

function roll_over(id)
{
	if (document.images)
	{
		document.images['image_' + id].src = over_image[id].src;
	}
}

function menu_light(id)
{
	var menuElements = document.getElementsByClassName("active_link");
	for(var i = 0; i < menuElements.length; i++)
	{
		menuElements[i].className = "link";
	}
	document.getElementById("secondary_menu_link_" + id).className = "active_link";
}

var theObj="";

function toolTip(text,me) {
  theObj=me;
  theObj.onmousemove=updatePos;
  document.getElementById('toolTipBox').innerHTML=text;
  document.getElementById('toolTipBox').style.display="block";
  window.onscroll=updatePos;
}

function updatePos() {
  var ev=arguments[0]?arguments[0]:event;
  var x=ev.clientX;
  var y=ev.clientY;
  diffX=24;
  diffY=0;
  document.getElementById('toolTipBox').style.top  = y-2+diffY+document.body.scrollTop+ "px";
  document.getElementById('toolTipBox').style.left = x-2+diffX+document.body.scrollLeft+"px";
  theObj.onmouseout=hideMe;
}
function hideMe() {
  document.getElementById('toolTipBox').style.display="none";
}