var ACREF = { 
	settings:{
		references: {},
		timer: 5000,
		anzahl:3,
		width:300,
		widthpicture:100,
		maxheight:100
	},
	du:0,
	fade:function(im,step) {
		var imgs = $$('#ac_references div.images');
		step = step || 0;

		imgs[im].style.opacity = step/100;
		imgs[im].style.filter = "alpha(opacity=" + step + ")"; // IE
		if ( im === 0 ){
			imgs[this.len-1].style.opacity = 1-step/100;
			imgs[this.len-1].style.filter = "alpha(opacity=0)"; // IE
		} else {
			imgs[im-1].style.opacity = 1-step/100;
			imgs[im-1].style.filter = "alpha(opacity=0)"; // IE
		}
		step = step + 0.5;
		if (step <= 100) {
			window.setTimeout(function () { ACREF.fade(im,step); }, 1);
		}
	},

	wait:function(im){
		this.len=document.getElementById('ac_references').getElementsByTagName("img").length/this.settings.anzahl; 
		//$$('#ac_references img').length/this.settings.anzahl;
		this.len = Math.round(this.len+0.49);
		if(im >= this.len){
			im = 0;
		}
		var j = 0;		
		this.du++;
		if ( this.du*this.settings.anzahl >= this.settings.references.DATA.length ){
			this.du = 0;
		}
		for ( i = 0; i < this.settings.references.DATA.length; i++ ){
			if(this.links[this.du*this.settings.anzahl+j]){
				document.getElementById('ac_references').getElementsByTagName("a")[i].href = this.links[this.du*this.settings.anzahl+j]
			}
			j++;
			if ( j === this.settings.anzahl ){
				j=0;
			}
		}

		this.fade(im);
		im++;
		setTimeout("ACREF.wait("+im+")", this.settings.timer)
	},

	inh:function(ref,anzahl,maxheight){
		var o = '', l=this.settings.width/this.settings.anzahl, z=0;
		var ran = [], temp = true;  
		this.links = [];
		$('ac_references').innerHTML='';		
		ACREF.settings.references=ref;
		ACREF.settings.anzahl=anzahl;
		ACREF.settings.maxheight=maxheight;

		o += '<div class="images">';
		for ( var i = 0; i < this.settings.references.DATA.length; i++ ) {
			var zahl = Math.floor((Math.random()*this.settings.references.DATA.length)+1);
			do {
				temp = false;
				for ( var j = 0; j < i; j++ ) {
					if ( zahl === ran[j] ) {
						zahl = Math.floor((Math.random()*this.settings.references.DATA.length)+1);
						temp = true;
					}
				} 
			}while (temp == true)
			ran[ran.length] = zahl;
			zufall = zahl;

			if ( z === this.settings.anzahl ){
				z = 0;
				o += '</div><div class="images" style="opacity:0; filter:alpha(opacity=0); position:absolute; left:0px">';
			}
			o += '<div style="width:'+(l)+'px;" align="center"><a target="_blank" href='+this.settings.references.DATA[zufall-1][2]+'>';
			o+='<img src="'+this.settings.references.DATA[zufall-1][0]+'" ';
			var margin=(this.settings.maxheight-this.settings.references.DATA[zufall-1][3])/2;
			o+='style="border:none; margin-top:'+margin+'px;"></a></div>';
			z++;
			this.links[i]=this.settings.references.DATA[zufall-1][2];
		}

		$('ac_references').style.width = (this.settings.anzahl-1)*l+this.settings.widthpicture + "px";
		$('ac_references').style.marginLeft = (this.settings.width - ((this.settings.anzahl-1)*l+this.settings.widthpicture))/2 + "px"; 
		o += '</div>';
		$('ac_references').insert(o);
	
		var j = 0;
		for ( i = this.settings.anzahl; i < this.settings.references.DATA.length; i++ ){
			$('ac_references').getElementsByTagName("a")[i].href = this.links[j]
			j++;
			if ( j === this.settings.anzahl ){
				j=0;
			}
		}
		setTimeout("ACREF.wait(1)", this.settings.timer)
	}	
}



var ACSLIDER={			
	move : function(c){
		var o='',cnt=0;				
		$$('#ac_slider .ac_sliderelement').each(function(){
			cnt++;
		});
		var z = (c <= 0) ? cnt-1 : c-1;
		var w = (c >= cnt) ? 0 : c+1;		
		if (cnt == w) {
			w=0;		
		}
		$('ac_slider').style.width=(317*cnt)+'px';		
		o+='<span class="back" onclick="ACSLIDER.move('+z+')"><img src="mm/move-l.jpg" title="Alpha Com Deutschland" style="cursor:pointer;" /></span>';
		o+='<span class="forward" onclick="ACSLIDER.move('+w+')"><img src="mm/move-r.jpg" title="Alpha Com Deutschland" style="cursor:pointer;" /></span>';
		$('ac_slider_nav').update(o);
		$('ac_slider').morph('left:-'+(c*317).toString()+'px', {
			transition: function(pos){
				return S2.FX.Transitions.easeFrom(pos);
			},
			duration: 1
		});
	}            		
}
Event.observe(window, 'load', function() {
	if($('ac_whatwedo')){
		ACSLIDER.move(0);
	}
});	

