/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function display_home_pub(){
    var deja_venu = lire_cookie("deja_venu");
    if(deja_venu != "oui"){
        if(document.getElementById('homepub')){

            var windowWidth = $('body').width();
            var windowHeight = $('body').height();

            var popupWidth = $('#homepub').width();
            var popupHeight = $('#homepub').height();

            var leftPosition = windowWidth/2-popupWidth/2;
            var topPosition = -1*popupHeight-10;

            $('#homepub_bg').css('width', windowWidth);
            $('#homepub_bg').css('height', windowHeight);
            $('#homepub_bg').css('position', 'absolute');
            $('#homepub_bg').css('top', 0);
            $('#homepub_bg').css('left', 0);
            $('#homepub_bg').css('z-index', 90);

            $("#homepub_bg").animate({
              opacity: 0.4,
              backgroundColor: "#000000"
            }, 1000 );

            $('#homepub').css('left', leftPosition);
            $('#homepub').css('top', topPosition);

            $("#homepub").animate({
              top: 0
            }, 1000 );
        }
    }
}

function hide_home_pub(){

    ecrire_cookie("deja_venu", "oui");

    var popupHeight = $('#homepub').height();
    var topPosition = -1*popupHeight-10;

    $("#homepub").animate({
      top: topPosition
    }, 1000 );

    $("#homepub_bg").animate({
      opacity: 0,
      display: 'none'
    }, 1000 );

    setTimeout("$('#homepub_bg').css('display', 'none')",1000);
    //;
}

function ecrire_cookie(nom, valeur, expires) {
  document.cookie=nom+"="+escape(valeur)+
  ((expires==null) ? "" : ("; expires="+expires.toGMTString()));
}

function arguments_cookie(offset){
  var endstr=document.cookie.indexOf (";", offset);
  if (endstr==-1) endstr=document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function lire_cookie(nom) {
  var arg=nom+"=";
  var alen=arg.length;
  var clen=document.cookie.length;
  var i=0;
  while (i<clen){
    var j=i+alen;
    if (document.cookie.substring(i, j)==arg)
       return arguments_cookie(j);
    i=document.cookie.indexOf(" ",i)+1;
    if (i==0) break;
  }
  return null;
}


$(document).ready(function(){
    display_home_pub();
});
