$(document).ready(function(){
  // Cufon.replace('h1', { fontFamily: "futura-light"} );
  // Cufon.replace('.questionnaire h2', { fontFamily: "futura-book"} );
  // Cufon.replace('.m-votre-compte th', { fontFamily: "futura-book"} );
  // Cufon.replace('#ct-votre-compte h3', { fontFamily: "futura-book"} );
  // Cufon.replace('.sub-header-bar h3', { fontFamily: "futura-book"} );
  
  $(".idconcepts-flash").flash(
    { src: '/PROD/flash/idconcepts.swf', width: 642, height: 213, flashvars: { xml_params: '/PROD/xml/'+$(".idconcepts-flash").attr('id')+'.xml' } },
    { version: 8 })
  ;
  $("#stage .images")
  .after('<div class="nav">') 
  .cycle({ 
    fx:     'fade',
    speed:  2500,
    pager:  '.nav'
  });
  
  $("#bfm-radio-spot").flash(
    { src: '/PROD/flash/player.swf', width: 320, height: 248, flashvars: { file: '/PROD/fichiers/30_IdBuffet_Mx030609.mp3', image: '/PROD/img/edito/radio-img-2.jpg' } },
    { version: 8 }
  );
  $("#bfm-radio-itw").flash(
    { src: '/PROD/flash/player.swf', width: 320, height: 248, flashvars: { file: '/PROD/fichiers/Thomas_Favrel_sur_BFM.mp3', image: '/PROD/img/edito/radio-img-1.jpg' } },
    { version: 8 }
  );
  
  //  Anchor Tabs
  anchor = $.url.attr("anchor");
  $("ul.tabs li:eq(1) a").removeClass("selected");
  if (anchor!=null){
    anchor = parseInt(anchor.substr(4));
  } else {
    anchor = 1;
  }
  
  $("ul.tabs li:eq("+(anchor-1)+") a").addClass("selected");
  $("ul.tabs").idTabs("tabs"+anchor, true);
  
  //  Cross Selling tabs
  $(".product-cross-selling").each(function(item){
    $(this).find('li.panier a').bind("click", function(e){
      e.stopPropagation()
      
      // Fetch product ID from URL
      $(this).attr("href").match(new RegExp(/PID=(\d+)&/g));
      PID = RegExp.$1;

      // Fetch Quantiy from the input text
      QPID = $('#QPID_'+PID).val();

      // If quantity is more than or equal to 1
      if (QPID>0)
      {
        href = $(this).attr("href").replace(/QPID_(\d+)=1&/, "QPID_"+PID+"="+QPID+"&");
        $(this).attr("href", href);
        
      // Don't move
      } else {
        alert("La quantité saisie doit être au minimum de 1");
      }
    });
  });

  if ($.url.param("Added")=="1")
  {
    $.openDOMWindow({
      loader:0,
      borderSize:0,
      width:245,
      height:100,
      windowPadding:0,
      windowBGColor:'transparent',
      windowBGImage:'/PROD/img/bg-addToCart.png',
      windowSource:'inline',
      windowSourceID:'#inlineAddToCartMessage'
    });
    $('#addToCartMessage').click(function(){$.closeDOMWindow()});
  }
});

function openWindow(url, w, h) {
  var options = "width=" + w + ",height=" + h + ",";
  options += "resizable=yes,scrollbars=yes,status=yes,";
  options += "menubar=no,toolbar=no,location=no,directories=no";
  var newWin = window.open(url, 'newWin', options);
  newWin.focus();
}
