
function recordAdsLink(link, object, name) {
  try {
    setEventGA(object, 'Cliquer publicite', name);
    setTimeout('window.open(link.href, "_blank")', 100);
  }
  catch(err){}
}

function applyHomeLink()
{
  $(".home_link").hover(function(){
    $("#house_menu").slideDown("fast");
    $(".home_link").prev().children("ul").fadeOut("fast");
    $(".home_link").siblings().children("ul").fadeOut("fast");
  },
  function(){
    $("#house_menu").slideUp("fast");
  });
}

// Permet d'enregistrer les images issus de la kazacolor en mode non connectée
function applyKazacolorUpload(route)
{
  var collectionImage = $.jStorage.get('collectionImage');
  var readyForUpload = $.jStorage.get('kk_ready_for_upload');
  
  if (collectionImage && (readyForUpload == 1)) {
    var html = '<div style="margin: 60px auto; width: 350px; height: 50px;">';
    html += '<div style="text-align: center;"><img src="/images/bar-loader.gif" alt="Loading" alt="loader" /></div>';
    html += '<p style="text-align: center;">Merci de patienter pendant le téléchargement des photos</p>';
    html += '</div>';
    goToHtml(html);
     $.ajax({
     type: "get",
     dataType: "json",
     url: route + "?collectionImage=" + collectionImage + "&json=1",
     success: function(msg){
       if(msg["route"] && msg["message"])
       {
          $.jStorage.deleteKey('collectionImage');
          $.jStorage.deleteKey('kk_ready_for_upload');
          $.jStorage.flush();
          $.jStorage.reInit();
          location.href = msg["route"];
       }
       
     }
    });
    
    //goTo(, true, );
  }
}

function applyAuthenticated(isAuth, route) 
{
  $('.authenticated').click(function(){
   var url = $(this).attr('href');
   var urlRoute = '';
   if(url==undefined){url = $(this).find('a').attr('href');}
   if(url!=undefined && !$(this).hasClass('nofollow')){urlRoute = "?route="+escape(url)}
    
    if (!isAuth) {goTo(route+urlRoute,true,"620px", "260px", false, false);}

    if($(this).hasClass('colorbox') && isAuth) {
      goTo($(this).attr('href'));
    }
    else if (isAuth) {return true;}
    return false;
  });
}

function applyColorBox(route)
{
  $('.generic_colorbox').live('click', function(){
    goTo($(this).attr('href'));
    return false;
  });
  $('.not_logged_in_colorbox').live('click', function(){
   var url = $(this).attr('href');
   var urlRoute = '';
   if(url==undefined){url = $(this).find('a').attr('href');}
   if(url!=undefined && !$(this).hasClass('nofollow')){urlRoute = "?route="+escape(url)}

    goTo(route+urlRoute, true, "620px", "260px", false, false);
    return false;
  });

   $('.generic_colorbox_iframe').live('click', function(){
    goTo($(this).attr('href'),true,"550px","520px");
    return false;
  });

  $('.generic_colorbox_scrollbar').live('click', function(){
    goTo($(this).attr('href'), false, "550px", "520px", true);
    return false;
  });
}

function setEventGA(objectGA, actionGA, labelGA, valueGA, trackerName)
{
   if(typeof(objectGA) != 'undefined' && typeof(actionGA) != 'undefined')
   {
    var tracker = trackerName;
    if (typeof(trackerName) == 'undefined') {
      tracker = "_testlocal._trackEvent";
    } else if (trackerName == "social") {
      tracker = "_testlocal._trackSocial";
    }
    if(!valueGA && !labelGA) {
      _gaq.push([tracker, objectGA, actionGA]);
    }
    else if (!valueGA){
      _gaq.push([tracker, objectGA, actionGA, labelGA]);
    }
    else
    {
      _gaq.push([tracker, objectGA, actionGA, labelGA, valueGA]);
    }
    //console.log("tracker:" + tracker + "\nObjectGA:" + objectGA + "\nactionGA:" + actionGA + "\nlabelGA:" + labelGA + "\nvalueGA:" + valueGA);
   }
}
function goToHtml(html)
{
  goTo(false,false,false,false,false,false,false,false,false, false,html);
}

function goTo(url,oiframe,owidth,oheight,oscroll,oinline,close_callback,cleanup_callback,complete_callback, bOverlay_close, oClose)
{
  if(!oiframe)
    oiframe = false;
   if(!oscroll)
    oscroll = false;
  if(!owidth)
    owidth = false;
  if(!oheight)
    oheight = false;
  if(!oinline)
    oinline = false;
  if(!oClose)
    oClose = false;
  if(!close_callback)
    close_callback = function(){return true};
  if(!cleanup_callback)
    cleanup_callback = function(){return true};
  if(!complete_callback)
    complete_callback = function(){return true};
  if(!bOverlay_close)
    bOverlay_close = false;

  $.colorbox({fixed:false,href: url ,html: oClose, overlayClose: bOverlay_close, scrolling : oscroll, iframe: oiframe, width: owidth, onClosed: close_callback, onCleanup: cleanup_callback, onComplete: complete_callback, height: oheight, opacity: '.6', inline: oinline});
}

// Si on clique en dehors de la colorbox ou qu'on l'a ferme alors le localStorage est remis à 0
$("#cboxContent #cboxClose").live('click', function(e) {
  $.jStorage.flush();   // Vide
  $.jStorage.reInit();  // Reinitialise
});

