
function sectionSelected()
{
	if( typeof SECTION != 'undefined' && SECTION ) {
		var li_to_select = $( '#top-menu-' + SECTION );
		if( li_to_select.length > 0 ) {
			li_to_select.addClass( 'li-top-menu-selected' ).find('a').css('color', '#fff');
		}
	}
}

function fix_footer_position()
{
	var win_height = $( window ).height();
	var footer_top = $( '#footer' ).offset().top;
	var footer_height = $( '#footer' ).height();
	var img_height = ( win_height - footer_top - footer_height - 20 );
	if( img_height > 0 ) {
		$('#footer').prev().append('<img id="footer-fix" class="hidden" src="' + SITE_PATH + 'img/pixel.gif" alt="" />');
		$( '#footer-fix' ).css( 'height', img_height + 'px' ).css( 'width', '100%' ).show();
	}
}

function jQueryDocumentReady()
{
	$( 'a.external' ).click( openExternalLink );
	$('#a-show-hide-search').live('click',
		function( e ) {
			e.preventDefault();
			var search_container = $('#search-container');
			search_container.toggle();
			if( search_container.css('display') == 'none' ) {
				$( this ).text('APRI RICERCA');
			} else {
				$( this ).text('CHIUDI RICERCA');
			}
			$( this ).blur();
			return false;
		}
	);

	if( typeof open_search != 'undefined' ) {
		$('#search-container').show();
		$('#a-show-hide-search').text('CHIUDI RICERCA');
	}

	//setUpRolloverMenu();
	sectionSelected();
	moduleReady();
	fix_footer_position();
}

function moduleReady() {}

function setUpRolloverMenu()
{
	var content = $( '#ul-top-submenus' );
	if( content.length > 0 ) {
		var li_top = $( '.li-top-menu' );
		$( '#top-menu-bar' ).hover(
			function(){},
			function() {
				content.hide();
				li_top.removeClass( 'li-top-menu-selected' );
				sectionSelected();
			}
		);
		li_top.each(
			function() {
				var t = $( this );
				var p = t.parent();
				var i = t.attr( 'id' ).replace( 'top-menu-', '' );
				t.hover(
					function() {
						li_top.removeClass( 'li-top-menu-selected' );
						li_top.find('a').css('color', '#434343');
						t.addClass( 'li-top-menu-selected' ).find('a').css('color', '#fff');
						$( 'li.li-top-submenu', content ).hide();
						$( '#top-submenu-' + i, content ).show().hover(
							function() {
								t.find('a').css('color', '#fff');
							},
							function() {
								t.find('a').css('color', '#434343');
							}
						);
						$( content ).show();
					},
					function() {
						t.find('a').css('color', '#434343');
 					}
				);
			}
		);
	}
}

function openExternalLink()
{
	window.open( $( this ).attr( 'href' ) );
	return false;
}

$( document ).ready( jQueryDocumentReady );

