jQuery(document).ready(
	function()
	{
	
	
		jQuery(window).scroll(function(){ // On ajoute une fonction quand on défile dans le site
		  // On récupère la position de la barre de défilement par rapport à notre fenêtre
  		var scrollTop = jQuery(window).scrollTop();
  		var posfen = scrollTop+100; 
  		jQuery('#window').css( {top: posfen+"px"} );
	 });
		//
		jQuery('#windowOpen').live(
			'click',
			function() {
				  //
          //Mise en place du masque
          /*
				  //Récupération des dimensions de la page
				  var xHeight = jQuery(document).height();
				  var xWidth = jQuery(window).width();
				  //Dimensionnement du masque recouvrant la page
				  jQuery('#masquepage').css({'width':xWidth,'height':xHeight});
				  //Apparition du masque
	      	jQuery('#masquepage').fadeIn();
	      	//Attribution à celui-ci d’une transparence de
          //façon à laisser la page légèrement visible 	
	      	jQuery('#masquepage').fadeTo("fast",0.6);	
	      	*/
				if(jQuery('#window').css('display') == 'none') {
				  //Centrage de la fenêtre
				  //
				  /*
	      	var xH = jQuery(window).height();
	      	var xW = jQuery(window).width();				  
      	  jQuery("#window").css('top', xH/2-jQuery("#window").height()/2);
      	  jQuery("#window").css('left', xW/2-jQuery("#window").width()/2);
      	  */
      	  //
      	  // Affichage de la fenêtre
          jQuery('#window').TransferTo(
  					{
  						to:'window',
  						className:'transferer2', 
  						duration: 400
  					}
  				).show();				  
  				}
				this.blur();
				return false;
			}
		);
		jQuery('#windowClose').bind(
			'click',
			function()
			{
			//Sppresion du masque
			//jQuery('#masquepage').hide();
			//
        jQuery('#window').TransferTo(
					{
						to:'windowOpen',
						className:'transferer2', 
						duration: 400
					}
				).hide();
			}
		);
		jQuery('#windowMin').bind(
			'click',
			function()
			{
				jQuery('#windowContent').SlideToggleUp(300);
				jQuery('#windowContent').css({ display : "none" } ); // ajouté car bug fermeture
				jQuery('#windowBottom, #windowBottomContent').animate({height: 10}, 300);
				jQuery('#window').animate({height:40},300).get(0).isMinimized = true;				
				jQuery(this).hide();
				jQuery('#windowResize').hide();
				jQuery('#windowMax').show();
			}
		);
		jQuery('#windowMax').bind(
			'click',
			function()
			{
				var windowSize = jQuery.iUtil.getSize(document.getElementById('windowContent'));
				jQuery('#windowContent').SlideToggleUp(300);
				jQuery('#windowContent').css({ display : "block" } ); // ajouté car bug fermeture
				jQuery('#windowBottom, #windowBottomContent').animate({height: windowSize.hb + 13}, 300);
				jQuery('#window').animate({height:windowSize.hb+43}, 300).get(0).isMinimized = false;
				jQuery(this).hide();
				jQuery('#windowMin, #windowResize').show();
			}
		);
		// resizablz : maxHeight: 400 maxWidth: 700
		jQuery('#window').Resizable(
			{
				minWidth: 200,
				minHeight: 60,
				maxWidth: 1100,
				maxHeight: 800,
				dragHandle: '#windowTop',
				handlers: {
					se: '#windowResize'
				},
				onResize : function(size, position) {
					jQuery('#windowBottom, #windowBottomContent').css('height', size.height-33 + 'px');
					var windowContentEl = jQuery('#windowContent').css('width', size.width - 25 + 'px');
					if (!document.getElementById('window').isMinimized) {
						windowContentEl.css('height', size.height - 48 + 'px');
					}
				}
			}
		);
		//
		//alert('test');


		jQuery('.windowAjax').live(
			'click',
			function() {
				//
			  //alert('Modifier !');
        $test = jQuery(this); // objet en test
        var refarticle =  jQuery('#affJS').attr("rel");
        var refenregistrement = $test.attr("rel");        
        var idreform = "#refform"+refenregistrement;
        //alert('idreform (refform '+refenregistrement+') = ' + idreform );
        var refformulaire = jQuery(idreform).html();        			              //
			  //AfficheModification = window.open ("articles_ajax.php?id="+refarticle+"&aj=1&trait=afform&refform="+refformulaire+"&refenr="+refenregistrement,"AfficheModification","resizable=yes,width=800,height=600,screenX=800,screenY=600,top=200,left=200,alwaysRaised=yes, scrolling=yes,toolbar=no, menubar=no,location=no,directories=no,status=no");
			  //AfficheModification = window.open ("articles_ajax.php?id="+refarticle+"&aj=1&trait=afform&refform="+refformulaire+"&refenr="+refenregistrement,"AfficheModification","resizable=yes,width=800,height=600,screenX=800,screenY=600,top=0,left=0,toolbar=no,menubar=no,location=no,directories=no,status=no, scrollbars=yes");
        AfficheModification = window.open ("articles_modif_form.php?refid="+refarticle+"&aj=1&trait=afform&refform="+refformulaire+"&refenr="+refenregistrement,"AfficheModification","resizable=yes,width=800,height=600,screenX=800,screenY=600,top=0,left=0,toolbar=no,menubar=no,location=no,directories=no,status=no, scrollbars=yes");
        
        return false;
        //
      });

/*
		jQuery('.windowAjax').live(
			'click',
			function() {
			  // on ouvre la fenêtre (ou on la laisse ouverture si déjà ouverte)
        jQuery('#windowOpen').click();
        // Traitement
        $test = jQuery(this); // objet en test
        var refarticle =  jQuery('#affJS').attr("rel");
        var refenregistrement = $test.attr("rel");        
          var idreform = "#refform"+refenregistrement;
          //alert('idreform (refform '+refenregistrement+') = ' + idreform );
          var refformulaire = jQuery(idreform).html();        
			  //
        var ajaxwaithtml = ''; // initialisation
        ajaxwaithtml = ajaxwaithtml + '<center>T&eacute;l&eacute;chargement en cours <br /> Veuillez patienter ... <br /> ';
        ajaxwaithtml = ajaxwaithtml + '<img src="modules/formulaires/fenetre/images/ajax-loader.gif" alt="en cours de chargement ..."   title="en cours de chargement ..."  ></center>';
			  jQuery('#windowContent').html('<br />' + ajaxwaithtml);			
			  //
        jQuery.ajax({  // ajax
          type: "GET",
          //url: "popupcatgen.php", // url de la page à charger par référence catégorie
          url: "articles_ajax.php", // url de la page à charger par référence ID article
          data: "id="+refarticle+"&aj=1&trait=afform&refform="+refformulaire+"&refenr="+refenregistrement, // GET de la page à charger par référence ID article
          cache: false, // pas de mise en cache
          success:function(retourdatas){ // si la requête est un succès
          //alert(html); // Affichage
          var scriptcleitor = '';
          //jQuery('#windowContent').html(Utf8.decode(retourdatas)); // Remplacement du contenu  avec decodage
          //var scriptcleitor = '<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>';
          //var scriptcleitor = '<input type="submit" value="submit" onclick="wysiwyg.submit();">';
          //scriptcleitor = scriptcleitor+'<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>';
          //
          //
          jQuery('#windowContent').html(retourdatas); // Remplacement du contenu  sans decodage
          //
          //jQuery("#commentairetextarea").cleditor({width:500, height:180, useCSS:true})[0].focus();
          //jQuery(".cleditorV1").cleditor({width:500, height:180, useCSS:true})[0].focus();
        //jQuery("textarea").cleditor()[0].focus();
          
        jQuery("#commentairetextarea").cleditor({
          width:        700, // width not including margins, borders or padding
          height:       400, // height not including margins, borders or padding
          controls:     // controls to add to the toolbar
                        "bold italic underline strikethrough subscript superscript | font size " +
                        "style | color highlight removeformat | bullets numbering | outdent " +
                        "indent | alignleft center alignright justify | undo redo | " +
                        "rule image link unlink | cut copy paste pastetext | print source",
          colors:       // colors in the color popup
                        "FFF FCC FC9 FF9 FFC 9F9 9FF CFF CCF FCF " +
                        "CCC F66 F96 FF6 FF3 6F9 3FF 6FF 99F F9F " +
                        "BBB F00 F90 FC6 FF0 3F3 6CC 3CF 66C C6C " +
                        "999 C00 F60 FC3 FC0 3C0 0CC 36F 63F C3C " +
                        "666 900 C60 C93 990 090 399 33F 60C 939 " +
                        "333 600 930 963 660 060 366 009 339 636 " +
                        "000 300 630 633 330 030 033 006 309 303",    
          fonts:        // font names in the font popup
                        "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," +
                        "Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana",
          sizes:        // sizes in the font size popup
                        "1,2,3,4,5,6,7",
          styles:       // styles in the style popup
                        [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"],
                        ["Header 3", "<h3>"],  ["Header 4","<h4>"],  ["Header 5","<h5>"],
                        ["Header 6","<h6>"]],
          useCSS:       false, // use CSS to style HTML when possible (not supported in ie)
          docType:      // Document type contained within the editor
                        '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
          docCSSFile:   // CSS file used to style the document contained within the editor
                        "", 
          bodyStyle:    // style to assign to document body contained within the editor
                        "margin:0px; font:10pt Arial,Verdana; cursor:text"
        });
          //
          //var wysiwyg = new Wysiwyg("commentairetextarea", "wysiwyg");
          //wysiwyg.init();
          //
          },
          error:function(XMLHttpRequest, textStatus, errorThrows){ // erreur durant la requete
          }
        });// fin ajax
        //
      }		
		);      
*/
		//
  //
	}
	//
);

