Index: extensions/Autosize/autosize.inc.php
===================================================================
--- extensions/Autosize/autosize.inc.php	(revision 18975)
+++ extensions/Autosize/autosize.inc.php	(revision 19003)
@@ -36,6 +36,5 @@
 **************************/
  static public function autosize_calcContent($content,$element_info){
- 
-  global $conf,$page, $template,$picture,$user; 
+   global $conf,$page, $template,$picture,$user; 
   global $defined_types,$pictureSelType ,$pictureDeriv ,$liste_type,$SRC_IMG;
   global $autosize_parametres,$user_status;
@@ -52,16 +51,7 @@
 }
  if(preg_match("|event|", $DEBUG_autosize, $val))  $infos_message =  "autosize_calcContent, " ; 
- if(preg_match("|test|", $DEBUG_autosize, $val )) { 
-     echo cl_print_var($infos_message) ;
- if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
- echo "COOKIE:"  . cl_print_var($_COOKIE) ;
- echo "GET:"  . cl_print_var($_GET) ;
- echo "POST:"  . cl_print_var($_POST) ;
- die("#60:" . $DEBUG_autosize);
- }
     $ma_page=isset($page['body_id'])?$page['body_id']:"" ;  
    if ($ma_page !='thePicturePage') return ; 
-
-           $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), array("Autosize","SelMaxi"));
+    $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), array("Autosize","SelMaxi"));
     if (count($types)==0){  
         include_once (AUTOSIZE_PATH.'maintain.inc.php');
@@ -72,7 +62,8 @@
           unset (  $_COOKIE['autosize_reload']) ;
     }
