//------cpIrroAngebote---------------------------
cpIrroAngebote = function(name){
	this.name=name;
	this.imagecount=10;
	this.imagenr=0;
	this.running=true;
	this.nextimage=this.imagenr+2 % this.imagecount;

	this.create=function(){ document.write('<img style="cursor:pointer; margin:20px; vertical-align:center;" onClick="cpIrroAngeboteItem[\''+this.name+'\'].show();" src="pic/knaller.jpg" />'); }

	this.show=function(){
		this.blackdiv=document.createElement("div");
		this.blackdiv.style.width=document.documentElement.clientWidth+'px';
		this.blackdiv.style.height=document.documentElement.clientHeight+'px';
		this.blackdiv.style.position='absolute';
		this.blackdiv.style.zIndex='104';
		this.blackdiv.style.display='block';
		this.blackdiv.style.left='0px';
		this.blackdiv.style.top=Math.max(document.documentElement.scrollTop,document.body.scrollTop)+'px';
		this.blackdiv.style.background='#888888';
		this.blackdiv.style.filter = "alpha(opacity:50)";
		this.blackdiv.style.KHTMLOpacity = this.blackdiv.style.MozOpacity = this.blackdiv.style.opacity = 0.5;

		var self=this;
		if (document.addEventListener) { this.blackdiv.addEventListener("click", self.blackdivclick=function(e) { self.close(); }, true); }
		else { this.blackdiv.attachEvent('onclick', self.blackdivclick=function(e) { self.close(); },true ) }

		document.getElementsByTagName('body')[0].appendChild(this.blackdiv);

		this.bgdiv=document.createElement("div");
		this.bgdiv.style.width='810px';
		this.bgdiv.style.height='560px';
		this.bgdiv.style.position='absolute';
		this.bgdiv.style.zIndex='104';
		this.bgdiv.style.display='block';
		this.bgdiv.style.left=(document.documentElement.clientWidth-810)/2+'px';
		this.bgdiv.style.top=Math.max(document.documentElement.scrollTop,document.body.scrollTop)+(document.documentElement.clientHeight-560)/2+'px';
		this.bgdiv.style.background='url(\'pic/angebote.png\')';
		document.getElementsByTagName('body')[0].appendChild(this.bgdiv);
		var tmpstr='';
		tmpstr+='<img onClick="cpIrroAngeboteItem[\''+this.name+'\'].setNext(\'-\');" style="cursor:pointer;" id="'+this.name+'_button'+i+'" src="pic/button_left.jpg" />';
		for(var i=0;i<this.imagecount/2;i++) 
			tmpstr+='<img onClick="cpIrroAngeboteItem[\''+this.name+'\'].setNext('+(i*2)+');" style="cursor:pointer;" id="'+this.name+'_button'+i+'" src="pic/button_off.jpg" />';
		tmpstr+='<img onClick="cpIrroAngeboteItem[\''+this.name+'\'].setNext(\'+\');" style="cursor:pointer;" id="'+this.name+'_button'+i+'" src="pic/button_right.jpg" />';
		this.bgdiv.innerHTML='<div id="'+this.name+'_innerdiv" style="display:block; width:798px; height:444px; margin:74px 0px 0px 6px; overflow:hidden; position:relative;"></div>'+
			'<div id="'+this.name+'_innerdivbuttons" style="display:block;width:798px; height:29px; text-align:center; margin:2px 0px 0px 6px; overflow:hidden; position:relative;">'+tmpstr+'</div>'+
			'<img src="pic/pdf3.jpg" style="cursor:pointer; position:absolute; right:10px; bottom:10px;" onclick="location.href=\'doc/Staedtereisen_zu_Jubilaeumspreis.pdf\';" />'
			//+'<img src="pic/close.jpg" style="cursor:pointer; position:absolute; right:30px; bottom:20px;" onclick="cpIrroAngeboteItem[\''+this.name+'\'].close();" />'
			;
		// 923 - 840
		this.loadImages();
	}

	this.close=function(){
		if(this.waitTimeout!=null) {
			clearTimeout(this.waitTimeout);
			this.waitTimeout=null;
		}
		if(this.switchTimeout!=null) {
			clearTimeout(this.switchTimeout);
			this.switchTimeout=null;
		}
		document.getElementsByTagName('body')[0].removeChild(this.bgdiv);
		this.bgdiv=null;
		var self=this;
		if (document.addEventListener) { this.blackdiv.removeEventListener("click", self.blackdivclick, true); }
		else { this.blackdiv.detachEvent('onclick', self.blackdivclick,true ) }
		document.getElementsByTagName('body')[0].removeChild(this.blackdiv);
		this.blackdiv=null;
		this.imagenr=0;
		this.running=true;
		this.nextimage=this.imagenr+2 % this.imagecount;
	}

	this.setButtons=function(){
		for(var i=0;i<this.imagecount/2;i++){
			if(this.imagenr/2==i) document.getElementById(this.name+'_button'+i).src='pic/button_on.jpg';
			else document.getElementById(this.name+'_button'+i).src='pic/button_off.jpg';
		}
	}

	this.loadImages=function(wait){
		if(wait==undefined) wait=5000;
		document.getElementById(this.name+'_innerdiv').innerHTML='<div id="'+this.name+'_innerdiv2" style="position:absolute;left:15px;width:4000px;">'+
			'<img src="pic/angebote/'+((this.imagenr)% this.imagecount+1)+'.jpg">'+
			'<img src="pic/angebote/'+((this.imagenr+1)% this.imagecount+1)+'.jpg">'+
			'<img style="margin-left:83px;" src="pic/angebote/'+((this.nextimage)% this.imagecount+1)+'.jpg">'+
			'<img src="pic/angebote/'+((this.nextimage+1)% this.imagecount+1)+'.jpg">'+
			'</div>';
		this.setButtons();
		if(this.running || wait!=5000) this.waitTimeout=setTimeout('cpIrroAngeboteItem[\''+this.name+'\'].switchPlus();',wait);
	}

	this.switchPlus=function(){
		this.waitTimeout=null;
		if(parseInt(document.getElementById(this.name+'_innerdiv2').style.left)<-823) {
			this.imagenr=(this.nextimage) % this.imagecount;
			this.nextimage=this.imagenr+2 % this.imagecount;
			this.switchTimeout=null;
			this.loadImages();
		}
		else {
			var ratio=Math.min(20,2000/Math.abs(parseInt(document.getElementById(this.name+'_innerdiv2').style.left)+360));
			ratio=10*(10-Math.abs(parseInt(document.getElementById(this.name+'_innerdiv2').style.left)+415)/50);
			window.status=5*10-Math.abs(parseInt(document.getElementById(this.name+'_innerdiv2').style.left)+415)/50;
			document.getElementById(this.name+'_innerdiv2').style.left=parseInt(document.getElementById(this.name+'_innerdiv2').style.left)-(ratio)+'px';
			this.switchTimeout=setTimeout('cpIrroAngeboteItem[\''+this.name+'\'].switchPlus();',50);
		}
	}

	this.setNext=function(i){
		if(this.switchTimeout==null) {
			if(i=='+') i=(this.imagenr+2) % this.imagecount;
			if(i=='-') i=(this.imagenr+this.imagecount-2) % this.imagecount;
			clearTimeout(this.waitTimeout);
			this.nextimage=i;
			this.running=false;
			this.loadImages(0);
		}
	}
	
	this.create();
}


var cpIrroAngeboteItem=Array();

function addcpIrroAngebote(id){
	if(cpIrroAngeboteItem[id]==null) {
		cpIrroAngeboteItem[id]=new cpIrroAngebote(id);
	}
}
