﻿var spacer = "../_elements/_library/images/espaceur.gif";
var slides = new Array();
var slidesOk = false;
try {
  var testSlides = staticSlides[0];
  slidesOk = true;
} catch (e) {
}
if (!slidesOk) {
  slides.push("../_data/home/default.jpg");
} else {
  for (var i = 0; i < staticSlides.length; i++) {
    slides.push(staticSlides[i]);
  }
  randomSlides.sort(function (a, b) { return Math.random() * 2 - 1 });
  for (var i = 0; i < randomSlides.length; i++) {
    slides.push(randomSlides[i]);
  }
}
var slideShow;
/* package ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
var website = {
  /* function //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  init: function () {
    setTimeout("slideShow.start()", 2000);
  },
  /* function //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  initSlideShow: function () {
    slideShow = new website.SlideShow("slideShow", "headSlideshow", slides, 3, 40, 1, false);
  },
  /* package /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  quadratic: {
    /* function //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
    easeIn: function (t, b, c, d) {
      return c * (t /= d) * t + b;
    },
    /* function //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
    easeOut: function (t, b, c, d) {
      return -c * (t /= d) * (t - 2) + b;
    },
    /* function //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
    easeInOut: function (t, b, c, d) {
      if ((t /= d / 2) < 1) return c / 2 * t * t + b;
      return -c / 2 * ((--t) * (t - 2) - 1) + b;
    }
    /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  },
  /* class /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  SlideShow: function (varName/*String*/, containerId/*String*/, source/*Array od String*/, durationSec/*Number*/, frequency/*Number*/, suspendSec/*Number*/) {
    this.varName = varName;
    this.container = document.getElementById(containerId);
    this.container.innerHTML = "<img id='slide0' style='position:absolute' src='" + spacer + "' /><img id='slide1' style='position:absolute' src='" + spacer + "' /><img id='slide2' style='position:absolute' src='" + spacer + "' />"
    this.initSlide = document.getElementById("slide0");
    this.bottomSlide = document.getElementById("slide1");
    this.topSlide = document.getElementById("slide2");
    this.duration = durationSec || 3;
    this.frequency = frequency || 40;
    this.suspend = suspendSec * 1000 || 3;
    this.slides = new Array();
    for (var i = 0; i < source.length; i++) {
      if (i == 0) {
        this.initSlide.src = source[i];
        this.topSlide.src = source[i];
      }
      if (i == 1) this.bottomSlide.src = source[i];
      this.slides.push(new website.Slide(this, source[i]));
    }
    this.activeSlide = this.slides[0];
    this.activeSlideNum = 1 % this.slides.length;
    if (!website.SlideShowInitOK) {
      /* Initialisation des méthodes publiques................................................................................................................................................................................................................................................................................................................*/
      website.SlideShow.prototype.start = function () {
        this.displaySlide(this.slides[this.activeSlideNum]);
        this.activeSlideNum = (this.activeSlideNum + 1) % this.slides.length;
      }
      /* .......................................................................................................................................................................................................................................................................................................................................................*/
      website.SlideShow.prototype.displaySlide = function (slide) {
        if (this.activeSlide) this.activeSlide.display(this.bottomSlide, 100);
        this.activeSlide = slide;
        this.activeSlide.display(this.topSlide, 0);
        setTimeout(this.varName + ".activeSlide.startAlpha(" + this.duration + "," + this.frequency + "," + this.suspendSlide + ")", 1000);
      };
      /* .......................................................................................................................................................................................................................................................................................................................................................*/
      website.SlideShow.prototype.suspendSlide = function () {
        setTimeout(this.slideShow.varName + ".start()", window[this.slideShow.varName].suspend);
      }
      /* .......................................................................................................................................................................................................................................................................................................................................................*/
      website.SlideShowInitOK = true;
    }
  },
  /* class /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  Slide: function (slideShow/*Slideshow*/, imagePath/*String*/) {
    this.slideShow = slideShow;
    this.image = new Image();
    this.image.src = imagePath;
    this.imageIsEmpty = false;
    this.t = 0;
    this.container = null;
    this.callBack = null;
    this.duration = 3;
    this.frequency = 40;
    if (!website.SlideInitOK) {
      /* Initialisation des méthodes publiques................................................................................................................................................................................................................................................................................................................*/
      website.Slide.prototype.toString = function () {
        return this.image.src;
      }
      /* .......................................................................................................................................................................................................................................................................................................................................................*/
      website.Slide.prototype.laodImage = function (state) {
        this.container.src = state > 0 ? this.image.src : spacer;
        this.imageIsEmpty = !state;
      }
      /* .......................................................................................................................................................................................................................................................................................................................................................*/
      website.Slide.prototype.display = function (container, opacity) {
        this.container = container;
        this.container.style.visibility = opacity > 0 ? "visible" : "hidden";
        this.container.style.top = opacity > 0 ? "0px" : "-300px";
        this.container.style.opacity = new String(opacity / 100);
        this.container.style.filter = "alpha(opacity=" + opacity + ")";
        this.laodImage(opacity > 0);
        this.t = 0;
      }
      /* .......................................................................................................................................................................................................................................................................................................................................................*/
      website.Slide.prototype.startAlpha = function (duration, frequency, callback) {
        this.callBack = callback;
        this.duration = duration || 3;
        this.frequency = frequency || 40;
        this.t = 0;
        this.alpha();
      }
      /* .......................................................................................................................................................................................................................................................................................................................................................*/
      website.Slide.prototype.alpha = function () {
        var opacity = Math.round(website.quadratic.easeOut(this.t++, 0, 100, this.duration * (1000 / this.frequency)));
        if (opacity > 0 && this.imageIsEmpty) this.laodImage(true);
        this.container.style.visibility = opacity > 0 ? "visible" : "hidden";
        this.container.style.top = opacity > 0 ? "0px" : "-300px";
        this.container.style.opacity = new String(opacity / 100);
        this.container.style.filter = "alpha(opacity=" + opacity + ")";
        if (opacity < 99) {
          setTimeout(this.slideShow.varName + ".activeSlide.alpha()", this.frequency);
        } else {
          this.container.style.opacity = "1";
          this.container.style.filter = "alpha(opacity=100)";
          this.callBack.call();
        }
      }
      /* .......................................................................................................................................................................................................................................................................................................................................................*/
      website.SlideInitOK = true;
    }
  },
  /* package ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  countdown: {
    object: null,
    /* function ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
    write: function (source/*String path to swf*/, targetTime/*String date YMDHMS*/, serverTime/*String date YMDHMS*/, format/*HTML String*/) {
      var countdown = website.countdown.object = new hws.document.FlashCode(source);
      countdown.id = "countdown";
      countdown.width = "250";
      countdown.height = "43";
      countdown.addFlashVars("color", "0x3F4349");
      countdown.addFlashVars("transparency", "1");
      countdown.addFlashVars("targetTime", targetTime);
      countdown.addFlashVars("serverTime", serverTime);
      countdown.addFlashVars("frequency", "17");
      countdown.addFlashVars("format", format);

      countdown.writeObject();
    }
    /* ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  },
  /* package ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  partners: {
    tdPartners: new Array(),
    numPartner: -1,
    /* function ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
    init: function (nbCells/*int*/) {
      partners.sort(function (a, b) { return Math.random() * 2 - 1 });
      website.partners.numPartner = -1;
      for (var i = 0; i < nbCells; i++) {
        website.partners.tdPartners.push(document.getElementById("tdPartner" + (i + 1)));
      }
    },
    /* function ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
    start: function () {
      nbCells = website.partners.tdPartners.length;
      if (nbCells > 0) {
        setInterval("website.partners.display(website.partners.tdPartners[0]);", 5000);
        for (var i = 0; i < nbCells; i++) {
          website.partners.display(website.partners.tdPartners[i]);
          if (i > 0) setTimeout("setInterval('website.partners.display(website.partners.tdPartners[" + i + "]);',5000);", 2000 * i);
        }
      }
    },
    /* function ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
    display: function (target) {
      website.partners.numPartner = ((website.partners.numPartner + 1) % partners.length);
      var currentPartner = partners[website.partners.numPartner];
      target.innerHTML = "<a href='" + currentPartner.url + "' target='_blank'><img src='" + currentPartner.logo + "' alt='" + currentPartner.name + "'></a>";
    }
    /* ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  },
  /* package ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  times: {
    /* function ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
    update: function () {
      var d = new Date();
      for (var i = 0; i < 2; i++) {
        document.getElementById("time" + i).innerHTML = d["to" + (i == 0 ? "UTC" : "Locale") + "String"]().match(new RegExp("\\d{2}:\\d{2}:\\d{2}", "gi"))[0];
      }
      setTimeout('website.times.update();', 1000);
    }
  },
  /* package ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
  map: {
    popup: null,
    open: function (lg, leg) {
      if (!leg) var leg = "";
      website.map.popup = window.open("http://capistanbul.geovoile.com/2010/?leg=" + leg + "&lg=" + lg, "istanbuleuroparaceMapPopup", "width=990,height=700,resizable=1,scrollbars=0");
      website.map.popup.focus();
    }
  }
  /* ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
}
hws.dom.addEvent(window,"load", website.init);

