/**
 * Common JavaScript playground
 */

(function($, LPG){

var $j = jQuery.noConflict();

  $j(function(){
    /*
     * Flash injection
     * - we load the symfony slot determined path
     * - or the default one (language determined via app.yml
     */
    var flash_path = LPG.flash.location || LPG.dir.media+LPG.flash['default'];
    $j('#flashContent').flash({
      height:   410,
      src:      flash_path,
      flashvars: { urlDomainFR: 'http://www.lpgsystems.fr',urlDomainEN: 'http://www.lpgsystems.com' },       
      width:    900,
      wmode:    'transparent',
      allowFullScreen: true
    });

         
      /*****************************************/   
      /**** affichage liste des sites webs   ***/  
            
      var statusWebsite=0;
      //Evenement switch sur click du bouton LPG sites    
      $j("#websites").click(function()
      {
          if(!statusWebsite){
              $j('#listeWebsites').show(); 
              $j("#websites").removeClass("websitesNoClicked");
              $j("#websites").addClass("websitesClicked");
              statusWebsite=1;
          }
          else if(statusWebsite){
              $j('#listeWebsites').hide();   
              $j("#websites").removeClass("websitesClicked");
              $j("#websites").addClass("websitesNoClicked");
              statusWebsite=0;
          }
      });    
      $j("#websites").mouseout(function()
      {
              if(statusWebsite){
                    $j("#listeWebsites").hide();
                    $j("#websites").removeClass("websitesClicked");
                    $j("#websites").addClass("websitesNoClicked");
                  statusWebsite=0;
          }
      
      }); 
          
      //quand survol de la liste des sites web il reste visible sinon il disparait et on remet la clase noClicked au bouton #websites
      $j("#listeWebsites").hover(function()
      {
          $j(this).show();
      },function()
      {
          $j(this).hide();
          $j("#websites").removeClass("websitesClicked");
          $j("#websites").addClass("websitesNoClicked");  
          statusWebsite=0;
      });
      /*****************************************/ 
      /*****************************************/       
      
      
      
      
      //affichage du sous menu sur un hover sur la classe li.sousmenu
      //affectation de la classe menuhover pour les li du mainMenu (car IE6 ne prend pas les pseudo classe :hover sur les li)   
      $j("#menu > ul > li.sousmenu").hover(function()
      {           
          $j(this).addClass("menuHover");
          $j(this).find("ul.niveau2").show();
      },function()
      {          
          $j(this).removeClass("menuHover");
          $j(this).find("ul.niveau2").hide();
          
      });  
          //sous menu 2
          $j("#menu li.sousmenu2").hover(function()
          { 
              $j(this).removeClass("sousmenu2");
              $j(this).addClass("menu2Hover");
              $j(this).find("ul.niveau3").show();
          },function()
          {          
              $j(this).removeClass("menu2Hover");
              $j(this).addClass("sousmenu2");
              $j(this).find("ul.niveau3").hide();
              
          });
          
     
      /*****************************************/ 
      /******* liste choix de langue************/   
                 
      //choix de langue apparition du div listLanguage quand on click sur choixlangue / disparition quand on reclick
      var statusLanguage=0;
      $j("#choixLanguage").click(function()
      {
          if(!statusLanguage){
              //$j("#IcoFleche").show(); 
              $("#listLanguage").show();              
              statusLanguage=1;
          }
          else if(statusLanguage){
            //$j("#IcoFleche").hide();
            $("#listLanguage").hide();               
              statusLanguage=0;
          }
      }); 
      //disparition de la liste quand on sort du div choixlanguage
      $j("#choixLanguage").mouseout(function()
      {
          if(statusLanguage){
              $j("#listLanguage").hide();
              statusLanguage=0;
          }      
      });
            //disparition/apparition du div listLanguage sur le li de langue hover 
            $j("#listLanguage ul li").hover(function()
            {
               $j("#listLanguage").show(); 
               $j(this).addClass("listLanguageHover");
            },function()        
            {
               $j("#listLanguage").hide();
               $j(this).removeClass("listLanguageHover"); 
               statusLanguage=0;
            });     
      /*****************************************/ 
      /*****************************************/       
      

    if ($.fn.wslide)
    {
      
      //*****************************************/
      //*** effet pager wslide sur div content ****// 
     /*  if($j("ul#pageContent").find("li").length>1)
       {
        $j('#pageContent').wslide({
            width: 520, 
            height: 200,
            duration:500,          
            horiz: true,
            autolink: 'ContentPager'       
        });
       }   */
    }
      
      
      /**************/
      /*** NEWS *****/
      /**************/      
      //galerie d'image de la news
      // sur un click dans la liste d'image on r�cup�re la src du click et on la remplace dans le visualiseur
      $j("div#iconListeLi img").click(function()
      {
        $j("#newBigImageVideo").hide();
        newsrc = $j(this).attr("src");
        if($j("#newBigImageImg img").attr("src")!=newsrc)
        {
            $j("#newBigImageImg").fadeOut("normal", function(){      
                $j("#newBigImageImg img").attr("src", newsrc);
                $j("#newBigImageImg").fadeIn();
              });
        }
      });

      /*
       * Affichage vid�o sur news
       */
      $j("#iconListe li.video img").click(function(){
        $j("#newBigImageImg").hide();
        $j('#newBigImageVideo').flash({
          flashvars: {
            mypath: $j(this).attr("longdesc")
          },
          height:   395,
          src:      LPG.flash.player,
          width:    430,
          wmode:    'transparent'
        });
        $j('#newBigImageVideo .alt').remove();
        $j('#newBigImageVideo').show();
      }); 
      
      
    var player = $f("player", {src: "http://www.lpgsystems.fr/video/flowplayer-3.1.3.swf", wmode: 'transparent'}, { 
      // flowplayer config 
    });
      
    player.load();
       
    
     if ($.fn.cycle)
    {
         $('#homePageSlider').cycle({ 
                fx:       'scrollHorz', 
                speed:    1000,
                pager: '#nav'    
         }); 
    }
    
    
    function checkPosition(position,limit)
    {
          
          /*alert("position:"+position);
          alert("limite:"+limit);   */
          
          //les cas ou on cache les boutons
               if(position == 1)
               {            
                 $j("#prevList").hide();        
               }  
               
               if(position>limit)
               {       
                 $j("#nextList").hide();
               }
               
           //les cas ou on affiche les boutons    
               if(position>1)
               {                
                 $j("#prevList").show();        
               }
               
               if(position<=limit)
               {       
                 $j("#nextList").show();
               }   
                       
    }
    
    
     if($j("#iconListeLi .image").length > 4)
      {        
      $j("#nextList").show();        
      }
      
     if($j("#iconListeLi .image").length < 2)
      {
      $j("#iconListe").hide();
      }
      
      
                                 
      //var limit = $('#iconListeLi').height() - $('#iconListe').height(); 
      
      // limit = nombre d'image dans le liste - 4 de d�part
      var nbImg =  $j("#iconListeLi .image").length;
      var limit = nbImg-4;       
      var position = 1;  
      
      checkPosition(position,limit);          
         
      $j("#nextList").click(function()
      {     
        //on v�rifie si on est pas en position de d�part
        if(parseInt($j('#iconListeLi').css("top"))<=0) {   
          $j('#iconListeLi').animate( { top:'-=76px' } , 500 );
          position++;
          checkPosition(position,limit); 
        }
      });
      
      $j("#prevList").click(function()
      {  
         if(parseInt($('#iconListeLi').css("top"))<0) {      
          $j('#iconListeLi').animate( { top:'+=76px' } , 500 );
          position--;  
          checkPosition(position,limit); 
         }   
      });
    
    
      //hover opacity sur miniImage dans le visualisator
      $j("#iconListeLi .image img").hover(function()
      { 
          $j(this).addClass("opacity");
      },function()
      {      
          $j(this).removeClass("opacity");
      });
    

      
      
      
      /********/
      // dans le listing des anciennes news
    /*if ($.fn.wslide)
    {
      if($j("ul#wslideNews").find("li").length>1)
      {
          $j('ul#wslideNews').wslide({
              width: 670, 
              height: 520,
              duration:300,          
              horiz: true,
              autolink: 'pagerNews'         
          });  
      }
    }*/

      //***********************
      /** REVUE DE PRESSE UL
       ***************************/
     if ($.fn.wslide)
     {
       if($j("ul#pressWslide").find("li").length>1)
       {
          $j('ul#pressWslide').wslide({
              width: 700, 
              height: 335,
              duration:300,        
              horiz: true,
              autolink: 'pagerPress'         
          });  
       
       }
     }

     if ($.fn.corner)
     {
       //arrondi dans les coin bas gauche et droite du div pressLayoout//
        $j('#pressLayout').corner(
        {
            tl: false,
            tr: false,
            bl: { radius: 16 },
            br: { radius: 16 },
            antiAlias: true,
            autoPad: true,
            validTags: ["div"]
        });
     }

   //lancement fonction preload d'image pour les images � charger (hover sur action) 
      preload(LPG.dir.img+"sitesLPG.gif");  
  
  
  /********************************/
  /*   Fonctions du formulaire contact
  /*
  /*******************************/
     
  $j("#divCountry > .countryunselected").click(function()
  {
      var monId = $j(this).attr('id');      
      monId = monId.substring(8);
    
       $.ajax({
                type: "post",
                url: "country.php", 
                data: "zone="+monId+"&language=FR",                        
                beforeSend:function(){                
                         $j('#StatusMsg').show();
                },
                success: function(data){
                    if(data.length >0) {  
                        $j('#divSelect').show(); 
                        $j("#StatusMsg").hide();                                         
                        $j('#select_countries').html(data);                        
                        
                        }
                    else { 
                        alert("erreur");
                        $j("#StatusMsg").hide(); 
                    } 
                }
       }); 
  });
  
 /* 
  function showJob(num) {   
        $j(".jobs").hide();          
        document.getElementById("jobs" + num).style.display = "block";
    }   */
    
    
  $j(".showJob").click(function()
  {
  
     $j(".jobs").hide(); 
     var id = $(this).attr("id");        
     
     $("#jobs"+id).show();
  
  });   
     
	// profil utilisateur et autre expandable
  $j("div.expandable").click(function () {
		$j("div.exp_content").hide('fast');
		$j(this).next().slideToggle('fast');
		// alternative: simple slideToggle.
  });
	
/*
  $j("div.expandable")
		.find('.content').hide().end()
		.find('.header').click(function () {
	  $('.content', this).slideToggle();
  }); 
*/

 
        var player = $j("player", {src: "http://www.lpgsystems.fr/video/flowplayer-3.1.3.swf", wmode: 'transparent'}, { 
      // flowplayer config 
      }); 
        
    $j("#overlayNews").attr("rel","#news93");
        
    // setup button action. it will fire our overlay 
    $j("span[rel]").overlay({
            
        // use the Apple effect for overlay
        effect: 'apple',
        expose: '#f1f1f1',
        // when overlay is opened, load our player
        onLoad: function() {
            player.load();
        },
        
        // when overlay is closed, unload our player
        onClose: function() {
            player.unload();
        }
    });    



	});//fin du onLoad
})(jQuery, LPG);