//var teaser = new dynamic_teaser();
var teaser =null;
var teaser_maxImages=5;
var teaser_actImagePointer=0;
var teaser_actDivPointer=0;
var teaser_actYPointer=null;
var teaser_maxY=null;
var teaser_maxX=null;
var teaser_nextImgHeight=null;
var teaser_div=null;
var teaser_DivID='teaser_content';
var teaser_images=new Array();
var teaser_Divs=new Array();
var teaser_Creation='create';
var teaser_colIndex=0;
var teaser_colors=new Array('#8CC63F','#1482C6','#B5121b');
var teaser_headerHeight=10;

function dynamic_teaser(TeaserID){
	//variablen:
	this.maxImages=teaser_maxImages;
	this.actImagePointer=teaser_actImagePointer;
	this.actDivPointer=teaser_actDivPointer;
	this.actYPointer=teaser_actYPointer;
	this.maxY=teaser_maxY;
	this.maxX=teaser_maxX;
	this.nextImgHeight=teaser_nextImgHeight;
	this.div=teaser_div;
	this.DivID=teaser_DivID;
	this.Divs=teaser_Divs;
	this.images=teaser_images;
	this.Creation=teaser_Creation;
	this.colIndex=teaser_colIndex;
	this.colors=teaser_colors;
	this.headerHeight=14;
	this.actDiv=0;
	
	//funktionen
	this.render=teaser_render;
	this.createDivs=teaser_createDivs;
	this.createMainDiv=teaser_createMainDiv;
	this.createContentDivs=teaser_createContentDivs;
	this.addImage=teaser_addImage;
	this.getNextColor=teaser_getNextColor;
	this.nextContent=teaser_nextContent;
	this.prevContent=teaser_prevContent;
	
	this.headerTPL="<div style='background:{BGCOL}; cursor:default; height:"+this.headerHeight+"px; overflow:hidden; color:#FFFFFF; font-size:12px; font-weight:bold; text-align:left; padding:3px 3px 3px 13px; width:100%;'>{HEADLINE}</div>";
	this.ImageTPL="<div style='height:{IMGHEIGHT}px;'><a href='{IMGLINK}' target='_blank' style='position:relative;'><img border='0' src='{IMGURL}' alt='{IMGLINK}' style='position:relative' /></a></div>";
}

function teaser_render(){
	//alert('teaser_render');
	this.createDivs();
}





function teaser_createDivs(){
	//alert('teaser_createDivs');
	this.createMainDiv();
	this.createContentDivs();
}

function teaser_createMainDiv(){
	//alert('teaser_createMainDiv');
	if(document.getElementById(this.DivID)){
		this.div=document.getElementById(this.DivID);
		this.maxY=this.div.clientHeight;
		this.maxX=this.div.clientWidth;
		this.maxX=266;
		this.maxY=552;
	//	this.div.style.overflowX="hidden";
	//	this.div.style.overflowY="show";
	}
	else{
		alert('Div nicht gefunden.');
	}
}
var m_maxCounter=80;