-    if(!isset($_COOKIE['windowHeight'] )){
+
+    if(!isset($_COOKIE['picture_deriv'] )){
        self::reload();
-       die("#76" . $DEBUG_autosize);
+       die("#76 autosize_calcContent:" . $DEBUG_autosize);
     }
 
@@ -80,5 +71,5 @@
    if (!isset($_COOKIE['autosize_reload'])  ){  
            self::reload();
-            die("#82 :" + $DEBUG_autosize);
+            die("#82 autosize_calcContent:" + $DEBUG_autosize);
 
     }  
@@ -111,5 +102,5 @@
   global  $template,$version,$icon_path,$page,$picture,$conf;
   global $user,$Css,$css_slideshow,$css_display,$liste_type;
-  global  $has_pamoorama,$pictureSelType,$pictureDeriv;
+  global  $has_pamoorama,$pictureSelType,$pictureDeriv,$pictureMap;
   global $infos_message,$warnings_message;
 
@@ -135,12 +126,64 @@
   $css_slideshow=isset($Css['.Autosize']['slideshow'])?$Css['.Autosize']['slideshow']:"yes"; 
   $css_display= isset($Css['.Autosize']['display'])?$Css['.Autosize']['display']:"block";  
+  $default_size =  $conf['derivative_default_size'];
+//============================================================
+self::get_cookies();
  //==============================================================
-  $pictureDeriv = pwg_get_session_var('picture_deriv',$conf['derivative_default_size']); 
-  $default_size =  $conf['derivative_default_size'];
+ if(preg_match("|test|", $DEBUG_autosize, $val)) { 
+    echo "Init:SESSION:"  . cl_print_var($_SESSION) ;
+       if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
+        echo "Init: COOKIE:"  . cl_print_var($_COOKIE) ;
+        echo "GET:"  . cl_print_var($_GET) ;
+        echo "POST:"  . cl_print_var($_POST) ;
+        echo "$pictureDeriv $pictureSelType $pictureMap ";
+      //  die("#135: ".$DEBUG_autosize);
+ }
   $autosize_parametres = cl_autosize_Get_Options();
-//=======================================================================
-$pictureSelType = pwg_get_session_var('picture_sel_type',$pictureSelType);  
+
+//=====================================================================
+  $current = $template->get_template_vars('current'); 
+   //=== Zone affichage ==       
+      $windowWidth=$_COOKIE['windowWidth'] ;
+      $windowHeight=$_COOKIE['windowHeight'] ;
+
+      $theImageTop= isset($_COOKIE['theImageTop'])?$_COOKIE['theImageTop']:0;
+      $theImageLeft=isset($_COOKIE['theImageLeft'])?$_COOKIE['theImageLeft']:0;
+
+       $theImageRight=isset($_COOKIE['theImageRight'])?$_COOKIE['theImageRight']:0;
+       $theImageBottom=isset($_COOKIE['theImageBottom'])?$_COOKIE['theImageBottom']:0;
+
+
+       $theImageMargeWidth=isset($_COOKIE['theImageMargeWidth']) ? $_COOKIE['theImageMargeWidth']:0;
+       $theImageMargeHeight=isset($_COOKIE['theImageMargeHeight'])?$_COOKIE['theImageMargeHeight']:0;
+
+      $theImageMargeHeight -= 2;
+if(isset($_COOKIE['theImageWidth'])){
+       $theImageWidth=    $_COOKIE['theImageWidth'];
+       $theImageHeight=  $_COOKIE['theImageHeight'] ;
+}
+       $theImageWidth=    $windowWidth -  $theImageLeft - $theImageMargeWidth;
+       $theImageHeight=   $windowHeight - $theImageTop  - $theImageMargeHeight ;
+ 
+   if (isset($element_info['is_gvideo']) && $element_info['is_gvideo'] ){
+    $pictureDeriv=$default_size;
+
+   }else{
+
+
+    $retour = self::get_min_max() ; 
+
+    $theMainImageSize = $retour->get_size();
+    $theMainImageWidth=   isset($_COOKIE['theMainImageWidth'])?$_COOKIE['theMainImageWidth']:$theMainImageSize[0];
+    $theMainImageHeight=   isset($_COOKIE['theMainImageHeight'])?$_COOKIE['theMainImageHeight']:$theMainImageSize[1] ;
+
+  if($theImageHeight!=0 && $theImageWidth!=0){
+      $pictureDeriv=$retour->type ;
+   }else{
+      $pictureDeriv=$default_size;
+   }
+}
  
  if(preg_match("|test|", $DEBUG_autosize, $val)) { 
+    echo "Init:SESSION:"  . cl_print_var($_SESSION) ;
     echo $infos_message ;
     if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
@@ -148,78 +191,6 @@
         echo "GET:"  . cl_print_var($_GET) ;
         echo "POST:"  . cl_print_var($_POST) ;
-        die("#147: ".$DEBUG_autosize);
+     echo ("#201: ".$DEBUG_autosize);
  }
- 
-
-if(!isset($_COOKIE['picture_sel_type'])){
-   if($autosize_parametres->defaut_type=="off")
-      $pictureSelType = pwg_get_session_var('picture_sel_type',"SelMaxi"); 
-   else
-      $pictureSelType = pwg_get_session_var('picture_sel_type',"Autosize"); 
-        
-}else{
-     $pictureSelType = $_COOKIE['picture_sel_type'] ;
-}
-
-//=====================================================================
-  $current = $template->get_template_vars('current'); 
-   //=== Zone affichage ==       
-      $windowWidth=$_COOKIE['windowWidth'] ;
-      $windowHeight=$_COOKIE['windowHeight'] ;
-
-      $theImageTop= isset($_COOKIE['theImageTop'])?$_COOKIE['theImageTop']:0;
-      $theImageLeft=isset($_COOKIE['theImageLeft'])?$_COOKIE['theImageLeft']:0;
-
-       $theImageRight=isset($_COOKIE['theImageRight'])?$_COOKIE['theImageRight']:0;
-       $theImageBottom=isset($_COOKIE['theImageBottom'])?$_COOKIE['theImageBottom']:0;
-
-
-       $theImageMargeWidth=isset($_COOKIE['theImageMargeWidth']) ? $_COOKIE['theImageMargeWidth']:0;
-       $theImageMargeHeight=isset($_COOKIE['theImageMargeHeight'])?$_COOKIE['theImageMargeHeight']:0;
-
-      $theImageMargeHeight -= 2;
-if(isset($_COOKIE['theImageWidth'])){
-       $theImageWidth=    $_COOKIE['theImageWidth'];
-       $theImageHeight=  $_COOKIE['theImageHeight'] ;
-}
-       $theImageWidth=    $windowWidth -  $theImageLeft - $theImageMargeWidth;
-       $theImageHeight=   $windowHeight - $theImageTop  - $theImageMargeHeight ;
- 
-   if (isset($element_info['is_gvideo']) && $element_info['is_gvideo'] ){
-    $pictureDeriv=$default_size;
-
-   }else{
-
-
-    $retour = self::get_min_max() ; 
-
-    $theMainImageSize = $retour->get_size();
-    $theMainImageWidth=   isset($_COOKIE['theMainImageWidth'])?$_COOKIE['theMainImageWidth']:$theMainImageSize[0];
-    $theMainImageHeight=   isset($_COOKIE['theMainImageHeight'])?$_COOKIE['theMainImageHeight']:$theMainImageSize[1] ;
-
-  if($theImageHeight!=0 && $theImageWidth!=0){
-      $pictureDeriv=$retour->type ;
-   }else{
-      $pictureDeriv=$default_size;
-   }
-}
-//============================================================
-  pwg_set_session_var('picture_deriv',$pictureDeriv);
-  setcookie( 'picture_deriv',
-            $pictureDeriv,
-            0,
-            cookie_path() 
-          );
-//============================================================
-pwg_set_session_var('picture_sel_type',$pictureSelType);
-  setcookie( 'picture_sel_type',
-            $pictureSelType,
-            0,
-            cookie_path() 
-          );
-//=============================================================
-$_COOKIE['picture_sel_type']=$pictureSelType;
-$_COOKIE['picture_deriv']=$pictureDeriv;
-
  $pattern = array();
   if($has_pamoorama=="true"){ 
@@ -255,5 +226,6 @@
       $content=str_replace( "<object" , "<object id='theMainImage_obj' name='theMainImage' "  ,$content,$ncount);
       $content=str_replace( "<embed" ,  "<embed id='theMainImage_emb' name='theMainImage' "  ,$content,$ncount);
-      $content=str_replace( 'id="video"',"id='theMainImage_obj'  name='theMainImage' " ,$content,$ncount);
+      $content=str_replace( 'id="video"',"id='theMainImage_vid'  name='theMainImage' " ,$content,$ncount);
+  $content=str_replace( '<video"',"<video id='theMainImage_vid'  name='theMainImage' " ,$content,$ncount);
   }else{
       $content=str_replace( "<iframe" ,  "<iframe id='iframe' name='theMainImage' "  ,$content,$ncount);
@@ -261,7 +233,7 @@
   $content=  preg_replace($pattern, "", $content);
 
-  $content= "<div id='theMainImage' style='height:".$theImageHeight."px  ;width:".$theImageWidth."px '>". $content . "<img src='".AUTOSIZE_PATH . "images/transparent.gif' /></div>";
+  $content= "<div id='theMainImage' style='height:".$theImageHeight."px  ;width:".$theImageWidth."px '>". $content . "</div>";
  $content= "<style>#theImageAndInfos{height:auto;width:auto;position:relative}
-  #theImage{height:auto;align:center;text-align:center;width:100%;position:relative}
+  #theImage{height:auto;align:center;text-align:center;position:relative}
   #theMainImage{height:auto;align:center;text-align:center;position:static}  
   #charlie{display:none }
@@ -270,5 +242,6 @@
 return  $content;
  }
- $content=  preg_replace($pattern, "", $content);
+ 
+   $content=  preg_replace($pattern, "", $content);
 
   return  $content;
@@ -291,26 +264,19 @@
   if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .= "init2, ";} ;
    global $theImageHeight,$theImageWidth,$theImageLeft,$theImageTop,$windowWidth,$windowHeight,$theMainImageSize;
