$(document).ready(function() {

    // init : open first content after 200ms
    $('#more-less-link').show();
    setTimeout(
      function(){
        $('#realisations .section-content').slideDown("slow");
      },
      500
    );
    //~ $('#realisations .section-content').show();

    // section navigation
    $('.section h2').click(function(e){
      if ($(this).next().is(':hidden')) {
        // hide visible
        $('.section-content:visible').slideUp("slow");
      }
      $(this).next().slideToggle("slow");
      $('#realisations').removeClass('more').find('#realisations-more-content').slideUp();
    }).css('cursor', 'pointer');


    // realisations
    $('#more-less-link a').click(function(e){
      e.preventDefault();
      $('#realisations').toggleClass('more').find('#realisations-more-content').slideToggle();
    });



    // player
    function openPanel() {
      $('#panel').animate({right:'0px'}, 250).removeClass('closed');
    }
    function closePanel() {
      $f('player').pause();
      var playerWidth = eval(-($('#player').outerWidth())-1)+'px';
      $('#panel').animate({right:playerWidth}, 250).addClass('closed');
    }

    $('#panel #panel-tab').click(function(){
      if ( $(this).parent().hasClass('closed') ) {
        openPanel();
      }
      else {
        closePanel();
      }
    })
    .css('cursor', 'pointer')
    .bind('mouseenter mouseleave', function(){
      $(this).toggleClass('hover');
    });



    // Flowplayer
    $f(
      "player",
      {
        src : "/swf/flowplayer-3.1.2.swf",
        wmode : "opaque"
      },
      {
        canvas: {
          background:'#000 url(../img/hp.png) center center no-repeat'
        },
        clip: {
          autoPlay: false,
          autoBuffering: false
        },
        plugins : {
          controls : {
            tooltips : false,
            url : '/swf/flowplayer.controls-3.1.2.swf',
            all : false,
            scrubber : true,
            play : true,
            mute : true,
            volume : true,
             autoHide : 'always',
            hideDelay : '1500',
            bottom : 0,
            left : 0,
            height:20,
            backgroundGradient: 'none',
            backgroundColor : '#000000',
            buttonColor : '#555555',
            buttonOverColor : '#b5fe00',
            sliderColor : '#000000',
            bufferColor : '#222222',
            progressColor : '#b5fe00',
            volumeSliderColor : '#222222'
          },
          audio: {
            url: '/swf/flowplayer.audio-3.1.0.swf'
          }
        },
        onLoad: function() {
          this.setVolume(85);
          this.hide();
        },
        onFinish: function() {
          closePanel();
        }
      }
    );


    // play btn
    $('#realisations .play, #realisations h3 a').click(function(e){
      e.preventDefault();
      closePanel();

      var clipInfo = $(this).attr('rel').match(/([^\[\]]+)/g);
      $('#player, #player object')
      .attr('width',clipInfo[1])
      .css({
          width:clipInfo[1]+'px'
      });
      $f('player').play({url:$(this).attr('href')}).show();
      openPanel();
    })
    .css('cursor','pointer');


});

