function getOffsetPosition($obj)
{
	var $top	= 0;
	var $left	= 0;
	
	do
	{
		$top	+= $obj.offsetTop;
		$left	+= $obj.offsetLeft;
	}
	while($obj = $obj.offsetParent);
	return {top: $top, left: $left};
}

function toggleNews($id)
{
	var $s = $($id).style;
	$s.display = ($s.display != 'block')
		? 'block'
		: 'none';
}

function getURL($link)
{
	window.location = $link;
}

function getScreenSize()
{
	var $w = 0;
	var $h = 0;
	
	if(document.body.offsetWidth && document.body.offsetHeight)
	{
		$w = document.body.offsetWidth;
		$h = document.body.offsetHeight;
	}
	else if(document.body.clientWidth && document.body.clientHeight)
	{
		$w = document.body.clientWidth;
		$h = document.body.clientHeight;
	}
	else
	{
		$w = window.innerWidth;
		$h = window.innerHeight;
	}
	return ($w != 0 && $h != 0) ? {width: $w, height: $h} : false;
}

function resizeScreen(onLoad)
{
	var $screen = getScreenSize();
	if($screen.width > 1000)
	{
		//if(!onLoad) window.location = window.location;
	}
	else
	{
		$('wrapper').style.overflow		= 'hidden';
		//$('wrapper').style.width		= '1000px';
		document.body.style.overflowX	= ($screen.width < 999)
			? 'scroll'
			: 'hidden';
	}
}

function highlightOver($target, $bgImage)
{
	$target = $($target);
	$target.className = 'holder_over';
	$target.style.backgroundImage = 'url('+ $bgImage +')';
//	$target.style.display = 'block';
}

function highlightOut($target)
{
	$target = $($target);
	$target.className = 'holder';
	$target.style.backgroundImage = 'none';
//	$target.style.display = 'none';
}

function comingEventOver($target, $bgImage)
{
	$target = $($target);
	$target.className = 'coming_event_over';
	$target.style.backgroundImage = 'url('+ $bgImage +')';
}

function comingEventOut($target)
{
	$target = $($target);
	$target.className = '';
	$target.style.backgroundImage = '';
}

function displayImage($caller, $thumb, $image, $type)
{
	var $timeout;
	var $items	= '';
	var $offset	= getOffsetPosition($caller);
	
	var $thumb = '<img src="'+ $thumb +'" />';
	
	if($type == 'horizontal')
	{
		 $('enlargement_vertical').style.display = 'none';
		
		var $holder = $('enlargement_horizontal');
		
		$holder.style.top	= $offset.top - 43 +'px';
		$holder.style.left	= $offset.left - 67 +'px';
	}
	else
	{
		$('enlargement_horizontal').style.display = 'none';
		
		var $holder = $('enlargement_vertical');
			
		$holder.style.top	= $offset.top - 64 +'px';
		$holder.style.left	= $offset.left - 46 +'px';
	}
	
	$holder.style.display = 'block';
	$holder.innerHTML = $thumb;	
	$holder.title = 'Click to view large version';
	
	$holder.onclick = function()
	{
		clearTimeout($timeout);
		window.open($image, '', 'fullscreen');
		$holder.style.display = 'none';
	};
	
	var hide = function()
	{
		$holder.style.display = 'none';
	};
	$timeout = setTimeout(hide, 5000);
}

function displayWallpaper($caller, $thumb, $wallpapers)
{
	var $items	= '';
	var $offset	= getOffsetPosition($caller);
	
	for(var $k in $wallpapers)
	{
		var $wallpaper = $wallpapers[$k];
		$items += '<a href="'+ $wallpaper +'" target="_blank">'+ $k +' > download</a>';
	}
	
	$('enlargement_menu').innerHTML			= $items;
	$('enlargement_wallpaper').innerHTML	= '<img src="'+ $thumb +'" />';
	
	var $holder = $('enlargement');
		$holder.style.display = 'block';
		$holder.style.top	= $offset.top - 43 +'px';
		$holder.style.left	= $offset.left - 67 +'px';
		
		$holder.onclick = function()
		{
			$holder.style.display = 'none';
		};
}

function selectClassicYacht($select)
{
	document.location = $select.value;
}

var $currentAgent;
function displayWorldwide($id)
{
	if($id != $currentAgent)
	{
		$currentAgent = $id;
		var $params =
		{
			agent_id: $id
		};
		
		new Ajax.Request('/actions/get_agent.php',
		{
			method:		'post',
			parameters:	$params,
			
			onSuccess:	function(ajax)
			{
				$('text').innerHTML = ajax.responseText +'<br />';
			}
		});
	}
}

/*var debug = function($msg)
{
	var $d = $('debug');
	if($d.style.display != 'block')
	{
		$d.style.display = 'block';
	}
	$d.innerHTML = $msg +'<br>'+ $('debug').innerHTML;
};

var trace = function()
{
	var $alert = '';
	var $iL = (arguments.length - 1);
	for(var $i=0; $i<=$iL; $i++)
	{
		$alert += arguments[$i];
		if($i < $iL) $alert += ', ';
	}
	alert($alert);
};*/

function show_lost_pass()
{
	$('lostpass').toggle();
}
