////////////////////////////////////////////////////////////////////////////////////////////
//
//  Smartesse - smarts_transition.js
//
//  Created on 01.2007 from Alexander Jung
//  copyright by zebworx interactive -- Alexander Jung
//
////////////////////////////////////////////////////////////////////////////////////////////

smarts_transition=function(){
	if(!smarts_transition.instances){
		smarts_transition.instances=new Array();
	}
	this.id=smarts_transition.instances.length;
	smarts_transition.instances[this.id]=this;
  
  this.texts = new Array ("TELEFONSERVICE", "BUSINESS SERVICES");

	this.elementId;
	this.container;
	this.bilder=new Array();
	this.current=0;
	this.next=0;
	this.last=0;
	this.transition;
	this.speed=10;
	this.steps=.02;
	this.type='fade';
}

smarts_transition.prototype.init=function(elementId){
	this.container=document.getElementById(elementId);   
  
  this.text_container = document.getElementById("image-text");
  this.text_container.innerHTML = this.texts[0];    

	this.elementId=elementId;

	var img=this.container.getElementsByTagName('img');

	for(var i=0;i<img.length;i++){
		if(img[i].id.substr(0,elementId.length+1)==elementId+'_'){
			this.bilder[i]=img[i];

			var id=this.bilder[i].id.substr(elementId.length+1);

			var newsrc=this.bilder[i].src.substr(this.bilder[i].src.lastIndexOf('/')+1);
		}
	}

	this.last=this.bilder.length-1;
}


smarts_transition.prototype.get_image=function(){
	if(this.current==this.last){
		this.next=0;
	}else{
		this.next=this.current+1;
	}

	this.container.style.background='url('+this.bilder[this.next].src+') 0px 0px 0px no-repeat';
	this.trans=1;
	this.transition=window.setInterval('smarts_transition.instances['+this.id+'].fade();',this.speed);
  //this.text_container.innerHTML = this.texts[this.next];      
}

smarts_transition.prototype.fade=function(){
	this.setTrans(this.bilder[this.current],this.trans-=this.steps);

	if(this.trans<=0){
		this.bilder[this.current].className='transition_hide';
		this.trans=1;
		this.setTrans(this.bilder[this.current],this.trans);

		this.current=this.next;
		this.bilder[this.next].className='transition_view';
     this.text_container.innerHTML = this.texts[this.next];  
		window.clearInterval(this.transition);
	}
}

smarts_transition.prototype.setTrans=function(obj,value){
	var objStyle;
	objStyle=(obj.length)?obj[i].style:obj.style;

	objStyle.filter='alpha(opacity='+(value*100)+')';
	objStyle.MozOpacity=''+value;
	objStyle.KTHMLOpacity=''+value;
	objStyle.opacity=''+value;
}


