﻿/********************************************************************\
    Configuration
\********************************************************************/

function getBaseUrl()
{
	return "/";
}

// page init
window.onload = function()
{
    initSlideShow();    
}

var ss;
function initSlideShow()
{
    if(document.getElementById("slideshow") != null)
    {
        var slideBaseUrl = getBaseUrl() + "web/img/slideshow/";
        
        ss = new SlideShow("ss", document.getElementById("ssImage"));
        ss.Label = document.getElementById("ssLabel");
        ss.PlayPauseButton = document.getElementById("ssPlayPauseButton");
        ss.PlayImageUrl = getBaseUrl() + "web/img/commons/btn-play.gif";
        ss.PauseImageUrl = getBaseUrl() + "web/img/commons/btn-pause.gif";
        
        ss.AddSlide(new Slide(slideBaseUrl + "ss01.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss02.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss03.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss04.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss05.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss06.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss07.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss08.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss09.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss10.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss11.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss12.jpg"));        
        ss.AddSlide(new Slide(slideBaseUrl + "ss13.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss14.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss15.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss16.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss17.jpg"));
        ss.AddSlide(new Slide(slideBaseUrl + "ss18.jpg"));
        
        ss.Play();  // autoplay
    }
}



/********************************************************************\
    Prototype
\********************************************************************/

function trim()
{
	var newstr = this + "";
	newstr = newstr.lTrim();
	newstr = newstr.rTrim();
	return newstr;
}
String.prototype.trim = trim;

function lTrim()
{
	var newstr = this + "";
	while(newstr.charAt(0) == " ") 
		newstr = newstr.substring(1, newstr.length);    
	return newstr;
}
String.prototype.lTrim = lTrim;

function rTrim()
{
	var newstr = this + "";
	while(newstr.charAt(newstr.length - 1) == " ") 
		newstr = newstr.substring(0, newstr.length - 1);    
	return newstr;
}
String.prototype.rTrim = rTrim; 

function replaceText(pattern, substitute)
{
	return this.split(pattern).join(substitute);
}
String.prototype.replaceText = replaceText;

function isEmail() 
{
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/   
	return re.test(this);
}
String.prototype.isEmail = isEmail;


/********************************************************************\
    Slide Show
\********************************************************************/
function Slide(src)
{
    this.Src = src;
    this._isLoaded = false;
    
    if (document.images) 
        this._image = new Image();
    
    this.Load = function()
    {
        if (!document.images)
            return;
        if (!this._isLoaded) 
        {
          this._image.src = this.src;
          this._isLoaded = true;
        }
    }
}

function SlideShow(name, image)
{
    this.Name = name;
    this.Image = image;
    this.Label = null;
    this.PlayPauseButton = null;
    this.PlayImageUrl = "";
    this.PauseImageUrl = "";
    this.Speed = 3000;
    this.Prefetch = true;
    this._slides = new Array();
    this._index = 0;
    this._timeoutid = 0;
    this._playmode = false;
    this._dofilter = (this.Image && typeof this.Image.filters != "undefined");
    this._dofade = (this.Image && typeof this.Image.style.MozOpacity != "undefined");
    this.AddSlide = function(slide)
    {
        if(this.Prefetch)
            slide.Load();
        this._slides[this._slides.length] = slide;
    }
    this.Play = function()
    {
        if(this._playmode)
            this.Pause();
        else
        {                
            if(this.PlayPauseButton != null)
                this.PlayPauseButton.src = this.PauseImageUrl;
            this.Next();
            this._timeoutid = window.setInterval(this.Name + ".Next()", this.Speed);
            
        }
        this._playmode = !this._playmode;
    }
    this.Pause = function()
    {
        if(this._timeoutid != 0)
            window.clearInterval(this._timeoutid);
        this._timeoutid = 0;
        if(this.PlayPauseButton != null)
            this.PlayPauseButton.src = this.PlayImageUrl;
    }
    this.Stop = function()
    {
        this.Pause();
        this._index = -1;
        this.Next();
    }
    this.Next = function()
    {
        this._index++;
        if(this._index >= this._slides.length)
            this._index = 0;
        this._loadCurrentSlide();
    }
    this.Previous = function()
    {
        this._index--;
        if(this._index < 0)
            this._index = this._slides.length -1;
        this._loadCurrentSlide();
    }
    this._loadCurrentSlide = function()
    {
        if(this._dofilter)
        {
            this.Image.style.filter = "progid:DXImageTransform.Microsoft.Fade()";
            this.Image.filters[0].apply();
        }
        this.Image.src = this._slides[this._index].Src;
        if(this._dofilter)
            this.Image.filters[0].play();
        else if(this._dofade)
        {
            this.Image.style.MozOpacity = 0.04;
            this._fadein(0.04);
        }       
        if(this.Label != null)
            this.Label.innerHTML = (this._index + 1) + "/" + this._slides.length;                
    }
    this._fadeinopacity = 0.04;
    this._fadein = function(opacity)
    {
        if (typeof opacity != "undefined")
            this._fadeinopacity  = opacity;
        this._fadeinopacity += 0.05;
        this.Image.style.MozOpacity = this._fadeinopacity;
        if(this.Image.style.MozOpacity < 0.99)
            window.setTimeout(this.Name + "._fadein()", 50);
    }
}