-
-
   //-- si Autosize correction redim ---------------
   $current = $template->get_template_vars('current'); 
   if (!isset($current)) return ;
-  
-//  if( $has_pamoorama=="true") return $content ;
-   if($pictureSelType!="Autosize") return $content ;
-
-$pattern =Array('/width=\"(\d+)\"/','/height=\"(\d+)\"/');
-$replacement = Array('',"style='height:".$theImageHeight."px'");
-$content= preg_replace($pattern, $replacement, $content);
+  if($pictureSelType!="Autosize") return $content ;  
+    $pattern =Array('/width=\"(\d+)\"/','/height=\"(\d+)\"/');
+    $replacement = Array('',"style='height:".$theImageHeight."px'");
+      $replacement = Array('',"");
+    $content= preg_replace($pattern, $replacement, $content);
 if( $has_pamoorama=="true") return $content ;
 
 if( !preg_match("|c1|", $DEBUG_autosize, $val) ) return $content ;
-
 //************************  c1 ***************************************
    echo "theMainImageWidth :" . $theMainImageSize[0] . " X " . $theMainImageSize[1]  . "<br >";
    echo "theImageWidth :" . $theImageWidth . " X " . $theImageHeight . "<br >";
-
    echo $infos_message."<br />";
-   
    $Ratio = $theMainImageSize[0]/$theMainImageSize[1];
 
