﻿var spacer = "../_elements/_library/images/espaceur.gif";
//var slides = ["../_data/home/leg1_arrival_3.jpg","../_data/home/leg1_arrival_6.jpg","../_data/home/leg1_arrival_1.jpg","../_data/home/logo.jpg"];
//var slides = ["../_data/home/ier_8.jpg","../_data/home/leg_1_onboard_1.jpg","../_data/home/leg_2_start.jpg","../_data/home/leg_1_onboard_2.jpg"];
//var slides = ["../_data/home/leg2_arrival_1.jpg","../_data/home/leg2_arrival_3.jpg","../_data/home/leg2_arrival_4.jpg","../_data/home/leg2_arrival_5.jpg","../_data/home/logo.jpg"];
//var slides = ["../_data/home/leg_2_prices.jpg","../_data/home/design_1.jpg","../_data/home/design_2.jpg","../_data/home/design_3.jpg","../_data/home/design_4.jpg","../_data/home/design_5.jpg","../_data/home/design_6.jpg","../_data/home/design_7.jpg","../_data/home/logo.jpg"];
//var slides = ["../_data/home/leg_3_start_1.jpg","../_data/home/leg_3_start_2.jpg","../_data/home/leg_3_start_3.jpg","../_data/home/leg_3_start_7.jpg","../_data/home/leg_3_start_4.jpg","../_data/home/leg_3_start_8.jpg","../_data/home/leg_3_start_6.jpg","../_data/home/leg_3_start_9.jpg","../_data/home/leg_3_start_11.jpg"];
//var slides = ["../_data/home/leg_3_arrival_1.jpg"];
var slides = ["../_data/home/ier_2.jpg","../_data/home/ier_5.jpg","../_data/home/leg1_arrival_2.jpg","../_data/home/leg_1_onboard_1.jpg","../_data/home/leg_1_onboard_2.jpg","../_data/home/leg_2_start.jpg","../_data/home/design_7.jpg","../_data/home/leg_3_start_1.jpg","../_data/home/leg_3_start_3.jpg","../_data/home/leg_3_start_6.jpg","../_data/home/leg_3_onboard_1.jpg","../_data/home/leg_3_arrival_1.jpg"];
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", "0xE4DBC2");
					countdown.addFlashVars("transparency", "0.2");
					countdown.addFlashVars("targetTime", targetTime);
					countdown.addFlashVars("serverTime", serverTime);
					countdown.addFlashVars("frequency", "17");
					countdown.addFlashVars("format", format);

					countdown.writeObject();
		}
		/* ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	},
	/* 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://istanbuleuroparace.geovoile.com/?e="+leg+"&lg="+lg,"istanbuleuroparaceMapPopup","width=960,height=600,resizable=1,scrollbars=0");
			website.map.popup.focus();
		}
	}
	/* ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
}
hws.dom.addEvent(window,"load", website.init);
