var g_licenseData = [];
g_licenseData[0] = { id: 1, name: "Dora", image : "http://www.photobykids.com/-/home/licenses/logo-dora.jpg", width: 150, height: 123, model : 45489 };
g_licenseData[1] = { id: 3, name: "Bob l'éponge", image : "http://www.photobykids.com/-/home/licenses/logo-bob.jpg", width: 150, height: 123, model : 45509 };
g_licenseData[2] = { id: 4, name: "Diego", image : "http://www.photobykids.com/-/home/licenses/logo-diego.jpg", width: 150, height: 123, model : 45508};

var footer = "<div style=\"padding-top: 30px; font-size: 120%\"><span style=\"font-weight: bold; font-size: 160%; color: #f1d431\">-15 %</span> sur tout le site avec le code <span style=\"font-weight: bold; font-size: 160%; color: #f1d431\">BONPLAN</span> !<br/><br/></div><div style=\"padding-top: 15px; font-size: 120%; line-height: 110%; color: #ffcf3c\">Pêle-mêle Toi et Moi : <span style=\"font-weight: bold; font-size: 150%\">9.90 €</span> frais d'envoi offerts<br/>au lieu de <span>16.50 €</span> avec le code promo <span style=\"font-weight: bold; font-size: 150%\">FUN</span></div>";

var g_currentProductId = null;
var g_productData = [];
g_productData["nouveautes"] = { id: 13, flash: "http://www.photobykids.com/11/-/flash/albumv2.swf", width: 540, height: 250, title: "<strong>Avec vos photos, composez des produits uniques !</strong>", text: " <strong>Personnalisez les photos de votre enfant aux couleurs<br />de l'univers de son héros préféré.<strong>" + footer , available: [1,3,4] };
g_productData["calendrier"] = { id: 13, image: "/data/shared/files/home2008/Product-View_Calendriers.jpg", title: "<strong>Calendriers</strong>", text: "<strong>Personnalisez vos calendriers</strong>&#160;!" + footer , available: [1,3,4] };
g_productData["album"] = { id: 3, image: "/data/shared/files/home2008/Product-View_AlbumsPhoto.jpg", width: 330, height: 230, title: "<strong>Albums Photo</strong>", text: "Vos albums photos personnalisés<br><strong>avec vos photos dans l'univers de votre héros préféré</strong>" + footer , available: [1,3,4] };
g_productData["tableau"] = { id : 8, image: "/data/shared/files/home2008/Product-View_Tableaux.jpg", title: "<strong>Tableaux sur toile</strong>", text: "Une véritable toile de maître<br>pour donner une autre dimension à vos photos" + footer , available: [1,3,4] };
g_productData["pelemele"] = { id: 2, image: "/data/shared/files/home2008/Product-View_PeleMele.jpg", title: "<strong>Pêle-mêle</strong>", text: "Votre enfant dans l'univers de son héros&#160;! <br>Un objet décoratif, personnalisé et unique&#160;!" + footer , available: [1,3,4] };
g_productData["invitation"] = { id: 1, image: "/data/shared/files/home2008/Product-View_CartonsdInvitation.jpg", title: "<strong>Cartons d'invitation</strong>", text: "<strong>Invitations d'anniversaire personnalisées</strong><br>Personnalisez chaque invitation avec votre photo et le prénom de chaque invité : Effet garanti&#160;!" + footer , available: [1,3,4] };
g_productData["carte"] = { id: 11, image: "/data/shared/files/home2008/Product-View_CartesPostales.jpg", title: "<strong>Cartes postales</strong>", text: "Créez vos cartes postales<br><strong>DORA, Bob l'Eponge et Diego</strong><br> avec votre propre photo&#160;!<br>Surprenez ainsi famille et amis&#160;!" + footer , available: [1,3,4] };
g_productData["poster"] = { id: 5, image: "/data/shared/files/home2008/Product-View_Posters.jpg", title: "<strong>Posters</strong>", text: "<strong>Posters personnalisés</strong><br>Unique pour vos enfants : <strong><br>leurs photos avec celles de leurs héros</strong>. <br>Une décoration de rêve&#160;!" + footer , available: [1,3,4] };
g_productData["toietmoi"] = { id: 12, image: "/data/shared/files/home2008/Product-View_PeleMeleTM.jpg", title: "<strong>Pêle-mêle &quot;Toi et moi&quot;</strong>", text: "Ton héros et toi, <br>en tête à tête&#160;!" + footer , available: [1,3,4] };
g_productData["cartedevisite"] = { id: 14, image: "/data/shared/files/home2008/Product-View_CartesDeVisite.jpg", title: "<strong>Cartes de visite</strong>", text: "Les premières cartes de visite de votre enfant, <br>avec sa photo&#160;!" + footer , available: [1,3,4] };
g_productData["cartedevoeux"] = { id: 15, image: "/data/shared/files/home2008/Product-View_CartesDeVoeux.jpg", title: "<strong>Cartes de voeux</strong>", text: "Souhaitez vos <strong>voeux 2008</strong> <br>avec le héros préféré de vos enfants&#160;!" + footer , available: [1,3,4] };
g_productData["marquepages"] = { id: 15, image: "/images/Product-View_MarquePage.jpg", title: "<strong>Marque-pages</strong>", text: "Créez des marque-pages uniques<br />et ne perdez plus jamais le fil de vos histoires&#160;!" + footer , available: [1,3,4] };


