$(document).ready
  (
    function()
    {
      init_bouton();
      init_box();
      init_pub(document.location.href);
    }
  );

function init_box()
{
  $("div.roundbox").wrap('<div class="dialog"><div class="bd"><div class="c"><div class="s"></div></div></div></div>');

  $('div.dialog').prepend('<div class="hd"><div class="c"></div></div>').append('<div class="ft"><div class="c"></div></div>');
}

function init_bouton()
{
  $(".jqbouton").each(function(i) {
      var old = $(this).html();
      $(this).html("<table id='bt_"+i+"' class='jqbouton' cellpadding=0 cellspacing=0><tr><td class='centre' nowrap>"+old+"</td><td class='droite'><div>&nbsp;</div></td></tr></table>");
      $('#bt_'+i).bind("mouseenter mouseleave", function(e) {$(this).toggleClass('jqboutonON');})
    }
  );

 // $('div.dialog').prepend('<div class="hd"><div class="c"></div></div>').append('<div class="ft"><div class="c"></div></div>');
}



/*
 *
 * Zones pub
 *
 */
var timer_pub;
var current_pub = new Array();
function init_pub(ref_url)
{
    var fic_pub = new Array();
    var liste_cc = new Array();
    $.getScript("http://www2.camping.fr/Pubs/choix-pub-script_200912092226.php?ref_url="+escape(ref_url), function(){
    fic_pub = get_array_pubs();
    liste_cc = get_liste_cc();
    if(current_pub["cc"] != liste_cc['hash'])
    {
      var code_cc = '';
      for(var i = 0; i < liste_cc['prio'].length; i++) {code_cc += liste_cc['prio'][i];}
      for(var i = 0; i < liste_cc['seco'].length; i++) {code_cc += liste_cc['seco'][i];}
      $("#coups_de_coeur").html(code_cc);
      current_pub["cc"] = liste_cc['hash'];
    }
      if(fic_pub["haut"]) {
	if(current_pub["haut"] != fic_pub["haut"][0]) {
	  $("#pub_haut").html("<IFRAME Marginwidth='0' marginheight='0' hspace='0' vspace='0' frameborder='0' scrolling='no' bordercolor='#000000' SRC='http://www2.camping.fr/Pubs/"+fic_pub["haut"][0]+"'></IFRAME>");
	  current_pub["haut"] = fic_pub["haut"][0];
	}
      }
      if(fic_pub["bas"]) {
	if(current_pub["bas"] != fic_pub["bas"][0]) {
	  $("#pub_bas").html("<IFRAME Marginwidth='0' marginheight='0' hspace='0' vspace='0' frameborder='0' scrolling='no' bordercolor='#000000' SRC='http://www2.camping.fr/Pubs/"+fic_pub["bas"][0]+"'></IFRAME>");
	  current_pub["bas"] = fic_pub["bas"][0];
	}
      }
      if(fic_pub["sky1"]) {
	if(current_pub["sky1"] != fic_pub["sky1"][0]) {
	  $("#pub_sky1").html("<IFRAME Marginwidth='0' marginheight='0' hspace='0' vspace='0' frameborder='0' scrolling='no' bordercolor='#000000' SRC='http://www2.camping.fr/Pubs/"+fic_pub["sky1"][0]+"'></IFRAME>");
	  current_pub["sky1"] = fic_pub["sky1"][0];
	}
      }
      if(fic_pub["sky2"]) {
	if(current_pub["sky2"] != fic_pub["sky2"][0]) {
	  $("#pub_sky2").html("<IFRAME Marginwidth='0' marginheight='0' hspace='0' vspace='0' frameborder='0' scrolling='no' bordercolor='#000000' SRC='http://www2.camping.fr/Pubs/"+fic_pub["sky2"][0]+"'></IFRAME>");
	  current_pub["sky2"] = fic_pub["sky2"][0];
	}
      }

      if(fic_pub["vign125"])
      {
	var tmp_to_compare = '';
	for(var i = 0; i < fic_pub["vign125"].length; i++)
	{
	  tmp_to_compare += fic_pub["vign125"][i];
	}
	if(tmp_to_compare != current_pub["vign125"]) {
	  fic_pub["vign125"] = fic_pub["vign125"].shuffle();
	  var code125='';
	  for(var i = 0; i < fic_pub["vign125"].length; i++)
	  {
	    code125 += "<center><div id='pub_vign_125' class='vignette125x125'><IFRAME height='125' width='125' Marginwidth='0' marginheight='0' hspace='0' vspace='0' frameborder='0' scrolling='no' bordercolor='#000000' SRC='http://www2.camping.fr/Pubs/"+fic_pub["vign125"][i]+"'></IFRAME></div></center>";
	  }
	  current_pub["vign125"] = tmp_to_compare;
	  $("#pub_vign_125").html(code125);
	}
      }
    });
}