@@ -331,41 +297,5 @@
          echo "left:".$theImageLeft."px;top:".$theImageTop."px;width:".$theImageWidth ."px;height:" .$theImageHeight."px;";
         echo "<div style='position:absolute;left:".$theImageLeft."px;top:".$theImageTop."px;width:".$theImageWidth ."px;height:" .  $theImageHeight."px;background-color:green;'>";
- 
- 
  die("#317 : " . $content + $DEBUG_autosize);
- $theImageHeight =abs($theImageHeight);
- $theImageWidth =abs($theImageWidth);
-
-    if ( preg_match("|<img|", $content, $val) ){
-        $chars=substr($pictureDeriv,0,2);    
-        $content=str_replace("<img ","<!--img ",$content);
-        $content=str_replace(">","-->",$content);
-        $src=explode( 'src=',$content);
-        $src=explode( ' ',$src[1]);
-        $src=$src[0];   
-        $char2=substr($src,-7); 
-        $content=str_replace("$char2", $chars.'.JPG"',$content);    
-        $ncount=1;
-        $content=str_replace( "width" ,  "old_w"  ,$content,$ncount);
-        $content=str_replace( "height" , "old_h" ,$content,$ncount);
-        if (isset($theImageHeight) && isset($theImagewidth))
-        $content=str_replace(" old_w","style='height:".$theImageHeight."px; width:".$theImageWidth."px;' old_w",$content,$ncount);
-        $content=str_replace("<!--img ","<img ",$content);
-        $content=str_replace("-->",">",$content);   
-       
-       $content=$content. "<span><br> height:".$theImageHeight."px; width:".$theImageWidth."px; </span>" ;
-        return $content ;
-    } 
-     // id="charlie"
-     if ( preg_match("|charlie|", $content, $val) ){
-   
-
-     //    return $content ;
-
- }
-
- 
-
-     
     
 } //INIT2
