google.load('jquery', '1.4.2');

function OnLoad() {
            
  $( function() {
  
/*
    windowResize();
*/
  
    $(window).ready(function() {
      $("#preloader").fadeOut('fast');
      $("#mark_tellok a, #copyright, ul.menu").fadeIn('slow');
     });
      
    $('.menu > li, #mark_tellok').mouseenter(function() {
      $('.menu li ul:has(a.selected)').fadeOut('fast');
      $('ul:animated',this).stop(true, true);
      $('ul',this).show();
    });
    
    $('.menu > li, #mark_tellok').mouseleave(function() {
      $('ul:not(:has(a.selected))', this).fadeOut('fast');
      $('.menu li ul:has(a.selected):animated').stop(true,true);
      $('.menu li ul:has(a.selected)').show();
    });        
    
    // register fancyboxes
    
    fb_defaults = {
      overlayShow: false,
      // en commentaires suppression de l'effet zoom
      /*
      transitionIn: 'elastic',
      transitionOut: 'elastic',
      easingIn: 'easeInOutExpo',
      easingOut: 'easeInOutCubic',
      speedIn: 900,
      speedOut: 900,
      orig: $('#origin'),
      */
      showCloseButton: false,
     
      padding: 0,
      onClosed: function() {
        /*
        Note: Le setTimeout est malheureusement nécessaire car si on appelle
        tout de suite openMenu, cela ne marche pas car la fermeture n'est pas 
        tout à fait finie...
        */   
        setTimeout(openMenu, 200);
      },
      onStart: function(selectedArray, selectedIndex, selectedOpts) {
        // New - last digital_illustration - preload gifs
        /*
        if (selectedArray[selectedIndex].hash=='#gifs') {
          $('#gifs img').attr('src', function() { return (this.src)?this.src:('images/gifs/' + this.alt + '.gif'); });      
        }
        */
        /*
        if (selectedIndex == selectedArray.length-2 && selectedArray[selectedIndex+1].hash=='#gifs') {
          $('#gifs img').attr('src', function() { return (this.src)?this.src:('images/gifs/' + this.alt + '.gif'); });      
        }
        */
      }
    };
     
    // images
    $("a.fb").fancybox(fb_defaults);
    // videos
    $("a.fb.video").fancybox($.extend({},fb_defaults,{
      type: 'swf',
      width: 480,
      height: 270, 
      swf : {
        // 'wmode'             : 'transparent',
        'allowFullScreen'   : 'true',
        'allowScriptAccess' : 'always',
      },
      showNavArrows: false,
      transitionIn: 'fade',
      transitionOut: 'fade',  
    }));
    // inline
    $("a.fb.inline").fancybox($.extend({},fb_defaults,{
      scrolling: 'no',
      transitionIn: 'fade',
      transitionOut: 'fade',
      /* hideOnContentClick: false, */
      /* showNavArrows: false, */
    }));
    
    /*
    $("a.fb.inline[href=#fblinks]").fancybox($.extend({},fb_defaults,{
      scrolling: 'no',
      transitionIn: 'fade',
      transitionOut: 'fade',
      showNavArrows: false,
    }));
    */
      
    // Clicks [ todo - voir bind('click.namespace')... ]
    $(".menu li a:not(.nomenu), #mark_tellok a").click(function() {
      $(this).blur();
      $(".menu li a.selected").removeClass('selected');
      $(this).addClass('selected');
      // $(this).parents('li').children('a').addClass('selected');
      if (false && $('#fancybox-wrap').is(':visible')) {
        $.fancybox.close(); // note: onClosed force la ré-ouverture
      } else {
        $('a[rel=' + $(this).attr('href').replace(/^#/,'') + ']:first').trigger('click');  
      }         
    });
    
    $(".menu li a.nomenu").click(function() {
      $(this).blur();
      return false;
    });
    
    // Only for new browsers
    $(window).bind('hashchange', function() {
      // close disabled
      if (false && $('#fancybox-wrap').is(':visible')) {
        $.fancybox.close(); // note: onClosed force la ré-ouverture
      } else {
        openMenu();  
      }         
    });
    
    // Start show
    openMenu();
  });

}

function openMenu() {
  // ouvre un nouveau menu basé sur l'url du navigateur
  // update class
  $(".menu li a.selected").removeClass('selected');
  $(".menu li a[href=" + window.location.hash + "]").addClass('selected');
  // close deroulant if any
  $('.menu li ul:not(:has(a.selected))').fadeOut('fast');
  // open deroulant
  $('.menu li ul:has(a.selected):animated').stop(true, true);
  $('.menu li ul:has(a.selected)').show();
  
  var rel = window.location.hash.replace(/^#/,'');
  if (rel) {
    $('a[rel=' + rel + ']:first').trigger('click');
  } else {
    $('a[rel=home]').trigger('click');
  }
}


function windowResize() {
  /*
  if (typeof(window.innerHeight) == 'undefined') return false;
  
  var l = 0;
  var h = 0;

  if (window.innerWidth < 1024) l = window.outerWidth - window.innerWidth + 1024;
  if (window.innerHeight  < 780) h = window.outerHeight - window.innerHeight + 780;
  
  if (l || h) {
    if (l > screen.availWidth) l = screen.availWidth;
    if (h > screen.availHeight) h = screen.availHeight;
    window.resizeTo((l)?l:window.outerWidth, (h)?h:window.outerHeight);
  }
  */
  window.moveTo(0,0);
  window.resizeTo(screen.availWidth, screen.availHeight);  
}

google.setOnLoadCallback(OnLoad);
