//////////////////////////////////////////////////////
function calculation()
{
	if ( $(document).height() < 650 )
	{
		$(document).height(650);
	}
	
	if ( $(document).width() < 1000 )
	{
		$(document).width(1000);
	}
	
	if ( $(document).height() == $(window).height() )
	{
		doc_height = $(window).height();
	}
	else
	{
		doc_height = $(document).height();
	}
	
	$('#wrapper').css("display", "");
	
	var empty_space		= 140;
	var wrapper_height	= doc_height - ($('#header').height() + $('#footer').height()) - empty_space;
	
	if ( wrapper_height < $('#carousel').height() )
	{
		wrapper_height = $('#carousel').height();
	}
	
	var wrapper_top 	= Math.ceil((wrapper_height + empty_space - wrapper_height - 20) / 2);
	var wrapper_left 	= Math.ceil(($('#content').width() / 2) - ($('#wrapper').width() / 2));
	
	//alert($(document).width() + '\n' + $('#wrapper').width() + '\n' + margin_left);
	//alert(doc_height + '\n' + wrapper_height + '\n' + wrapper_top + '\n' + wrapper_left);
	
	$('#wrapper').css(
		{
			"top" 		: wrapper_top, 
			"left" 		: wrapper_left, 
			"height"	: wrapper_height
		}
	);
	
	$('#v_line').css(
		{
			"top" 		: 0, 
			"height"	: $('#wrapper2').height()
		}
	);
	
	if ( ($(document).height() == $(window).height()) && ($('#wrapper2').height() < (wrapper_height + empty_space)) )
	{
		$('#footer').css("position", "absolute");
	}
	else
	{
		$("#footer").css("position", "relative");
	}
}


//////////////////////////////////////////////////////
function setPosition(flag)
{
	var inter			= 0;
	var millisecond		= 0;
	
	try
	{
		if ( flag != undefined )
		{
			millisecond = 100;
			
			inter = setTimeout(
				function()
				{
					calculation();
					$('#carousel').css('top', ($("#wrapper").height() - parseInt($('#carousel').css("height"))) / 2);
				}, 
				millisecond
			);
		}
		else
		{
			calculation();
		}
	}
	catch ( error )
	{
		alert(err.description);
	}
}


//////////////////////////////////////////////////////
var g_load_flag_m = 0;
var g_load_flag_l = 0;

function mainMenuPosition()
{
	var inter 			= 0;
	var millisecond		= 200;
	
	if ( g_load_flag_m == 0 )
	{
		g_load_flag_m = 1;
		
		$('#menu_top').css("left", -$('#menu_top').width());
	}
	
	inter = setTimeout(
		function()
		{
			if ( $(document).width() == $(window).width() )
			{
				doc_width = $(document).width();
			}
			else
			{
				doc_width = $(window).width();
			}
			
			var lang_pos_left	= 28; //width flag image + position left
			var menu_place_size = doc_width - ( parseInt($('#logo_ags').css('right')) + $('#logo_ags').width() ) - lang_pos_left;
			var menu_left		= Math.ceil((menu_place_size - $('#menu_top').width()) / 2) + lang_pos_left; ////$('#wrapper2').getOffset().left + 20;
			
			//alert(doc_width + '\n' + $('#logo_ags').css('right') + '\n' + $('#logo_ags').width());
			//alert(menu_place_size + '\n' + $('#menu_top').width() + '\n' + lang_pos_left);
		
			$('#menu_top').animate(
				{
					left : menu_left
				}, 
				"slow", 
				function()
				{
					var int = setTimeout(
						function()
						{
							$('#menu_ags span').css(
								{
									"background-image"		: "url(img/lighting_menu.png)",
									"background-position" 	: "bottom center",
									"background-repeat"		: "no-repeat"
								}
							);
						},
						50
					);
				}
			);
		}, 
		millisecond
	);
}


//////////////////////////////////////////////////////
function leftMenuPosition()
{
	var inter 			= 0;
	var millisecond		= 400;
	
	if ( g_load_flag_l == 0 )
	{
		//var menu_top 	= $('#menu_left').height() + ($('#menu_left').getOffset().top - $('#header').height());
		var menu_top 	= $('#menu_left').getOffset().top + $('#menu_left').height();

		g_load_flag_l 	= 1;
		
		$('#menu_left').css("top", -menu_top);
	}
	
	inter = setTimeout(
		function()
		{
			if ( $(document).width() == $(window).width() )
			{
				doc_width = $(document).width();
			}
			else
			{
				doc_width = $(window).width();
			}

			$('#menu_left').animate(
				{
					top : 0
				}, 
				"slow",
				function()
				{
					var int = setTimeout(
						function()
						{
							//$(".current_ml").css(
//								{
//									"background-image"		: "url(img/lighting_menu_left.png)",
//									"background-position" 	: "top right",
//									"background-repeat"		: "no-repeat"
//								}
//							);
							
							$('#menu_left a').removeClass("temp_current");
							$('#menu_left a:first').addClass("current_ml");
						},
						100
					);
				}
			);
		}, 
		millisecond
	);
}

