﻿/*

Copyright 2010 tribalmedia

Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License. You may
obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.

Contact sales@tribalmedia.com for more information.

*/

// Parameters
var gText = "Zerspanungstechnik";
var gTextInterval = 1800;			// 1000 = 1 sec.
var gPositionX = 180;
var gPositionY = 116;
var gNumberOfImages = 4;			// 01.jpg, 02.jpg, ..., 10.jpg etc.
var gTransitionInterval = 2000;
var gBlendingInterval = 1000;

// Internal 
var gImageIndex = 0;
var gCurrentImage = null;

function initializeAnimation()
{
	gText = tmSetInnerHTML('animatorText', gText);
	gText.currentRight = 750;
	gText.style['right'] = '750px';
	var anElement = tmGetElement('animatorFrame');
	anElement.style['left'] = '' + gPositionX + 'px';
	anElement.style['top'] = '' + gPositionY + 'px';
	anElement.style['visibility'] = 'visible';
	setTimeout(aniNextTransition, gBlendingInterval);
}

function aniNextTransition()
{
	gImageIndex++;
	if (gImageIndex > gNumberOfImages)
		gImageIndex = 1;
	if (gCurrentImage != null) {
		aniHide(gCurrentImage);
		if (gCurrentImage.id == 'animatorImage1')
			gCurrentImage = tmGetElement('animatorImage2');
		else
			gCurrentImage = tmGetElement('animatorImage1');
	} else {
		gCurrentImage = tmGetElement('animatorImage1');
		setTimeout(aniSlideText);
	}
		
	var aPath = "";
	gCurrentImage.style['opacity'] = '0.0';
	gCurrentImage.style['filter'] = 'alpha(opacity = 0);';
	gCurrentImage.currentOpacity = 0.0;
	if (gImageIndex < 10)
		aPath = "0";
	aPath = "./Images/" + aPath + gImageIndex + ".jpg";
	gCurrentImage.onload = function () {
		aniShow(gCurrentImage);
	}
	gCurrentImage.src = aPath;
}

function aniShow(theImage)
{
	theImage = tmGetElement(theImage);
	theImage.currentOpacity += 0.05;
	theImage.style['opacity'] = '' + theImage.currentOpacity;
	var anIEValue = parseInt(theImage.currentOpacity * 100.0);
	theImage.style['filter'] = 'alpha(opacity = ' + anIEValue + ');';
	if (theImage.currentOpacity >= 1.0)
		setTimeout(aniNextTransition, gTransitionInterval);
	else
		setTimeout("aniShow('" + theImage.id + "');", (gBlendingInterval / 20));
}

function aniHide(theImage)
{
	theImage = tmGetElement(theImage);
	theImage.currentOpacity -= 0.05;
	theImage.style['opacity'] = '' + theImage.currentOpacity;
	var anIEValue = parseInt(theImage.currentOpacity * 100.0);
	theImage.style['filter'] = 'alpha(opacity = ' + anIEValue + ');';
	if (theImage.currentOpacity > 0.0)
		setTimeout("aniHide('" + theImage.id + "');", (gBlendingInterval / 20));
}

function aniSlideText()
{
	gText.currentRight -= 3;
	gText.style['right'] = '' + gText.currentRight + 'px';
	if (gText.currentRight > 0)
		setTimeout(aniSlideText, (gTextInterval / 250));
}

function tmGetElement(theElement)
{
	if (typeof(theElement) == "string")
		return document.getElementById(theElement);
	else
		return theElement;
}

function tmSetInnerHTML(theElement, theHTML)
{
	theElement = tmGetElement(theElement);
	theElement.innerHTML = theHTML;
	return theElement;
}