function teaser_createContentDivs(){
	//alert('teaser_createContentDivs');
	var actDiv=null;
	var sActImgCode='';
	var aActImg=new Array();
	var actHeaderCode='';
	var actImgCode='';
	var actInnerCounter=0;
	var divCounter=0;
	var firstDiv=true;
	this.actImagePointer=0;
	var actiheight=null;
	var aImage= this.images[this.actImagePointer];
	actiheight=aImage[1];
	while(this.actImagePointer<this.images.length&&divCounter<m_maxCounter){
		this.actYPointer=0;
		var actID='teaserdiv_'+divCounter;
		divCounter++;
		actInnerCounter=0;
		actDiv=document.createElement('div');
		actDiv.style.width=this.maxX;
		actDiv.id=actID;

		actDiv.style.height=this.maxY;
		actDiv.style.position='absolute';
		actDiv.style.className='div_FloatLeft';
		actDiv.style.top=0;
		this.div.appendChild(actDiv);
		if(!firstDiv){
			if(is_ie()){
				actDiv.style.display='none';
			}
			else{
				actDiv.style.filter = 'alpha(opacity=0)';
				actDiv.style.opacity= 0;
				actDiv.style.display='none';
			}
		}
		if(!is_ie()){
			actDiv.style.left=(divCounter-1)*this.maxX;
		}
		else{
			actDiv.style.left=0;
		}
		
		//
		sActImgCode='';
		
		while((this.actYPointer+actiheight+5+this.headerHeight<this.maxY)&&(actInnerCounter<this.maxImages)&&(this.actImagePointer<this.images.length)){
		//	alert(this.actYPointer);
			actHeaderCode=this.headerTPL.replace(/{BGCOL}/g,this.getNextColor());
			actHeaderCode=actHeaderCode.replace(/{HEADLINE}/g,aImage[3]);
			actImgCode=this.ImageTPL.replace(/{IMGLINK}/g,aImage[2]);
			actImgCode=actImgCode.replace(/{IMGURL}/g,aImage[0]);
			actImgCode=actImgCode.replace(/{IMGHEIGHT}/g,actiheight);
			this.actYPointer+=actiheight+this.headerHeight;
			sActImgCode+=actHeaderCode+actImgCode;
			this.actImagePointer++;
			actInnerCounter++;
			aImage= this.images[this.actImagePointer];
			if(aImage){
				actiheight=aImage[1];
			}
			
		}
		firstDiv=false;
	//	alert(sActImgCode);
		actDiv.innerHTML=sActImgCode;
		
		//inhalt des Divs
		this.Divs.push(actDiv);
	}
}

var teaserDiv1=null;
var teaserDiv2=null;

function teaser_fadeInOut(Div1,Div2){
	teaserDiv1=Div1;
	teaserDiv2=Div2;
	if(!teaserDiv1||!teaserDiv2){
		return;
	}
//	alert(Div1.id+':'+Div2.id);
	for(var i=0;i<=100;i+=5){
		setTimeout("teaser_setOcaDiv12("+i+")",i*10);
	}
}

function teaser_fadeInOutIE(Div1,Div2){
	if(!Div1||!Div2){
		return;
	}
	Div1.style.display='';
	Div2.style.display='none';
}

function teaser_setOcaDiv12(Val){
	if(!teaserDiv1||!teaserDiv2){
		return;
	}
	if(Val==0){
		teaserDiv1.style.display='';
		teaserDiv2.style.display='';
	}
	var revVal=100-Val;
	teaserDiv1.style.opacity= Val/100;
	teaserDiv2.style.opacity= revVal/100;
	if(Val==100){
		teaserDiv2.style.display='none';
		teaserDiv1.style.display='';
	}
}

function teaser_setOcaDiv12IE(Val){
	var revVal=100-Val;
	teaserDiv1.style.filter = 'alpha(opacity='+Val+')';
	teaserDiv2.style.filter = 'alpha(opacity='+revVal+')';
}

function teaser_addImage(imgpath,imgheight,imagelink,title){
	this.images.push(new Array(imgpath,imgheight,imagelink,title));
//	alert(title+'geadded');
}

function is_ie(){
	return (document.all&&true);	
}

function teaser_getNextColor(){
	//alert('teaser_getNextColor');
	if(this.colIndex>this.colors.length-1){
		this.colIndex=0;
	}
	return this.colors[this.colIndex++];
}


function teaser_prevContent(){
	
}

function teaser_nextContent(){
	var pointer=this.actDiv;
	var act_Div=this.Divs[pointer];
	pointer++;
	if(pointer==this.Divs.length){pointer=0;}
	var next_Div=this.Divs[pointer];
	if(is_ie()){//IE
		teaser_fadeInOutIE(next_Div,act_Div);
	}
	else{
		teaser_fadeInOut(next_Div,act_Div);
	}
	this.actDiv=pointer;
	
}
