var index_currentPhoto = -1;
var index_currentMenu = -1;
var index_currentSubmenu = -1;
var index_menuPrefix = 'nrg';
var menu = new Array (
  'about',
  'artist_programs',
  'workshops',
  'floating_images',
  'sunset_suppers',
  'venues',
  'calendar'
);

var preload_rollovers = new Array(
  index_menuPrefix+'_about_h.gif',
  index_menuPrefix+'_exhibitions_h.gif',
  index_menuPrefix+'_photographers_h.gif',
  index_menuPrefix+'_artist_programs_h.gif',
  index_menuPrefix+'_workshops_h.gif',
  index_menuPrefix+'_floating_images_h.gif',
  index_menuPrefix+'_sunset_suppers_h.gif',
  index_menuPrefix+'_venues_h.gif',
  index_menuPrefix+'_calendar_h.gif',
  index_menuPrefix+'_about.gif',
  index_menuPrefix+'_exhibitions.gif',
  index_menuPrefix+'_photographers.gif',
  index_menuPrefix+'_artist_programs.gif',
  index_menuPrefix+'_workshops.gif',
  index_menuPrefix+'_floating_images.gif',
  index_menuPrefix+'_sunset_suppers.gif',
  index_menuPrefix+'_venues.gif',
  index_menuPrefix+'_calendar.gif',
  'sm_bg_artistprogram.gif',
  'sm_bg_floatimage.gif',
  'sm_bg_sunset.gif',
  'sm_bg_workshop.gif'
);

function changeMenu(m_index) {
  this.setAttribute('src', base_url+'img/fl/'+index_menuPrefix+'_'+this.getAttribute('name')+'_h.gif');
}

function clearMenu(m_index) {
  var menu_index = indexInArray(menu, this.getAttribute('name'));
  if (menu_index != index_currentMenu) {
    this.setAttribute('src', base_url+'img/fl/'+index_menuPrefix+'_'+this.getAttribute('name')+'.gif')
  }
}

function menurollOver(el) {
  this.setAttribute('src', base_url+'img/fl/'+index_menuPrefix+'_'+this.getAttribute('name')+'_h.gif');
}

function menurollOut(el) {
  if (el.target.getAttribute('pos') != index_currentSubmenu) {
    this.setAttribute('src', base_url+'img/fl/'+index_menuPrefix+'_'+this.getAttribute('name')+'.gif')
  }
}

function transparencyOff(index) {
  this.setOpacity(1.0);
  this.addClass('sm_mouseover');
  if (this.id == 'sm_floating_images') {
    this.setStyle('background-image', 'url('+base_url+'img/fl/sm_bg_floatimage.gif)');
  }
  else if (this.id == 'sm_sunset_suppers') {
    this.setStyle('background-image', 'url('+base_url+'img/fl/sm_bg_sunset.gif)');
  }
  else if (this.id == 'sm_workshops') {
    this.setStyle('background-image', 'url('+base_url+'img/fl/sm_bg_workshop.gif)');
  }
  else {
    this.setStyle('background-image', 'url('+base_url+'img/fl/sm_bg_artistprogram.gif)');
  }
}

function transparencyOn(index) {
  this.setOpacity(0.5);
  this.removeClass('sm_mouseover');
  this.setStyle('background-image', 'none');
}

window.addEvent('domready', function(){
  $('footer').setOpacity(0.8);
//  $('header').setStyle('position', 'fixed');
//  $('menu').setStyle('position', 'fixed');
  if (index_currentMenu >= 0 && $('sub_menu_'+menu[index_currentMenu])) {
    $('sub_menu_'+menu[index_currentMenu]).setStyle('display', 'block');
  }
  $$('img.m_img').each(function(el) {
    el.addEvent('mouseenter', changeMenu);
    el.addEvent('mouseleave', clearMenu);
  });
  $$('img.sub_img').each(function(el) {
    el.addEvent('mouseenter', menurollOver);
    el.addEvent('mouseleave', menurollOut);
  });
  var i = 0;
  $$('div.sm_content').each(function(el) {
    el.setOpacity(0.5);
    el.addEvent('mouseenter', transparencyOff.bind(el, i));
    el.addEvent('mouseleave', transparencyOn.bind(el, i));
    i++;
  });
  $$('div.csm_content').each(function(el) {
    el.setOpacity(0.5);
    el.addEvent('mouseenter', transparencyOff.bind(el, i));
    el.addEvent('mouseleave', transparencyOn.bind(el, i));
    i++;
  });

  if ($('sm_calendar')) {
    $('sm_calendar').addEvent('mouseover', function(){this.setStyle('background-image','url('+base_url+'img/fl/'+index_menuPrefix+'_viewcalendar.gif)');});
    $('sm_calendar').addEvent('mouseleave', function(){this.setStyle('background-image','url('+base_url+'img/fl/'+index_menuPrefix+'_whatson.gif)');});
  }

  i = 0;
  preload_rollovers.each(function(img) {
    preload_rollovers[i] = new Image();
    preload_rollovers[i].src = base_url+'img/fl/'+img;
    i++;
  });
});

function indexInArray(theArray, theValue) {
  var arLength = theArray.length;
  for(var i=0; i<arLength; i++) {
    if (theArray[i] == theValue){
    return i;
    }
  }
  return -1;
}
