var menuStack = ['past_forums','speakers','videos','presentations','opinions'];
for(i in menuStack) (new Image).src = 'images/' + menuStack[i] + '_menu.png';

var pageStack = ['profile','past_forums','speakers','videos','presentations','opinions','resources','contact'];
var currentPage = null;

$(document).ready(function(){
  $('#nav > li').bind('mouseover', navOpen);
  $('#nav > li').bind('mouseout',  navTimer);
  $('#theYear').html((new Date).getFullYear());
  
  try {
    var min = slideShow.length > 4 ? 5 : slideShow.length;
    for(i=0;i<min;i++){
      preloadImage(i);
    }
    $('#controls div img').css('opacity',.7);
    $('#controls div img').hover(controlOver,controlOut);
  } catch(e) {
    ;
  }

  try {
    buildSlideShow(); // in head of any page with a slide show — var slide_show = {path:"/images/path_to_slides/",length:number_of_slides,varies:BOOLEAN(do the pics vary in size?)}
  } catch(e){
    ;
  }

  // *********  here we accommodate IE
  if($.browser.msie){
    document.onclick = function(){
      var str = (window.event.srcElement).toString();
      if(str.charAt(str.length-1) == '#'){
        return false;
      } else {
        navClose();
      }
    };
    $('#darkScreen').css('opacity',.8);
  //   $('#blog').css('height','18px');
  //   $('#join').css('height','23px');
  //   $('.primary_nav').css('height','19px');
  //   $('#right_column_small').css('margin-top','1px');
  //   $('.subnav a').css('height','24px');
  //   $('.subnavDouble a').css('height','36px');
  //   $('.secondary').css('height','14px');
  //   $('.secondaryDouble').css('height','24px');
  //   $('#home_content_list').css('top','155px');
  //   $('#home_sponsors').css({'margin-right':'57px'});
  //   $('#miceType').css({'left':380,'text-align':'center'});
  //   $('#miceType_menu li a, #about_sponsors').css('height','17px');
  //   $('#blog, #join, .primary_nav, .subnav a, .subnavDouble a, .secondary_nav li a, .secondary, .secondaryDouble, #miceType_menu li a, #about_sponsors').css('padding-top','0px');
  //   $('#blog, #join, .primary_nav, .subnav a, .subnavDouble a, .secondary_nav li a, .secondary, .secondaryDouble, #miceType_menu li a, #about_sponsors').each(function (){
  //     if(this.href.charAt(this.href.length-1) != '#'){
  //       $(this).attr('title',$(this).html());
  //     }
  //     $(this).empty();
  //     
  //     $('#home_content').css('top','0px');
  //     $('#home_right').css('right','48px');
  //     $('#home_footer').css('margin-top','0px');
  //     $('#news').css({'width':'326px','height':'317px'});
  //     
  //   });
  // } else {
  //   if($('#left_column').height() > $('#middle').height()) $('#textWrapper').css('height',$('#left_column').height());
  //   if($('#right_column').height() > $('#middle').height()) $('#textWrapper').css('height',($('#right_column').height() - 30));
  }
  // if($.browser.msie && jQuery.browser.version == 6){
  //   $('#wrapper1').css({'left':'-138px'});
  //   $('#header a').bind('mouseover', function(){$(this).css({'cursor':'pointer'})});
  //   $('.secondary_nav').css('margin-left','50px');
  //   $('#footer').css({'background-image':'url(images/bottom_swoopie_small.png)','margin-left':30});
  //   $('#sponsors').css({'left':'358px','top':'35px'});
  //   $('#home_sponsors').css({'right':'0px','top':'-50px'});
  //   $('#middle_sorted_noNav').css({'margin-left':'125px'});
  // };
  // *********  that's enough of THAT
  
  // *********  set "You Are Here" state
  var pos = $('.yah').position();
  if(pos){
    $('#nav').append('<img id="yah" src="images/yah.png" style="position:absolute;top:-10px;left:'+pos.left+'px;width:1px;height:42px"/>');
  }

  // *********  make sure all content is on white bg
  var fullHeight = ($(document).height() > ($('#copyright').offset()).top + 50 ? $(document).height() : ($('#copyright').offset()).top + 50);
  $('#frame').css('height',fullHeight);
  
});



// *********  this section handles the primary navigation dropdown behaviors
var timeout = 500;
var closetimer = 0;
var currentMenu = null;

document.onclick = function(event){
  var str = (event.target).toString();
  if(str.charAt(str.length-1) == '#'){
    return false;
  } else {
    navClose();
  }
};

function navOpen(){
  navCanceltimer();
  navClose();
  currentMenu = $(this).find('ul').css('display', 'block');
}

function navClose(){
  if(currentMenu) currentMenu.css('display', 'none');
}

function navTimer(){
  closetimer = window.setTimeout(navClose, timeout);
}

function navCanceltimer(){
  if(closetimer){
    window.clearTimeout(closetimer);
    closetimer = null;
  }
}
// *********  end dropdown behaviors


// *********  slide show

function buildSlideShow(){
  if(slideShow.home){
    for(i=0;i<slideShow.length;i++){  // slideShow images are named "ss0.jpg", "ss1.jpg" and so on
      thisImage = '<div id="slideShow'+i+'" class="regularSlideShow" style="background-image:url('+slideShow.path+'ss'+i+'.jpg)"></div>';
      $('#slideShowWrapper').append(thisImage);
    }
    $('#slideShow0').fadeIn();
    setTimeout('ss()',5000);
  }
}

function ss(){
  var slideShowLength = $('#slideShowWrapper').children().length;
  for(i=0;i<slideShowLength;i++){
    if($('#slideShow'+i).css('display') != 'none'){
      var thisImage = i;
      break;
    }
  }
  $('#slideShow'+i).fadeOut();
  var next = (i+1 < slideShowLength ? i+1 : 0);
  $('#slideShow' + next).fadeIn();
  setTimeout('ss()',5000);
}

// *********  end slide show


