var prompt;
var prTimer = null;
var promptId;

function addH(id) {
	var obj = document.getElementById( id );
	if(obj == null) return false;
	obj.className = "prompt hidden";
	if( document.all) $('select').css('visibility','visible');
}

$(function() {

	if ( !$.browser.safari )
	{	$('#f-input input').val('?????').css({color: '#A7A7A3'});
		$('#f-input input').focus(function(){
			var val = $(this).val();
			if ( val == '?????')
				$(this).val('').css({color: '#000'});
		});
		$('#f-input input').blur(function(){
			var val = $(this).val();
			if ( val == '')
				$(this).val('?????').css({color: '#A7A7A3'});
		});
	}

	$(document).keydown(function(e){
		//if (window.event) e = window.e;
		if ( window.location.pathname == '/' ) return true;
		if (e.ctrlKey)
		{	var href = null;
			var loc = window.location.pathname;
			var locArr = loc.split('/');
			var prevLevel = '/';
			if ( locArr.length > 1 )
			{	locArr.pop();
				locArr.pop();
				prevLevel = locArr.join('/') + '/'; 
			}
			//alert(prevLevel);
			switch (e.keyCode ? e.keyCode : e.which ? e.which : null)
			{
				case  38:
					href = prevLevel;
					break;
				case 36:
					href = '/';
					break;
			}
			if (href) window.location.href = href;
		}
	});

	$('.pr-wrap').hover(
		function () {
			$('.prompt').addClass('hidden');
			if( prTimer != null)
			{	clearTimeout( prTimer );
				prTimer = null;
			}
			
			var offset = $(this).offset();
			prompt = $('#pr-' + $(this).attr('id'));
			promptId = prompt.attr('id');
			prompt.removeClass('hidden');
			prompt.css({
				top: offset.top + $(this).height() + 5 + 'px',
				left: offset.left + 'px'
			});
			
			if( document.all) 
			{	//$('select').css('visibility','inherit');
				var selects = $('select');
				for (i = 0; i < selects.length; i++)
				{	var select = selects.eq(i);
					var offsetSelect = select.offset();
					var PX1 = offset.left;
					var PX2 = offset.left + prompt.width() + 22;
					var PY1 = offset.top + $(this).height() + 5;
					var PY2 = offset.top + $(this).height() + 5 + prompt.height();
					//alert(PX1 + ';' + PX2 + '; = ;' + PY1 + ';' + PY2);
					
					var SX1 = offsetSelect.left;
					var SX2 = offsetSelect.left + select.width();
					var SY1 = offsetSelect.top;
					var SY2 = offsetSelect.top + select.height();
					//alert(SX1 + ';' + SX2 + '; = ;' + SY1 + ';' + SY2);
					
					if (	(PX1 < SX2) && (PX2 > SX1) && (PY1 < SY2) && (PY2 > SY1) ) 
					{	select.css('visibility', 'hidden');
					}
				}
			}
		},
		function () 
		{	prTimer = setTimeout( "addH( promptId )", 200 );	}
	);

	$('.prompt').hover(
		function () 
		{	if( prTimer != null)
			{	clearTimeout( prTimer );
				prTimer = null;
			}
		},
		function () 
		{	$(this).addClass('hidden');
			if( document.all) $('select').css('visibility','visible');
		}
	);
});