function getProductByNumericId(nid)
{
   for (id in g_productData)
   {
      if (g_productData[id].id == nid)
         return g_productData[id];
   }

   return null;
}

function displayProduct(productId)
{
document.getElementById("cadreflash").style.display = (productId == "nouveautes" ? "block" : "none");


if (g_currentProductId == productId)
      return true;

   g_currentProductId = productId;

   var data = g_productData[productId];

   var imgElt = document.getElementById("product-view-image");
   var textElt = document.getElementById("product-view-text");
   var titleElt = document.getElementById("product-view-title");

   if (!data)
   {
      imgElt.style.backgroundImage = "";
      imgElt.innerHTML = "";
      textElt.innerHTML = "(no data)";

      return false;
   }

   if (data.flash)
   {
      imgElt.style.backgroundImage = "";

      var so = new SWFObject(data.flash, "product_view_flash", data.width, data.height, "8", null);

      if (!so.write("product-view-image"))
         HTMLUtils.redirect(document, "/page.php?id=NoFlash");
   }
   else if (data.image)
   {
      imgElt.style.backgroundImage = "url(" + data.image + ")";
      imgElt.onclick = function() { goProduct(); };
      imgElt.innerHTML = "";
   }
   else
   {
      imgElt.style.backgroundImage = "";
      imgElt.innerHTML = "";
   }

   textElt.innerHTML = data.text;
   titleElt.innerHTML = data.title;

   return true;
}

function goProduct(productId, offer, modelId)
{
   if (g_currentProductId == null && !productId)
      return false;
   else if (!productId)
      productId = g_currentProductId;

   var data = g_productData[productId];

   if (!data)
      return false;

   if (modelId)
      var dlg = new LicenseDialog(data.id, offer, modelId);
   else
      var dlg = new LicenseDialog(data.id, offer);

   dlg.show();

   return true;
}

function showCCMVideo()
{
   var dlg = new MediaDialog(IDM.MediaDialog.TYPE_FLASH, "/data/shared/files/ccm-pbk.swf", 400, 300);
   dlg.show();
}

function init()
{
   displayProduct("nouveautes");

   var intro = new SWFObject("/data/shared/files/home2008/presentation.swf", "intro", 190, 60, "8", null);
   intro.addParam("wmode", "opaque");
   intro.addParam("scale", "noscale");
   intro.write("intro-text");
}

HTMLUtils.addOnLoadFunction(init);

function LicenseDialog(productId, offer)
{
   IDM.Dialog.call(this);

   this.setButtons([ IDM.Dialog.Button.CANCEL ]);
   this.setTitle("Choisis ton héros préféré !");

   this.m_productId = productId;
   this.m_offer = offer;
}

LicenseDialog.prototype = new IDM.Dialog();

LicenseDialog.prototype._constructInner = function(contElt, boxElt)
{
   boxElt.style.textAlign = "center";

   if (this.m_offer)
   {
      var dlgTitleElt = HTMLUtils.getChildElement(boxElt, null, "title", true);

      var titleElt = document.createElement("div");
      titleElt.className = "title";
      titleElt.innerHTML = "Comment bénéficier de cette offre exceptionnelle ?";

      var introElt = document.createElement("div");
      introElt.innerHTML = "Lors de votre inscription à notre newsletter, votre compte sera<br/>"
         + "<strong>automatiquement crédité de 20 cartes de visite</strong> offertes (hors frais de port).<br/>"
         + "Vous n'aurez alors plus qu'à composer le modèle de votre choix. Le prix de vos<br/>"
         + "cartes de visite sera automatiquement déduit de votre commande.<br/><br/>";

      boxElt.insertBefore(introElt, dlgTitleElt);
      boxElt.insertBefore(titleElt, introElt);
   }

   for (var i = 0, n = g_licenseData.length ; i < n ; ++i)
   {
      var licData = g_licenseData[i];

      var imgElt = document.createElement("img");
      imgElt.className = "clickable-control";
      imgElt.src = licData.image;
      imgElt.onclick = JSUtils.makeCallback(this, LicenseDialog.prototype._onClickedLicense, licData.id);
      imgElt.style.margin = "0 5px";
      imgElt.align = "absmiddle";
      imgElt.width = licData.width;
      imgElt.height = licData.height;
      imgElt.style.visibility = "visible";
      boxElt.appendChild(imgElt);
   }
}

LicenseDialog.prototype._onClickedLicense = function(licenseId)
{
   HTMLUtils.redirect(document, "http://www.photobykids.com/shop/shop.php?sid=" + licenseId + "&partnerid=1&product=" + this.m_productId);
}