/**
  Mesnils saint denis
*/

// Insert automatiquement le lecteur video youtube lorsqu'un lien figure dans le corps de texte
function insertYouTubePlayer(){
  var iHeight=225;
  var iWidth=276;
  var sTpl ='<object width="'+iWidth+'" height="'+iHeight+'"><param name="movie" value="http://www.youtube.com/v/%%ID%%&hl=fr&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/%%ID%%&hl=fr&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+iWidth+'" height="'+iHeight+'"></embed></object>';
  var eContainer = $("#article-sideinfo");
  var aEls = $("#article .texte a[href^=http://www.youtube.com/watch?]");
  var i,s,a,e;
  for(i=0;i<aEls.length;i++){
    s = aEls[i].href;
    a = s.match(/\?v=([a-zA-Z0-9].*?)$/);
    if(a.length == 2 ){
       e = document.createElement('div');
       e.className = "video-box";
       e.innerHTML = sTpl.replace(/%%ID%%/g,a[1]);
       eContainer.append(e);
    }
    if((aEls[i].innerHTML).match(/^http/)) aEls[i].style.display='none';
  }
}

// Insert automatiquement le lecteur video youtube lorsqu'un lien figure dans le corps de texte
function insertDailymotionPlayer(){
  var iHeight=225;
  var iWidth=276;
  var sTpl ='<object width="'+iWidth+'" height="'+iHeight+'"><param name="movie" value="http://www.dailymotion.com/swf/%%ID%%&related=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.dailymotion.com/swf/%%ID%%&related=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+iWidth+'" height="'+iHeight+'"></embed></object>';
  var eContainer = $("#article-sideinfo");
  var aEls = $("#article .texte a[href^=http://www.dailymotion.com/video/]");
  var i,s,a,e;
  for(i=0;i<aEls.length;i++){
    s = aEls[i].href;
    a = s.match(/http\:\/\/www\.dailymotion\.com\/video\/([a-zA-Z0-9].*?)$/);
    if(a.length == 2 ){
       e = document.createElement('div');
       e.className = "video-box";
       e.innerHTML = sTpl.replace(/%%ID%%/g,a[1]);
       eContainer.append(e);
    }
    if((aEls[i].innerHTML).match(/^http/)) aEls[i].style.display='none';
  }
}

$(document).ready(function() { 
    $('ul.sf-menu').supersubs({ 
        minWidth:    17,   // minimum width of sub-menus in em units 
        maxWidth:    27,   // maximum width of sub-menus in em units 
        extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                           // due to slight rounding differences and font-family 
    }).superfish();
    insertYouTubePlayer();
    insertDailymotionPlayer(); 

  if(document.location.toString().match(/nolog=1/)){
    $("a").each(
      function(i){
       if(this.href.match(/^http/) && !(this.href.match(/nolog=1/))) this.href = this.href + (this.href.match(/\?/) ? '&nolog=1' : '?nolog=1');
      }
    );
  }
  // $("#galeries").tabs();
  $("a.popup").bind("click", function(){
    window.open(this.href,this.target,"width=470,height=500,menubar=yes,toolbar=no,directories=no,location=no,resizable=yes,scrollbars=yes,status=no");
    return false;
  });
  window.focus();
    
}); 
    
