//*************************************************
//                Top menu functions
//*************************************************
var canCloseMenu = new Array;
var topSubMenus = ['about', 'news', 'service', 'clients', 'team'];
function showTopSubMenu(id)
{
	if ($('top_sub_menu_'+id))
	{
		var menu_position = $('top_menu_image_'+id).positionedOffset();
		$('top_sub_menu_'+id).style.left = menu_position.left+'px';
		$('top_sub_menu_'+id).style.top = menu_position.top+24+'px';
		canCloseMenu['top_sub_menu_'+id] = false;
		if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
		{
			topSubMenus.each(function(name){
				$('top_menu_image_'+name).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/top_menu_en/'+name+'.png' + "',sizingMethod='crop')";
				$('top_sub_menu_'+name).hide();
			});
			$('top_menu_image_'+id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/top_menu_en/'+id+'_hover.png' + "',sizingMethod='crop')";
		}
		else
		{
			topSubMenus.each(function(name){
				$('top_menu_image_'+name).src = '/images/top_menu_en/'+name+'.png';
				$('top_sub_menu_'+name).hide();
			});
			$('top_menu_image_'+id).src = '/images/top_menu_en/'+id+'_hover.png';
		}
		$('top_sub_menu_'+id).show();
	}
	else
	{
		if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
		{
			topSubMenus.each(function(name){
				$('top_menu_image_'+name).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/top_menu_en/'+name+'.png' + "',sizingMethod='crop')";
				$('top_sub_menu_'+name).hide();
			});
			$('top_menu_image_'+id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/top_menu_en/'+id+'_hover.png' + "',sizingMethod='crop')";
		}
		else
		{
			topSubMenus.each(function(name){
				$('top_menu_image_'+name).src = '/images/top_menu_en/'+name+'.png';
				$('top_sub_menu_'+name).hide();
			});
			$('top_menu_image_'+id).src = '/images/top_menu_en/'+id+'_hover.png';
		}
	}
}
function hideTopSubMenu(id)
{
	if ($('top_sub_menu_'+id))
	{
		canCloseMenu['top_sub_menu_'+id] = true;
		setTimeout("closeTopSubMenu('"+id+"')",400);
	}
	else
	{
		if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
		{
			$('top_menu_image_'+id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/top_menu_en/'+id+'.png' + "',sizingMethod='crop')";
		}
		else
		{
			$('top_menu_image_'+id).src = '/images/top_menu_en/'+id+'.png';
		}
	}
}
function closeTopSubMenu(id)
{
	if ($('top_sub_menu_'+id))
	{
		if (canCloseMenu['top_sub_menu_'+id])
		{
			canCloseMenu['top_sub_menu_'+id] = false;
			if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
			{
				$('top_menu_image_'+id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/top_menu_en/'+id+'.png' + "',sizingMethod='crop')";
			}
			else
			{
				$('top_menu_image_'+id).src = '/images/top_menu_en/'+id+'.png';
			}
			$('top_sub_menu_'+id).hide();
		}
	}
}
function topMenuMouseOver(id)
{
	canCloseMenu['top_sub_menu_'+id] = false;
}

//*************************************************
//                Top tabs functions
//*************************************************

function topTabMouseOver(id)
{
	$('tab_content_'+id).removeClassName('tab');
	$('tab_link_'+id).removeClassName('tab');
	$('tab_content_'+id).addClassName('active_tab');
	$('tab_link_'+id).addClassName('active_tab');
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		$('tab_left_'+id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/header/active_tab_left.png' + "',sizingMethod='crop')";
		$('tab_right_'+id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/header/active_tab_right.png' + "',sizingMethod='crop')";
	}
	else
	{
		$('tab_left_'+id).removeClassName('tab_left');
		$('tab_right_'+id).removeClassName('tab_right');
		$('tab_left_'+id).addClassName('active_tab_left');
		$('tab_right_'+id).addClassName('active_tab_right');
	}
	if ($('blog_calendar_button'))
	{
		$('blog_calendar_button').absolutize();
	}
}
function topTabMouseOut(id)
{
	$('tab_content_'+id).removeClassName('active_tab');
	$('tab_link_'+id).removeClassName('active_tab');
	$('tab_content_'+id).addClassName('tab');
	$('tab_link_'+id).addClassName('tab');
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		$('tab_left_'+id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/header/tab_left.png' + "',sizingMethod='crop')";
		$('tab_right_'+id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + '/images/header/tab_right.png' + "',sizingMethod='crop')";
	}
	else
	{
		$('tab_left_'+id).removeClassName('active_tab_left');
		$('tab_right_'+id).removeClassName('active_tab_right');
		$('tab_left_'+id).addClassName('tab_left');
		$('tab_right_'+id).addClassName('tab_right');
	}
	if ($('blog_calendar_button'))
	{
		$('blog_calendar_button').absolutize();
	}
}

//*************************************************
//                Dom functions
//*************************************************

function Viewport()
{
	this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;
	this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
	this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
	this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
	this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
	this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
	return this;
}

function corectCss()
{
	$('body_bottom_left_image').style.top = Viewport().pageY - $('body_bottom_left_image').getHeight() + 'px';
	if (Prototype.Browser.IE)
	{
		$('body_top_center_image').style.left = ( Viewport().pageX - 18 - $('body_top_center_image').getWidth() ) / 2 + 'px';
	}
	if ($('header_image'))
	{
		var pos = $('top_right_image_position').positionedOffset();
		$('header_image').style.top = (pos.top-32)+'px';
		$('header_image').style.left = (pos.left-70)+'px';
		$('header_image').show();
	}
	if ($('contact_header_image'))
	{
		var pos = $('top_right_image_position').positionedOffset();
		$('contact_header_image').style.top = (pos.top-15)+'px';
		$('contact_header_image').style.left = (pos.left+15)+'px';
		$('contact_header_image').show();
	}
	if ($('customers_header_image'))
	{
		var pos = $('top_right_image_position').positionedOffset();
		$('customers_header_image').style.top = (pos.top-47)+'px';
		$('customers_header_image').style.left = (pos.left+15)+'px';
		$('customers_header_image').show();
	}
	if ($('responses_header_image'))
	{
		var pos = $('top_right_image_position').positionedOffset();
		$('responses_header_image').style.top = (pos.top-15)+'px';
		$('responses_header_image').style.left = (pos.left)+'px';
		$('responses_header_image').show();
	}
	if ($('programs_list_image'))
	{
		var pos = $('programs_list_image_position').positionedOffset();
		$('programs_list_image').style.top = (pos.top-107)+'px';
		$('programs_list_image').style.left = (pos.left-87)+'px';
		$('programs_list_image').show();
	}
}

document.observe('dom:loaded',function() {
	corectCss();
})
Event.observe(window, 'resize', function() {
	corectCss();
});