ï»¿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!                  
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatusVideo = 0;

//loading popup with jQuery magic!
function loadPopupVideo(){
    //loads popup only if it is disabled
    if(popupStatusVideo==0){
        jQuery("#backgroundPopupvideo").css({
            "opacity": "0.7"
        });
        jQuery("#backgroundPopupvideo").fadeIn("slow");
        jQuery("#popupVideo").fadeIn("slow");
        popupStatusVideo = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopupVideo(){
    //disables popup only if it is enabled
    if(popupStatusVideo==1){
        jQuery("#backgroundPopupvideo").fadeOut("slow");
        jQuery("#popupVideo").fadeOut("slow");
        popupStatusVideo = 0;
    }
}

//centering popup
function centerPopupVideo(){
    //request data for centering
    var windowWidthVideo = document.documentElement.clientWidth;
    var windowHeightVideo = document.documentElement.clientHeight;
    var popupHeightVideo = jQuery("#popupVideo").height();
    var popupWidthVideo = jQuery("#popupVideo").width();
    //centering
    //var toposVideo = '20px';
    var scrollTop = ( jQuery(window).scrollTop() ) + 20;// position du scroll
    var toposVideo = scrollTop+'px';
    var leftposVideo = (windowWidthVideo/2-popupWidthVideo/2) - 100;
    leftposVideo = leftposVideo+'px';
    jQuery("#popupVideo").css({
        "position": "absolute",
        "top": toposVideo,
        "left": leftposVideo
    });
    //only need force for IE6
    jQuery("#backgroundPopupvideo").css({
        "height": windowHeightVideo
    });
    
}


//CONTROLLING EVENTS IN jQuery
jQuery(document).ready(function(){

    // changement du curseur pour les actions PopUp
    jQuery('#popupVideoClose').hover(function () {
      jQuery(this).animate({opacity: "0.7"}, 100);
      jQuery(this).css({ cursor: "pointer"});
      }, function () {
      jQuery(this).animate({opacity: "1.0"}, 100);
      jQuery(this).css({ cursor: "auto"});
    });

    //CLOSING POPUP
    //Click the x event!
    jQuery("#popupVideoClose").click(function(){
        jQuery('.videoboxe').css({'display' : 'block' });
        disablePopupVideo();
        jQuery('#flvplayer').html(""); // suppression vidéo

    });
    //Click out event!
    jQuery("#backgroundPopupvideo").click(function(){
        disablePopupVideo();
    });
    //Press Escape event!
    jQuery(document).keypress(function(e){
        if(e.keyCode==27 && popupStatusVideo==1){
            disablePopupVideo();
        }
    });

});
// ------------------ nouvelle fonction pour  jQuery ----------------------------
// initialisation tétière après chargement
//jQuery.fn.Video = function(refvideo) {
function Video(refvideo){
  var urlsiteVideo= "http://afges.org/images_site/Flash/";
  var so = new SWFObject("blocs/popupvideo/swf/mpw_player.swf", "swfplayer", "400", "300", "9", "#000000"); // Player loading
  so.addVariable("flv", urlsiteVideo+refvideo+""); // File Name
  so.addVariable("jpg","blocs/popupvideo/images/wait.jpg"); // Preview photo
  so.addVariable("autoplay","true"); // Autoplay, make true to autoplay
  so.addParam("allowFullScreen","true"); // Allow fullscreen, disable with false
  so.addVariable("backcolor","000000"); // Background color of controls in html color code  86583C
  so.addVariable("frontcolor","ffffff"); // Foreground color of controls in html color code
  so.write("flvplayer"); // This needs to be the name of the div id
  //
  jQuery('.videoboxe').css({'display' : 'none' });
  //window.scroll(0,0); // horizontal and vertical scroll targets
  //centering with css
  centerPopupVideo();
  //load popup
  loadPopupVideo();

};



