var maxPhoto=0;
var currentPhoto=0;
var photoTimer;
var photoDelayTime=3800;
var photoTransitionTime=1000;

$(document).ready(function() {
  $('.sidebar-nav li').hover(
    function() {
      $('.sidebar-nav li.selected').removeClass('selected');
      $(this).addClass('selected');
    },
    function() {
      $('.sidebar-nav li.selected').removeClass('selected');
      $('.sidebar-nav li.default').addClass('selected');
    }
  );
  
  $('.blinds h2').css('padding','0');
  $('.blinds .window').each(function(i,item) {$(item).attr('rel',$(this).height());});
  $('.blinds .window').not(':first').css({height:0,overflow:'hidden'});
  $('.blinds li').click(function() {
    var item=$('.window',this);
    if(item.height()<=0)
      item.animate({height:item.attr('rel')},function() {$(this).css('overflow','visible');});
    $(this).parent().children('li').children('.window').not(item).css('overflow','hidden').animate({height:0});
  });
  
  if((maxPhoto=$('.photostream li').length)>1) {
    currentPhoto=Math.floor(Math.random()*maxPhoto);
    $('.photostream li').css({top:0,left:0}).not(':eq('+currentPhoto+')').hide();
    photoTimer=setTimeout('nextPhoto()',photoDelayTime);
  }
});

function nextPhoto() {
  var n=currentPhoto+1;
  if(n>=maxPhoto)
    n=0;
  var target=$('.photostream li').eq(currentPhoto);
  var nTarget=$('.photostream li').eq(n);
  
  target.css('z-index','98');
  nTarget.css('z-index','99');
  
  nTarget.stop().fadeIn({duration:photoTransitionTime,
                         easing:'easeOutCirc',
                         complete:function() {
                           target.stop().hide();
                           currentPhoto=n;
                         }
                        });
                        
  photoTimer=setTimeout('nextPhoto()',photoDelayTime);
}