@@ -374,6 +304,10 @@
 ***************************/
 static public  function reload(){
-    //=========================================
-    include_once ( "include/functions_cookie.inc.php");
+//=========================================
+include_once ( "include/functions_cookie.inc.php");   
+global $ma_page,$user,$element_info,$infos_message,$DEBUG_autosize;
+global $pictureDeriv,$pictureSelType,$pictureMap;
+      global $conf;
+
   $set_miniature = "<!DOCTYPE html><html><head>
    <meta http-equiv='content-type' content='text/html; charset=UTF-8'/>
@@ -384,5 +318,5 @@
 
    $set_var = "<script type='text/javascript'>\n var COOKIE_PATH =  '".cookie_path()."';\n";  
-   global $ma_page,$user,$element_info;
+
    $set_var .= " var mapage =  '". $ma_page . "';\n";  
    $set_var .= " var theme =  '" .$user['theme']. "';\n";  
@@ -399,8 +333,51 @@
      <div></div>
       </body></html>";   
+
+ 
+  $default_size =  $conf['derivative_default_size'];
+//=======================================================================
+$pictureSelType = pwg_get_session_var('picture_sel_type',$default_size);  
+$pictureDeriv = pwg_get_session_var('picture_deriv',$default_size);  
+$pictureMap = pwg_get_session_var('picture_map',$default_size);  
+//=======================================================================
+   $autosize_parametres = cl_autosize_Get_Options();
+   $userst= $user['status']."_enabled" ;
+ $userst=$autosize_parametres-> $userst;
+ $usertype= $user['status']."_type" ;
+ $usertype = $autosize_parametres->$usertype;
+if($userst=='off'){
+ 
+}else{ 
+      if($usertype!="Autosize" && $usertype!="SelMaxi" ){
+          $pictureSelType = $usertype;
+          $pictureDeriv = $usertype;
+      }else if($autosize_parametres->defaut_type=="off"){
+          $pictureSelType = pwg_get_session_var('picture_sel_type',"SelMaxi"); 
+      }else {
+          $pictureSelType = pwg_get_session_var('picture_sel_type',"Autosize");  
+      }
+}        
+//============================================================
+  self::save_cookies();
+if( !isset($_COOKIE['picture_deriv'])  ){
+  echo "INIT <pre>";
+  print_r($_COOKIE);
+  die(400);
+}
+
+if(preg_match("|vue_init|", $DEBUG_autosize, $val)) { 
+        echo "Reload: $userst <br> $usertype <br> autosize_parametres:"  . cl_print_var($autosize_parametres) ;
+        echo $infos_message ;
+    if ( isset($_COOKIE['pwg_id']) ) unset ($_COOKIE['pwg_id']) ;
+        echo "Reload: SESSION:"  . cl_print_var($_SESSION) ;
+        echo "Reload: COOKIE:"  . cl_print_var($_COOKIE) ;
+        echo "GET:"  . cl_print_var($_GET) ;
+        echo "POST:"  . cl_print_var($_POST) ;
+        die("#442: ".$DEBUG_autosize);
+ }
         echo $set_miniature ;
         echo $set_var ;
         echo $autoscript;  
-                 die();
+        die();
       //=========================================     
 
@@ -422,5 +399,5 @@
  //==== mise à l'échelle ===
     $current = $template->get_template_vars('current'); 
-      $default_size =  $conf['derivative_default_size'];
+    $default_size =  $conf['derivative_default_size'];
 
     if(isset($current['selected_derivative'])) {
@@ -443,7 +420,5 @@
     $autosize_parametres =	 cl_autosize_Get_Options() ;			
     $theme=$user['theme'];
-
     //==============================================================================
- 
     $template->assign(
       array(   
@@ -458,5 +433,5 @@
           'AUTOSIZE_PATH_ABS' => AUTOSIZE_PATH_ABS,
           'Version_pwg' => PHPWG_VERSION ,
-          'slideshow' => $page['slideshow']
+          'slide_show' => $page['slideshow']
          )
     );
@@ -488,10 +463,7 @@
     $theme=$user['theme'];
     if ($has_pamoorama=="false" ) return ; 
-    if ($css_slideshow="no" and isset($_GET['slideshow'])) return ;   
+    if ($css_slideshow == "no" and isset($_GET['slideshow'])) return ;   
 			$AUTOSIZE_PATH = dirname(__FILE__).'/';
-
 //=====================================================================
-
-
 			$template->assign(
   					array(
@@ -501,9 +473,7 @@
 					'theme' => $theme  ,
 					'DEBUG_autosize' => $DEBUG_autosize   ,
-					'AUTOSIZE_PATH' => AUTOSIZE_PATH
-         
+					'AUTOSIZE_PATH' => AUTOSIZE_PATH         
 					)
 						);
-
 			$autoscript="<script type='text/javascript'>
 			/* cl_autosize_script_2 */
@@ -558,6 +528,4 @@
 *************************/	
 	static public function cl_autosize_affiche(){
-
-
   if (!defined('AUTOSIZE_PATH')) {
       define(  'AUTOSIZE_PATH',   PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/' );
@@ -565,5 +533,4 @@
         define(  'AUTOSIZE_PATH_ABS',  realpath(AUTOSIZE_PATH)."/");
 }
-
 
     global $user, $picture, $template,$page,$known_script;
@@ -575,11 +542,13 @@
     global $autosize_parametres,$user_status;    
     global  $has_pamoorama,$pictureSelType,$pictureDeriv;
-     global $DEBUG_autosize;
+    global $DEBUG_autosize;
+      global $css_slideshow,$css_display;  
       if(preg_match("|event|", $DEBUG_autosize, $val)) { $infos_message .=  "cl_autosize_affiche, " ;} ;
-
 $ma_page=isset($page['body_id'])?$page['body_id']:"" ;
 if ($ma_page !='thePicturePage') return ;  
+//============================================================
+ self::save_cookies();
+
     if(isset($set_miniature)){
-
           $set_miniature = self::cl_autosize_nofile($set_miniature) ;
           $set_miniatures= explode("script",$set_miniature);
@@ -594,11 +563,11 @@
           $template->append('footer_elements',$set_miniature);  
       }
-         
-  global $css_slideshow,$css_display;
-		$AUTOSIZE_PATH = dirname(__FILE__).'/';
-   $theme=$user['theme'];  
- 		load_language('plugin.lang', AUTOSIZE_PATH);
-		include_once (AUTOSIZE_PATH."include/affiche.php");      
-   
+ if ($css_slideshow == "no" and isset($_GET['slideshow'])) return ;   
+  
+  $AUTOSIZE_PATH = dirname(__FILE__).'/';
+  $theme=$user['theme'];  
+  load_language('plugin.lang', AUTOSIZE_PATH);
+
+ include_once (AUTOSIZE_PATH."include/affiche.php");   
 
      $file =AUTOSIZE_PATH_ABS.'template/picture_1.tpl' ;
@@ -613,8 +582,11 @@
      if($pictureSelType == $pictureDeriv ) {
          if(preg_match("|event|", $DEBUG_autosize, $val)) {  cl_aff_infos_plus();} ;
-     //   return ;
+    
      } 
-         if (defined('GMAPS_VERSION')) $gmaps_function="true";
+      
+    if (defined('GMAPS_VERSION')) $gmaps_function="true";
           else $gmaps_function="false" ;
+
+
 
         $template->set_filenames(array('autosize_content_header'=> $file )); 
@@ -669,10 +641,22 @@
         $template->parse('mes_script');
       }    
-      
-        cl_aff_infos_plus();
+     
+
+if(preg_match("|vue_cookies|", $DEBUG_autosize, $val)) { 
+
+  $pictureSelType=$_COOKIE['picture_sel_type'];
+  $pictureDeriv=$_COOKIE['picture_deriv'];
+  $infos_message .= "cl_autosize_affiche: $pictureSelType  <--> $pictureDeriv \n" ;
+
+}
+   cl_aff_infos_plus();
+   if(preg_match("|test|", $DEBUG_autosize, $val)) { 
+    echo "cl_autosize_affiche:_COOKIE:"  . cl_print_var($_COOKIE) ;
+    echo $infos_message ;
+    $pictureMap=$_COOKIE['picture_map'];
+    echo "SelType:" . $pictureSelType." pictureDeriv:".$pictureDeriv ." pictureMap:".$pictureMap;
+    die ("#710: ".$DEBUG_autosize);
+ }
         return $template->parse( 'autosize_content', false);
-   
-	
-
 	} //public function cl_autosize_affiche
 
@@ -1042,5 +1026,6 @@
     $img_url  = $img_select->get_url();
     if(!file_exists(PHPWG_ROOT_PATH.$img_url)){   
-      $img_type  =  $img_select->get_type();	  
+      $img_type  =  $img_select->get_type();	 
+     
       $file_id=explode("?",$img_url); 
       if(count($file_id) ==1){
@@ -1053,5 +1038,9 @@
               $file_no->id=$id ;
               $file_no->type=$img_type ; 
-              array_push($nofiles,serialize($file_no)) ;              
+              array_push($nofiles,serialize($file_no)) ;   
+               if( $img_type == $pictureDeriv){
+         
+          break ;
+    }           
       }
       $ok=false ;     
@@ -1066,7 +1055,5 @@
       $nosrc=true ;
     }  
-   
-     
-   $exec_miniatures ="";
+    $exec_miniatures ="";
       $script_miniatures .= "<script type='text/javascript'>
         var nofile=Array(";
@@ -1092,4 +1079,55 @@
     }
  }
+ /***************************
+ *  get_cookies
+ ****************************/
+ static public  function  get_cookies(){
+  global $pictureDeriv,$pictureSelType,$pictureDeriv;
+  if(!isset($_COOKIE['picture_deriv'])){
+      $pictureDeriv= pwg_get_session_var('picture_deriv');
+      $pictureSelType = pwg_get_session_var('picture_sel_type');
+      $pictureMap = pwg_get_session_var('picture_map') | $pictureDeriv;
+  }else{
+      $pictureDeriv = $_COOKIE['picture_deriv'];
+      $pictureSelType = isset( $_COOKIE['picture_sel_type'])?$_COOKIE['picture_sel_type']:$pictureDeriv;
+      
+      $pictureMap =  isset($_COOKIE['picture_map'])?$_COOKIE['picture_map']:$pictureDeriv;
+  }
+  $_COOKIE['picture_sel_type']=$pictureSelType;
+  $_COOKIE['picture_deriv']=$pictureDeriv;
+  $_COOKIE['picture_map']=$pictureMap;
+
+ }
+ /***************************
+ * save_cookies
+ ****************************/
+ static public  function  save_cookies(){
+ global $pictureDeriv,$pictureSelType,$pictureDeriv;
+
+  pwg_set_session_var('picture_deriv',$pictureDeriv);
+  pwg_set_session_var('picture_sel_type',$pictureSelType);
+  pwg_set_session_var('picture_map',$pictureDeriv);
+//============================================================
+  setcookie( 'picture_sel_type',
+            $pictureSelType,
+            time()+5,
+            cookie_path() 
+          );
+//=============================================================
+  setcookie( 'picture_map',
+            $pictureDeriv,
+            time()+5,
+            cookie_path() 
+          );
+//============================================================
+  setcookie( 'picture_deriv',
+            $pictureDeriv,
+            time()+5,
+            cookie_path() 
+          );
+$_COOKIE['picture_sel_type']=$pictureSelType;
+$_COOKIE['picture_deriv']=$pictureDeriv;
+$_COOKIE['picture_map']=$pictureDeriv;
+}
  //==================================================
 } // class
