// Title: 		TG8FX
// Creator: 	Stephan Kirchhoff - Traget.Eight Industries - http://www.target-8.com
// Contact:     stephan.kirchhoff@target-8.com
// Releasedate:	10.08 2007
// Description: a summary of Classes, Objects and Functions to make visual and logic Effects
//

function SlideShow()
{
	this.Images = new Array();
	this.ImageContainer;
	this.oldImage;
	this.activeID = -1;
	
	this.init = function()
	{
		this.ImageContainer = document.getElementById('imgContainer');
		
		var Images = document.getElementsByTagName('a');
		
		for(var i=0; Images[i]; i++)
		{
			if(Images[i].rel!='')
			{
				var s = Images[i].rel.split(":");
				
				if(s[0]=="swap")
				{
					Images[i].parent = this;
					Images[i].file = s[2];
					Images[i].image = new Image();
					Images[i].image.src = "img/big/"+s[2];
					
					this.Images.push(Images[i]);
				}
			}
		}
		
		this.next();
		
	}
	
	this.next = function()
	{
		try {
			if(this._pTG8)
			{
				var p = this._pTG8;
				window.setTimeout(function(){p.swap();}, 3000);
			}else{
				var p = this;
				window.setTimeout(function(){p.swap();}, 6000);
			}
		} catch(e){
			alert(e);
		}
	}
	
	this.swap = function()
	{
		if(this.activeID < (this.Images.length-1))
		{
			this.activeID++;
			this.blendOut();
		}else{
			this.activeID = 0;
			this.blendOut();
		}
	}
	
	this.blendIn = function()
	{
		var p = this;
		this._pTG8.ImageContainer.width   = this._pTG8.Images[this._pTG8.activeID].image.width;
		this._pTG8.ImageContainer.height  = this._pTG8.Images[this._pTG8.activeID].image.height;
		this._pTG8.ImageContainer.src 	= this._pTG8.Images[this._pTG8.activeID].image.src;
		
		var fx = new Fx.Style(this._pTG8.ImageContainer, 'opacity',{duration:2000, onComplete:this._pTG8.next});
		fx._pTG8 = this._pTG8;
		fx.start(1);
	}
	
	this.blendOut = function()
	{
		var p = this;
		var fx = new Fx.Style(this.ImageContainer, 'opacity',{duration:2000, _pTG8:this, onComplete:this.blendIn});
		fx._pTG8 = this;
		fx.start(0);
	}
	
	this.initBlend = function()
	{
		var p = this;
		var fx = new Fx.Style(this.ImageContainer, 'opacity',{duration:1, _pTG8:this, onComplete:function(){this._pTG8.ImageContainer.style.display='block';this._pTG8.blendIn();}});
		fx._pTG8 = this;
		fx.start(0);
	}
	
	this.init();
	
}

