var gsdi = {
	sendForm: function( f, callback )
	{
		var cb		= typeof( callback ) == 'function' ? callback : (function(e,s) { 
			f.innerHTML = '<div style="padding-top: 4px">'+e.responseText+'</div>';
		});
		var action 	= f.action;
		var method	= typeof( f.method ) == 'string' && f.method != '' ? f.method : 'post';
		var data 	= Form.serialize( f );
		var newAJAX = new Ajax.Request( action, { 
				method: 	method, 
				postBody: 	data, 
				onComplete: cb
			});
		return false;
	}
	
};

function showOnly( id )
{
	
	resetElements( 'cat_'+id );
	$('licat_'+id).className = 'selected';
	/*
	var except 	= exceptElement || '';
	var show	= showStyle || '';
	var elms 	= $$(className);
	elms.each( function( a, b ) { 
		if ( exceptElement != '' && a.id == exceptElement )
		{
			a.style.display = show;
		}
		else {
			a.style.display = 'none';
		}
	})
	*/
}
var $catName	= '';
Event.observe(window, 'load', initSlide, false);

var $maxcar	= 100;
var $maxcnt	= 0;
var $total 	= 0;
var $disp	= 4;
var	$offset	= 0;

function _hideNextSep( e )
{
	var n = e.nextSibling;
	if ( n && n.nodeType == 3 ) n = n.nextSibling;
	if ( n && n.className == 'submenu-sep' )
	{
		Element.hide( n );
	}
}
function _hidePreviousSep( e )
{
	var n = e.previousSibling;
	if ( n && n.nodeType == 3 ) n = n.previousSibling;
	if ( n && n.className == 'submenu-sep' )
	{
		Element.hide( n );
	}
}
function _showNextSep( e )
{
	var n = e.nextSibling;
	if ( n && n.nodeType == 3 ) n = n.nextSibling;
	if ( n && n.className == 'submenu-sep' )
	{
		Element.show( n );
	}
}
function _showPreviousSep( e )
{
	var n = e.previousSibling;
	if ( n && n.nodeType == 3 ) n = n.previousSibling;
	if ( n && n.className == 'submenu-sep' )
	{
		Element.show( n );
	}
}

function initSlide() {
	
	/*
	//resetElements( '.submenu-data' );
	hideAll( "submenu-data" );
	
	Event.observe( $('btScrollLeft'), 'click', moveLeft, false);
	Event.observe( $('btScrollLeft'), 'mouseover', function(e) { 
		$('btScrollLeft').addClassName("btScrollLeft-hover");
	}, false);
	Event.observe( $('btScrollLeft'), 'mouseout', function(e) { 
		$('btScrollLeft').removeClassName("btScrollLeft-hover");
	}, false);
	
	Event.observe( $('btScrollRight'), 'click', moveRight, false);
	Event.observe( $('btScrollRight'), 'mouseover', function(e) { 
		$('btScrollRight').addClassName("btScrollRight-hover");
	}, false);
	Event.observe( $('btScrollRight'), 'mouseout', function(e) { 
		$('btScrollRight').removeClassName("btScrollRight-hover");
	}, false);
	
	$('btScrollLeft').hide();
	$('btScrollRight').hide();
	*/
	
	if ( typeof( init ) == 'function' )
	{
		init();
	}
}

function hideAll( cName )
{
	var elms = $$( "."+cName );
	elms.each( function(e){
		Element.hide(e);
		_hideNextSep( e );
	})
	$('submenu-loading').style.display = "none";
	$('submenu-content').style.display = "block";
}

function resetElements( cName )
{
	if ( $catName != '' )
	{
		hideAll( $catName );
	}
	var elms = $$( "."+cName );
	$total 		= 0;
	$maxcnt		= 0;
	$disp		= 0;
	$offset		= 0;
	$catName = cName;
	$last	= null;
	elms.each( function(e){
		if ( $maxcnt < $maxcar )
		{
			var ec = e.firstChild;
			if ( typeof( ec.tagName ) == 'undefined' )
				ec = ec.nextSibling;
			if ( $maxcar > ( $maxcnt + ec.innerHTML.length ) )
			{
				Element.show(e);
				_showNextSep( e );
				$maxcnt += ec.innerHTML.length;
				$disp++;
			}
			else {
				_hidePreviousSep( e );
			}
		}
		else {
			
			Element.hide(e);
			_hideNextSep( e );
		}
		/*
		if ( $total >= $disp )
		{
			if( $total == $disp )
				_hidePreviousSep( e );
			
			Element.hide(e);
			
			_hideNextSep( e );
			
		}
		else {
			Element.show(e);
			_showNextSep( e );
		}
		*/
		$last = e;
		$total++;
		
	})
	_hideNextSep( $last );
	
	$('btScrollLeft').hide();
	if ( $total > $disp )
	{
		$('btScrollRight').show();
	}
	else
	{
		$('btScrollRight').hide();
	}
}

function moveLeft(e) {
	
	if ( $offset != 0 )
	{
		$offset--;
		var elms = $$( "."+$catName );
		var $step	 = 0;
		elms.each( function(e){
			if ( $step >= $offset && $step < $offset+$disp )
			{
				if ( !e.visible() )
					Element.show( e );
				if( $step == $offset )
					_hidePreviousSep( e );
				if ( $step < ($offset+$disp-1) )
					_showNextSep( e );
			}
			else 
			{
				Element.hide( e );
				if ( $step == ($offset+$disp) )
					_hidePreviousSep( e );
				_hideNextSep( e );
			}
			$step++;
		})
	}
	
	if ( $offset == 0 )
		$('btScrollLeft').hide();
	if ( $offset > 0 && $step < $offset+$disp )
		$('btScrollRight').hide();
	else
		$('btScrollRight').show();
}
function moveRight(e) {
	if ( ( $offset + $disp ) < $total )
	{
		$offset++;
		var elms = $$( "."+$catName );
		var $step	 = 0;
		elms.each( function(e){
			if ( $step >= $offset && $step < $offset+$disp )
			{
				if ( !e.visible() )
					Element.show( e );
				if( $step == $offset )
					_hidePreviousSep( e );
				if ( $step < ($offset+$disp-1) )
					_showNextSep( e );
			}
			else {
				Element.hide( e );
				_hideNextSep( e );
			}
			$step++;
		})
		if ( ( $offset + $disp ) == $total )
		{
			$('btScrollRight').hide();
		}
	}
	if ( $offset > 0 )
		$('btScrollLeft').show();
	else
		$('btScrollLeft').hide();
}