var text = "1";
var Text1 = "Son-Vidéo.com : le meilleur rapport émotion/prix !";
var Text2 = "Commande par téléphone au 0826 960 290 - Expédition sous 24h";
var place = 1;

function scrollIn() {
	if (text == "1") {
		var Message = Text1;
	} else {
		var Message = Text2;
	}
	window.status = Message.substring(0, place);
	if (place >= Message.length) {
		place = 1;
		window.setTimeout("scrollOut()", 10000);
	} else {
		place++;
		window.setTimeout("scrollIn()", 0);
	}
}

function scrollOut() {
	if (text == "1") {
		var Message = Text1;
	} else {
		var Message = Text2;
	}
	window.status = Message.substring(place, Message.length);
	if (place >= Message.length) {
		if (text == "1") {
			text = "2";
		} else {
			text = "1";
		}
		place = 1;
		window.setTimeout("scrollIn()", 1000);
	} else {
		place++;
		window.setTimeout("scrollOut()", 0);
	}
}

scrollIn();

function get_bookmarks()
{
  var url = encodeURIComponent(document.location);
  var titre = encodeURIComponent(document.title);
  var tab = new Array();
  //Mail
  tab.push(new Array('Envoyer', 'mail', "GetPopin('mail');", 'js'));
  //Favoris
  tab.push(new Array('Favoris', 'favoris', "favoris();", 'js'));
  //Imprimer
  tab.push(new Array('Imprimer', 'print', "print();", 'js'));  
  //google favoris
  tab.push(new Array('Google', 'google', "http://www.google.com/bookmarks/mark?op=add&bkmk="+url+"&title="+titre+"&annotation=", 'classic'));
   //facebook
  tab.push(new Array('Facebook', 'facebook', "http://www.facebook.com/sharer.php?u="+url+"&t="+titre, 'classic'));
  //myspace
  tab.push(new Array('MySpace','myspace', "http://www.myspace.com/Modules/PostTo/Pages/?u="+url+"&t="+titre+"&c=", 'classic'));
  //Windows live
  tab.push(new Array('Windows live', 'live', "https://skydrive.live.com/sharefavorite.aspx%2f.SharedFavorites??marklet=1&mkt=FR_fr&url="+url+"&title="+titre+"&top=1&wa=wsignin1.0", 'classic'));
  //twitter
  tab.push(new Array('Twitter','twitter', "http://twitter.com/home?status="+titre+",%20"+url, 'classic'));
  //plaxo
  tab.push(new Array('Plaxo', 'plaxo', "http://www.plaxo.com/events?share_link=+url&desc="+titre, 'classic'));
  //netvibes
  tab.push(new Array('NetVibes','netvibes', "http://www.netvibes.com/share?url="+url+"&title="+titre, 'classic'));
  
  var Node = document.getElementById("ulmenuPartager");
  while(Node.hasChildNodes() == true) {
    Node.removeChild(Node.firstChild);
  }

  for(var i=0; i != tab.length; i++)
  {
     var li = document.createElement("li");
     li.className = tab[i][1];
     a = '<a href="'
     a += (tab[i][3] == 'classic') ? tab[i][2]+'"': '#"';
     if(tab[i][3] == 'classic')
     {
      a  += ' target="_blank"';
     }
     else
     {
      a  += ' onclick="'+tab[i][2]+'"';
     }
     a += '>'+tab[i][0]+'</a>';
     li.innerHTML = a;
     Node.appendChild(li);
  }
  Node.innerHTML += "<div class='spacer'>&#160;</div>";
}

function GetPopin(nom)
{  
  var xmlHttp = getXmlHttpObject();
  if (xmlHttp == null)
  {
    alert("Votre navigateur ne supporte pas les requêtes HTTP.");
    return false;
  }

  xmlHttp.onreadystatechange = function (){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
    {
      var response = xmlHttp.responseText;
      if(nom == 'mail')
      {
      	response = response.replace(new RegExp("##URL##","g"), document.location);
      	response = response.replace(new RegExp("##NOM_PAGE##","g"), document.title);
      }
      GetId('PhC_CMS_PopIn_Contenu').innerHTML = response;
		  centerPopin('PhC_CMS_PopIn');
		  GetId('PhC_CMS_PopIn').style.visibility = 'visible';
    }
  }
  
  xmlHttp.open("POST", "/Parts/Popin/"+nom+".html", true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.send("action=get");
  
}

function closePopin()
{
      GetId('PhC_CMS_PopIn').style.visibility = 'hidden';
      GetId('PhC_CMS_PopIn_Contenu').innerHTML = '';
}

function chargerCSS(fichier){  
    var headID = document.getElementsByTagName("head")[0];  
    var cssNode = document.createElement('link');   
       cssNode.type = 'text/css';  
       cssNode.rel = 'stylesheet';  
       cssNode.href = fichier;  
       cssNode.media = 'screen';
       headID.appendChild(cssNode);  
}  

chargerCSS('/css/criteo.css?'+Math.random());

function GetId(id) {
	return document.getElementById(id);
}

var browserDetection = ( function() {
  var u = navigator.userAgent; var e = /*@cc_on!@*/false;
  var c = {
    // Browsers
    ie    : e,
    firefox : /firefox/i.test(u),
    opera : /opera/i.test(u),
    chrome  : /chrome/i.test(u),
    safari  : /safari/i.test(u) && !/chrome/i.test(u)
  }
  try {
    if (c.ie) 
      c.ie = /msie\s([^;]+)/i.exec(u)[1];
    else if (c.firefox)
      c.firefox = /firefox\/([^\s]+)/i.exec(u)[1];
    else if (c.opera)
      c.opera = /opera\/([^\s]+)/i.exec(u)[1];
    else if (c.chrome)
      c.chrome = /chrome\/([^\s]+)/i.exec(u)[1];
    else if (c.safari)
      c.safari = /version\/([^\s]+)/i.exec(u)[1];
  } catch(e) {}

  this.client = c;
})();


function centerPopin(myId) {
  result=returnSize();
  var myWidth=result[0];
  var myHeight=result[1];
  var elementWidth=document.getElementById(myId).offsetWidth;
  var elementHeight=document.getElementById(myId).offsetHeight;
  var myScrollLeft=document.documentElement.scrollLeft;
  var myScrollTop= (window.scrollY > 0) ? window.scrollY : document.documentElement.scrollTop;
  var posX=myScrollLeft+myWidth-myWidth/2-elementWidth/2
  var posY=myScrollTop+myHeight-myHeight/2-elementHeight/2;
  document.getElementById(myId).style.left=posX+"px";
  document.getElementById(myId).style.top=posY+"px";
}

function returnSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var result = new Array(myWidth,myHeight);
  return result;
}

window.onDomReady = DomReady;

//Setup the event
function DomReady(fn)
{
  //W3C
  if(document.addEventListener)
  {
    document.addEventListener("DOMContentLoaded", fn, false);
  }
  //IE
  else
  {
    document.onreadystatechange = function(){
      if(document.readyState == "complete")
        {
          fn(); } 
        }
  }
}
