$(function() {
  $.nyroModalSettings({
    debug: false, // Show the debug in the background
    windowResize: false,
    minWidth: 350, // Minimum width
    minHeight: 0, // Minimum height
    autoSizable: true, // Indicate if the content is auto sizable. If not, the min size will be used
    css: { // Default CSS option for the nyroModal Div. Some will be overwritten or updated when using IE6
      bg: {
        position: 'absolute',
        overflow: 'hidden',
        top: 0,
        left: 0,
        height: '100%',
        width: '100%'
      },
      wrapper: {
        position: 'absolute',
        top: '50%',
        left: '50%',
        border: '3px solid #ecf4f9',
        background: '#fff url(/images/popup-top-bg.jpg) top center repeat-x'
      },
      wrapper2: {
      },
      content: {
      },
      loading: {
        position: 'absolute',
        top: '50%',
        left: '50%',
        marginTop: '-50px',
        marginLeft: '-50px',
        border: '3px solid #ecf4f9'
      }
    },
    wrap: { // Wrapper div used to style the modal regarding the content type
      div: '<div class="wrapper"></div>',
      ajax: '<div class="wrapper"></div>',
      form: '<div class="wrapper"></div>',
      formData: '<div class="wrapper"></div>',
      image: '<div class="wrapperImg"></div>',
      swf: '<div class="wrapperSwf"></div>',
      iframe: '<div class="wrapperIframe"></div>',
      iframeForm: '<div class="wrapperIframe"></div>',
      manual: '<div class="wrapper"></div>'
    },
    closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="fermer">Fermer</a>\n\
    <div class="logo"><img src="/images/logo-mini.png" /></div>', // Adding automaticly as the first child of #nyroModalWrapper
    contentLoading: '<a href="#" class="nyroModalClose">Cancel</a>', // Loading div content
    contentError: 'Un problème est survenu durant le chargement de la page.<br />Veuillez réessayer ultérieurement.<br /><a href="#" class="nyroModalClose">Fermer</a>', // Content placed in the loading div in case of error
    endFillContent: endFillContent
  });
});

function endFillContent(elts, settings){
  $("#nyroModalContent", elts.wrapper).append('<div class="clear"></div><div id="closeLink"><a href="#" class="nyroModalClose" title="fermer">Fermer </a></div>');
}

$(document).ready(function(){
  $('.soon').tooltip({
    delay: 0,
    fade: 250,
    showURL: false,
    bodyHandler: function() {
      return "Disponible très prochainement";
    }
  });

  openBlankLink();
  openModalHelper();

  $(".toggle-rel").click(function  () {
    id = $(this).attr("rel");
    $("#"+id).slideToggle("slow");
    return false;
  });

  $.browser.msie6 = $.browser.msie &&/MSIE 6\.0/i.test(window.navigator.userAgent) &&!/MSIE 8\.0/i.test(window.navigator.userAgent) &&!/MSIE 7\.0/i.test(window.navigator.userAgent);
  if($.browser.msie6) {
    var left_position = ($(window).width()/2)-($('#ie6').width()/2);
    $('#ie6').css('left', left_position+'px');
    $('#ie6').css('display', 'block');
  }
});

function openBlankLink() {
  var liens = $('a.blank');

  for (var i = 0 ; i < liens.length ; i++)  {
    liens[i].onclick = function()  {
      window.open(this.href);
      return false;
    };
  }
}

function openModalHelper() {
  $('.helper').click(function(e) {
    var container = $(this).attr("rel");
    var content = $(container).html();
    $.nyroModalManual({
      content: content,
      wrap: { manual: '<div class="wrapper help-modal"></div>' }
    });
    return false;
  });
}