
function getBounds(element)
{
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft - parent.scrollLeft;
    top += parent.offsetTop - parent.scrollTop
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

function hide_all()
{
	all = document.all || document.getElementsByTagName( "*" );
	for( i = 0; i < all.length; i ++ )
	{
		if( all[i].className == 'sub_div' )
		{
			all[i].style.display = 'none';
		}
	}
}

function Prepare()
{
	all = document.all || document.getElementsByTagName( "*" );
	for( i = 0; i < all.length; i ++ )
	{
		
		if( all[i].className == 'menuitem' )
		{
			all[i].className = 'menuitem';
			
			elem = all[i].childNodes[0];
			
			elem.onmouseover = function(){ highlight(this); };
			elem.onmouseout = function(){ droplight(this); };
			
			z = all[i].getElementsByTagName('img')[0];

			if( z )
			{
				z.style.height = '9px';
				z.style.width = '9px';		
			}
		}
		
		if( all[i].className == 'sub_div' )
		{
			inn = all[i].innerHTML;
			all[i].innerHTML = '<div class="sub_sub">' + inn + '</div>';
			
			td = all[i].parentNode;
		
			bound = getBounds(td);
	
			all[i].style.top = (bound.top + bound.height - 2) + "px";
			all[i].style.left = (bound.left + 7) + "px";
			all[i].onmouseout = function(){ hidediv(this); };
			all[i].onmouseover = function(){ showdiv(this); };
			
			
		}
	}
}

function highlight(elem)
{
	all = document.all || document.getElementsByTagName( "*" );
	for( i = 0; i < all.length; i ++ )
	{
		if( all[i].className == 'sub_div' )
		{
			all[i].style.display = 'none';
		}
		
		if( all[i].className == 'menuhl' )
		{
			all[i].className = 'menuitem';
		}
		
		if( all[i].parentNode == elem.parentNode )
		{
			all[i].style.display = 'block';
			
			td = all[i].parentNode;
			bound = getBounds(td);
			all[i].style.top = (bound.top + bound.height - 2) + "px";
			all[i].style.left = (bound.left + 7) + "px";	
		}
	}

	elem.parentNode.className = 'menuhl';
}

function hidediv( elem )
{
	elem.style.display = 'none';
}
function showdiv( elem )
{
	elem.style.display = 'block';
}

function droplight(elem)
{
	td = elem.parentNode;
	td.className = 'menuitem';
}


	function ImageId( src )
	{
		var id = '';
		var pos = 0;
		var flag = true;

		while(true)
		{
				if( src.substring(pos, pos+1) == '_' )
				{
					break;
				}
					
				if( src.substring(pos, pos+1) == '/' )
					id = '';
				else
					id = id + src.substring(pos, pos+1);
					
				pos=pos+1;
		}
		return id;
	}

	function RImage()
	{
		var id = ImageId(document.getElementById('gal_img').src);
		ajax_get( '/gallery/_next.htm?id=' + id ,ImageSet);
	}

	function LImage()
	{
		var id = ImageId(document.getElementById('gal_img').src);
		ajax_get( '/gallery/_prev.htm?id=' + id ,ImageSet);
	}

	function ImageView()
	{
		var src = document.getElementById('gal_img').src;
		var id = '';
		var pos = 0;
		var flag = true;

		while(true)
		{
			if( src.substring(pos, pos+1) == '_' )
			{
				break;
			}			
			id = id + src.substring(pos, pos+1);	
			pos=pos+1;
		}

		window.open( id + '.jpg' );
	}
	
	var last_obj = false;

	var def_url = '/';

	var ajax = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  ajax = new ActiveXObject("Msxml2.XMLHttp");
} catch (e) {
  try {
    ajax = new ActiveXObject("Microsoft.XMLHttp");
  } catch (e2) {
    ajax = false;
  }
}
@end @*/

	if (!ajax) 
	{
	  ajax = new XMLHttpRequest();
	}
		if(!ajax) alert('ajax is not supported!');

	function check_state()
	{
		if(ajax.readyState == 4)
		{
			if(ajax.status == 200)
				return true;
			else
				alert('incorrect request');
				return false;
		}
	}

function ImageSet()
{
//	show_waiter();
	//alert(ajax.responseText);
	if(!check_state()) return;
	document.getElementById('gal_img').src = ajax.responseText;
//	hide_waiter();
}

function def_func() {};
	
function ajax_get( url , func )
{
	ajax.open('GET', url,true);
	ajax.onreadystatechange = func;
	ajax.send(null);		
}

function ajax_post( url, data, func )
{
	ajax.open( 'POST', url, true );
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	ajax.onreadystatechange = func;
	ajax.send( data );
}

function evalue( e_name )
{
	return encodeURI(value( e_name ));
}