function ImageSwap()
{
	this.Images = new Array();
	this.ImageContainer;
	this.InfoContainer;
	this.oldImage;
	this.infoVis;
	
	this.init = function()
	{
		this.ImageContainer = document.getElementById('imgContainer');
		this.InfoContainer = document.getElementById('comment');
		
		var Images = document.getElementsByTagName('a');
		
		for(var i=0; Images[i]; i++)
		{
			if(Images[i].rel!='')
			{
				var s = Images[i].rel.split(":");
				if(s[0]=="swap" && s[1]=="info")
				{
					Images[i].parent = this;
					Images[i].onmousedown = this.showDesc;
				}else if(s[0]=="swap")
				{
					Images[i].parent = this;
					Images[i].file = s[2];
					Images[i].altT = s[3];
					Images[i].image = new Image();
					Images[i].image.src = "../img/big/"+s[2];
					Images[i].onmousedown = this.showImage;
					
					if(s[1]=="1")
					{
						this.oldImage = Images[i];
						this.oldImage.style.cursor = "default";
						this.oldImage.onmousedown = '';
					}
				}
			}
		}
		
		this.initBlend();
	}
	
	this.showImage = function()
	{
		this.parent.blendOut(this);
	}
	
	this.blendOut = function(o)
	{
		var p = o;
		this.oldImage.style.cursor = "pointer";
		this.oldImage.onmousedown  = this.showImage;
		
		this.oldImage = o;
		
		this.oldImage.style.cursor = "default";
		this.oldImage.onmousedown  = '';
		
		this.hideDesc();
		
		var fx = new Fx.Style(this.ImageContainer, 'opacity',{duration:1000, _pTG8:this, onComplete:this.blendIn});
		fx._pTG8 = this;
		fx.start(0);
	}
	
	this.blendIn = function()
	{
		this._pTG8.ImageContainer.width  = this._pTG8.oldImage.image.width;
		this._pTG8.ImageContainer.height = this._pTG8.oldImage.image.height;
		this._pTG8.ImageContainer.src 	 = this._pTG8.oldImage.image.src;
		this._pTG8.ImageContainer.alt	 = this._pTG8.oldImage.altT;
		
		var fx = new Fx.Style(this._pTG8.ImageContainer, 'opacity',{duration:1000});
		fx.start(1);
	}
	
	this.initBlend = function()
	{
		var p = this;
		var fx = new Fx.Style(this.ImageContainer, 'opacity',{duration:1, _pTG8:this, onComplete:this.initBlendEnd});
		fx._pTG8 = this;
		fx.start(0);
		
		var fx2 = new Fx.Style(this.InfoContainer, 'opacity',{duration:1, _pTG8:this, onComplete:function(){this._pTG8.InfoContainer.style.display='block';}});
		fx2._pTG8 = this;
		fx2.start(0);
		
	}
	
	this.initBlendEnd = function()
	{
		this._pTG8.ImageContainer.style.display = "block";
		var fx = new Fx.Style(this._pTG8.ImageContainer, 'opacity',{duration:1000});
		fx.start(1);
	}
	
	this.showDesc = function()
	{
		if(this.parent.infoVis)
		{
			this.parent.hideDesc();
		}else{
			this.parent.infoVis = true;
			var fx = new Fx.Style(this.parent.InfoContainer, 'opacity',{duration:1000});
			fx.start(0.75);
		}
	}
	
	this.hideDesc = function()
	{
		this.infoVis = false;
		var fx = new Fx.Style(this.InfoContainer, 'opacity',{duration:1000});
		fx.start(0);
	}
	
	this.init();
	
}

function scrollView()
{
	this.Items = new Array();
	this.Container = document.getElementById("frame");
	
	this.StepWidth = 3;
	this.ScrollPos = 0;
	this.ScrollTarget = 0;
	
	this.ElementPos = 0;
	this.IntervalId;
	this.ScrollTMP;
	
	
	this.getElements = function()
	{
		var items = document.getElementsByTagName("div");
		for(var i=0; items[i]; i++)
		{
			if(items[i].className=="projekt-item")
			{
				this.Items.push(items[i]);
			}
		}
	}
	
	this.next = function()
	{
		if(this.ElementPos+this.StepWidth < this.Items.length)
		{
			
			this.ElementPos+=this.StepWidth;
			this.ScrollInit();
		}
	}
	
	this.prev = function()
	{
		if(this.ElementPos-this.StepWidth >= 0)
		{
			this.ElementPos-=this.StepWidth;
			this.ScrollInit();
		}else if(this.ElementPos-2 >= 0)
		{
			this.ElementPos-=2;
			this.ScrollInit();
		}else if(this.ElementPos-1 >= 0)
		{
			this.ElementPos-=1;
			this.ScrollInit();
		}
	}
	
	this.ScrollInit = function()
	{
		if(this.ElementPos==0)
		{
			
			this.ScrollTarget = 0;
		}else{
			this.ScrollTarget = this.Items[this.ElementPos].offsetTop-this.Items[0].offsetTop;
		}
		var p = this;
		
		try{
			clearInterval(this.IntervalId);
			this.ScrollTMP = 999999;
		} catch(e){
		}
		
		this.IntervalId = setInterval(function(){p.Scroll();}, 40);
		
	}
	
	this.Scroll = function()
	{
		
		if(Math.round(this.ScrollPos)==this.ScrollTarget)
		{
			clearInterval(this.IntervalId);
			this.ScrollTMP = 999999;
		}else{
			this.ScrollTMP = this.Container.scrollTop;
			this.Container.scrollTop = this.ScrollPos = (this.ScrollPos-(this.ScrollPos-this.ScrollTarget)/7);
		}
	}
	
	this.ScrollByPose = function(pos)
	{
		this.ScrollTarget = this.Items[pos*this.StepWidth].offsetTop-this.Items[0].offsetTop;
		var p = this;
		
		try{
			clearInterval(this.IntervalId);
			this.ScrollTMP = 999999;
		} catch(e){
		}
		
		this.IntervalId = setInterval(function(){p.Scroll();}, 40);
	}
	
	this.getElements();
}
