function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

/*
var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		menu_basys08_02_over = newImage("images/menu_basys08_02-over.gif");
		menu_basys08_04_over = newImage("images/menu_basys08_04-over.gif");
		menu_basys08_06_over = newImage("images/menu_basys08_06-over.gif");
		menu_basys08_08_over = newImage("images/menu_basys08_08-over.gif");
		menu_basys08_10_over = newImage("images/menu_basys08_10-over.gif");
		menu_basys08_12_over = newImage("images/menu_basys08_12-over.gif");
		menu_basys08_14_over = newImage("images/menu_basys08_14-over.gif");
		preloadFlag = true;
	}
}
*/

 // hostname - paginas.fe.up.pt or www.basysconference.org

 //alert(" DEBUG: location: '"+window.location.pathname+"' ");
 _base_pages_ = ['index.html', 'main.html', 'shortcuts.html', 'papers_form.html', 'papers_form.php', ''];
 _is_this_base_page_ = false;
 if ( window.location.pathname.indexOf(_base_pages_[0]) != -1 )
	 _is_this_base_page_ = true;
 if ( window.location.pathname.indexOf(_base_pages_[1]) != -1 )
	 _is_this_base_page_ = true;
 if ( window.location.pathname.indexOf(_base_pages_[2]) != -1 )
	 _is_this_base_page_ = true;
 if ( window.location.pathname.indexOf(_base_pages_[3]) != -1 )
	 _is_this_base_page_ = true;
 if ( window.location.pathname.indexOf(_base_pages_[4]) != -1 )
	 _is_this_base_page_ = true;
 // case ''
 if ( (window.location.pathname.indexOf('.html') == -1) &&
      (window.location.pathname.indexOf('.php') == -1) )
	 _is_this_base_page_ = true;

 //alert(" DEBUG: _is_this_base_page_: '"+_is_this_base_page_+"' ");

 //alert(" DEBUG: url: '"+this.url+"' ");

// Estrutura menus
var _menus_ = { 
		0 : ['menu_basys_home', 'index.html',
			[ ]
			],
		1 : ['menu_basys_call', '', //'calls.html',
			[ ['dropmenu_basys08_19', 'calls_submissions/papers.html'],
			  ['dropmenu_basys08_22', 'calls_submissions/submissions.html']
			  //['dropmenu_basys08_25', 'calls_submissions/participations.html']
			]
			],
		2 : ['menu_basys_conference', '', //Conference
			[ ['dropmenu_basys08_05', 'conference/news.html'],
			  ['dropmenu_basys08_55', 'conference/dates.html'],
			  ['dropmenu_basys08_56', 'conference/keynotes.html'],
			  ['dropmenu_basys08_13', 'conference/commitiees.html'],
			  ['dropmenu_basys08_16', 'conference/sponsors.html']
			]
			],
		3 : ['menu_basys_registration', 'registration/registration.html',
			[ ]
			],
		4 : ['menu_basys_programme', 'programme/programme.html',
			[ ]
			],
		5 : ['menu_basys_local_info', '', // 
			[ ['dropmenu_basys08_42', 'local_information/venue.html'],
			  ['dropmenu_basys08_48', 'local_information/porto.html'],
			  ['dropmenu_basys08_51', 'local_information/accomodations.html'],
			  ['dropmenu_basys08_54', 'local_information/attractions.html']
			]
			],
		6 : ['menu_basys_contacts', 'main/contacts.html',
			[ ]
			],
		7 : [''],
		8 : ['']
		};

$(document).ready(function() {
   /*
   $("#teste").click(function() {
     alert("Hello world!");
   });*/

	_add_str_ = '';
	if (!_is_this_base_page_)
		_add_str_ = '../';

   _img_bottons_base_dir_ = _add_str_+'images/bottons/';
   _img_sub_menus_bottons_base_dir_ = _add_str_+'images/bottons/sub_menus/';

	_opened_menu_ = null;

   $("#Menu-itens > li strong").each(function(i) {
		_elem_ = _menus_[i];
		_img_path_normal_ = _img_bottons_base_dir_ + _elem_[0]+'.gif';
		_img_path_over_   = _img_bottons_base_dir_ + _elem_[0]+'-over.gif';
		if ( _elem_[1] != '' )
		{
			_html_str_ = '<a href="'+_add_str_+_elem_[1]+'" ><img src="'+_img_path_normal_+'" border="0" /></a>';
		} else {
			_html_str_ = '<img src="'+_img_path_normal_+'" border="0" />';
		}
		// preload images
		_temp_img_ = newImage(_img_path_normal_);
		_temp_img_ = newImage(_img_path_over_);
		$(this).html(_html_str_).hover(
			  function () {
				_img_elem_ = $(this).find('img:first');
				_img_src_ = _img_elem_.attr('src');
				_img_src_ = _img_src_.replace('.gif', '-over.gif');
				_img_elem_.attr('src', _img_src_);
				if ( _opened_menu_ != null )
					_opened_menu_.hide();
				_opened_menu_ = $(this).parent().find('.sub-Menu');
				_opened_menu_.show();
			  }, 
			  function () {
				_img_elem_ = $(this).find('img:first');
				_img_src_ = _img_elem_.attr('src');
				_img_src_ = _img_src_.replace('-over.gif', '.gif');
				_img_elem_.attr('src', _img_src_);
				//$(this).parent().find('.sub-Menu').hide();
			  }
			);
   });

   $("#Menu-itens .sub-Menu").each(function(i) {

		_elem_ = _menus_[i][2];

		$(this).find("li").each(function(i2) {
			//dropmenu_basys08_02.gif
			//alert(" DEBUG:: i = '"+i+"'; '"+_elem_[i2]+"'");
			//_add_str_ = '';
			//if (!_is_this_base_page_)
			//	_add_str_ = '../';
			_img_path_normal_ = _img_sub_menus_bottons_base_dir_+_elem_[i2][0]+'.gif';
			_img_path_over_   = _img_bottons_base_dir_ + _elem_[i2][0]+'-over.gif';
			_html_str_ = '<a href="'+_add_str_+_elem_[i2][1]+'" ><img src="'+_img_path_normal_+'" border="0" /></a>';

			// preload images
			_temp_img_ = newImage(_img_path_normal_);
			_temp_img_ = newImage(_img_path_over_);

			$(this).html(_html_str_).hover(
				  function () {
					_img_elem_ = $(this).find('img:first');
					_img_src_ = _img_elem_.attr('src');
					_img_src_ = _img_src_.replace('.gif', '-over.gif');
					_img_elem_.attr('src', _img_src_);
				  }, 
				  function () {
					_img_elem_ = $(this).find('img:first');
					_img_src_ = _img_elem_.attr('src');
					_img_src_ = _img_src_.replace('-over.gif', '.gif');
					_img_elem_.attr('src', _img_src_);
				  }
				);
			//$(this).html(' terte ('+i2+')');
		});

		$(this).hover(
			  function () {
				_i = 1;
			  }, 
			  function () {
				$(this).hide();
				_opened_menu_ = null;
			  }
			);
   });


 });

