$(document).ready(function() {
    /*** NAV ***/
    $('.rollover').hover(function() {
        if($(this).parents('h2').is('.selected')) return;
        var img = $(this).find('img');
        img.attr('src', img.attr('src').substr(0, (img.attr('src').length - 4)) + '-selected.png');
    }, function() {
        if($(this).parents('h2').is('.selected')) return;
        var img = $(this).find('img');
        img.attr('src', img.attr('src').substr(0, (img.attr('src').length - 13)) + '.png');
    });

    /*** SLIDER ***/
    $("#slider .picts").sudoSlider({
         fade: true,
         auto:true,
         prevNext:false,
         speed: 4000
      });

      /*** SUBNAV ***/
      /* Click */
      $('#subnav h2 a').click(function() {
          var h2 = $(this).parent('h2');
          if(h2.is('.selected')) {
              h2.removeClass('selected');
              $('#' + $(this).attr('href').substr(1)).slideUp('fast', function() {});
          } else {
              $('#subnav h2').removeClass('selected');
              $('#subnav .slide').slideUp('fast');
              h2.addClass('selected');
              $('#' + $(this).attr('href').substr(1)).slideDown('fast', function() {});
              $('.picts').hide();
              $('#picts-' + $(this).attr('href').substr(1)).show();
          }
          
      });
      /* Init */
      var anchor = window.location.hash;
      if(anchor != '') {
          if(anchor.indexOf('plus/') == -1 && anchor.indexOf('page/') == -1) {
              $('#subnav h2 a[href=' + anchor + ']').parent('h2').addClass('selected');
              $('#' + anchor.substring(1)).slideDown('fast', function() {});
              $('#picts-' + anchor.substring(1)).show();
          } else {
              $('#overlay').load('ajax/' + anchor.substr(6) + '.ajax.html', function() {
                $(this).fadeIn('fast', function() {
					initScroll();
                    $('#subnav h2').first().addClass('selected');
                    $('#subnav .slide').first().slideDown('fast', function() {});
                    $('#content .picts').first().show();
                });
            });
          }
      } else {
          $('#subnav h2').first().addClass('selected');
          $('#subnav .slide').first().slideDown('fast', function() {});
          $('#content .picts').first().show();
      }
      

      /*** OVERLAY ***/
      $('a.popin').click(function() {
            $('#overlay').load('ajax/' + $(this).attr('href').substr(6) + '.ajax.html', function() {
                    initScroll();
                $(this).fadeIn('fast');
            });
      });
      $('.popin-close').live('click', function() {
          $('#overlay').fadeOut('fast', function() { 
              $(this).html('') });
      });
      $(window).scroll(function (e) {
            $('#overlay').css('height', $(window).scrollTop() + $(window).height());
      });

      /*** POPUP ***/
      $('.popup').click(function() {
        window.open ($(this).attr('href'), 'SAR', config='height=350, width=555, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
        return false;
    });

});

