var SlideShow = new Class({
	initialize: function(containerId){
		this.containerId = containerId;
		this.timer;
		this.nextDiv = 0;
		this.lastDiv = -1;
		this.manipulate = false;
		this.topicsCount = 0;
		this.ie7 = true;
		
		if(document.getElementsByTagName('body')[0].hasAttribute) this.ie7 = false;
		
		//if(!this.ie7) {alert("ie8");}
		
		//if(window.ie) {alert("ie");}
		//if(window.ie7) {alert("ie7");}
		//if(window.ie6) {alert("ie6");}
		
		for (i=0;i<$('news_head_topic').getElementsByTagName("div").length;i++) {
			if(!$('news_head_topic').getElementsByTagName("div")[i].id) continue;
			if($('news_head_topic').getElementsByTagName("div")[i].id.match(/news_head_topic/)) {
				this.topicsCount++;
			}
		}	
		
		if(window.ie && !this.ie7 && !window.ie6) {
		
			for (i=0; i<this.topicsCount; i++) {
				//$('news_head_topic_'+(i)).style.filter = "alpha(opacity=0)";
				
				$('news_head_topic_'+(i)).getElements('img')[0].style.filter = "alpha(opacity=0)";
				$('news_head_topic_'+(i)).style.backgroundColor = "transparent";
				$('news_head_topic_'+(i)).style.position = "absolute";
				$('news_head_topic_'+(i)).style.width = "780px";
				$('news_head_topic_'+(i)).style.height = "289px";
				$('news_head_topic_'+(i)).style.display = "block";
				$('news_head_topic_'+(i)).style.visibility = "visible";
				//$('news_head_topic_'+(i)).getElements('a')[0].id.match(/'news_head_topic_'+(i)/);
				//$('news_head_topic_'+(i)).getElements('img')[0].style.position = "static";
				//$('news_head_topic_'+(i)).getElements('img')[0].style.width = "780px";
				//$('news_head_topic_'+(i)).getElements('img')[0].style.height = "289px";
				//$('news_head_topic_'+(i)).getElements('div')[0].style.backgroundColor = "#B1111B";
				$('news_head_topic_'+(i)).getElements('div')[0].style.filter = "alpha(opacity=0)";	
				$('news_head_topic_'+(i)).getElements('div')[1].style.filter = "alpha(opacity=0)";
				$('news_head_topic_'+(i)).getElements('div')[0].style.zIndex = 0;
				$('news_head_topic_'+(i)).getElements('div')[1].style.zIndex = 0;
				$('news_head_topic_'+(i)).getElements('img')[0].style.zIndex = 0;
			}
			//$('news_head_topic_'+(this.nextDiv)).style.filter = "alpha(opacity=100)";//alpha(opacity=70)
			$('news_head_topic_'+(this.nextDiv)).getElements('img')[0].style.filter = "alpha(opacity=100)";
			
			$('news_head_topic_'+(this.nextDiv)).getElements('div')[0].style.filter = "alpha(opacity=70)";
			$('news_head_topic_'+(this.nextDiv)).getElements('div')[1].style.filter = "alpha(opacity=100)";
			$('news_head_topic_'+(this.nextDiv)).getElements('div')[0].style.zIndex = 99;
			$('news_head_topic_'+(this.nextDiv)).getElements('div')[1].style.zIndex = 100;
			$('news_head_topic_'+(this.nextDiv)).getElements('img')[0].style.zIndex = 98;
		}
		
	},
	init: function() {
		
	},
	start: function() {	
		
		var cssProperty = "opacity";
		var cssStartVal = 0;
		var cssEndVal = 1;
		
		
		if (!this.manipulate) {
			if(this.nextDiv == this.topicsCount-1) {
				this.nextDiv = 0;
				this.lastDiv = (this.topicsCount-1);// console.log("nextDiv=0,lastDiv=" + (this.topicsCount-1));
			} 
			else {
				this.nextDiv = this.nextDiv + 1;
				this.lastDiv = this.nextDiv - 1;// console.log("nextDiv="+(this.nextDiv)+", lastDiv="+(this.lastDiv));
			}
		} 
		
		
		//console.log("NEXTDIV: " + this.nextDiv + ", LASTDIV: " + this.lastDiv);
		
		if(window.ie && !this.ie7 && !window.ie6) {
			this.ieFade();
		}
		else
		{
			var fadeOld = new Fx.Style($('news_head_topic_'+(this.lastDiv)), cssProperty, {duration: 1000});
			fadeOld.start(cssEndVal, cssStartVal);
			var fadeNew = new Fx.Style($('news_head_topic_'+this.nextDiv), cssProperty, {duration: 1000});
			fadeNew.start(cssStartVal, cssEndVal);
//			var fadeOld = new Fx.Tween($('news_head_topic_'+(this.lastDiv)), cssProperty, {duration: 1000});
//			fadeOld.start(cssEndVal, cssStartVal);
//			var fadeNew = new Fx.Tween($('news_head_topic_'+this.nextDiv), cssProperty, {duration: 1000});
//			fadeNew.start(cssStartVal, cssEndVal);
		} 
		if(window.ie && !this.ie7 && !window.ie6) {
			ieFadeLock = 0;
		}
		if (this.manipulate) this.manipulate = false;
	},
	

	ieFade: function() {
		
		
		
		var valueDecr = 100;
		var valueIncr = 0;
		var lastDiv = this.lastDiv;
		var nextDiv = this.nextDiv;
		
		
		$('news_head_topic_'+(lastDiv)).style.filter = "alpha(opacity=100)";
		
		//$('news_head_topic_'+(lastDiv)).style.visibility = "visible";
		

		$('news_head_topic_'+(nextDiv)).style.filter = "alpha(opacity=0)";
		
		//$('news_head_topic_'+(nextDiv)).style.visibility = "visible";
	
		
		var once = true;		
		
//		clearInterval(cssIe);
		var cssIe = setInterval(function() {
			valueDecr=valueDecr-10;
			valueIncr=valueIncr+10;

//			$('banner_right').innerHTML += nextDiv + "<br>";
						
			//document.getElementById('news_head_topic_'+(lastDiv)).filters.item("alpha").opacity = valueDecr;
			//document.getElementById('news_head_topic_'+(nextDiv)).filters.item("alpha").opacity = valueIncr;

			document.getElementById('news_head_topic_'+(lastDiv)).getElementsByTagName('img')[0].filters.item("alpha").opacity = valueDecr;
			document.getElementById('news_head_topic_'+(nextDiv)).getElementsByTagName('img')[0].filters.item("alpha").opacity = valueIncr;
			
			if(valueDecr==0) {
				//$('news_head_topic_'+(lastDiv)).style.visibility = "hidden";
				//$('news_head_topic_'+(lastDiv)).style.display = "none";
				
				//$('news_head_topic_'+(nextDiv)).style.visibility = "visible";
				//$('news_head_topic_'+(nextDiv)).style.display = "block";
				
				$('news_head_topic_'+(lastDiv)).getElements('div')[0].style.filter = "alpha(opacity=0)";
				$('news_head_topic_'+(lastDiv)).getElements('div')[1].style.filter = "alpha(opacity=0)";
				
		
				
			}
			
			if(valueIncr==30) {

				$('news_head_topic_'+(nextDiv)).getElements('div')[0].style.filter = "alpha(opacity=70)";
				$('news_head_topic_'+(nextDiv)).getElements('div')[1].style.filter = "alpha(opacity=70)";
				
				$('news_head_topic_'+(lastDiv)).getElements('div')[0].style.zIndex = 0;
				$('news_head_topic_'+(lastDiv)).getElements('div')[1].style.zIndex = 0;
				$('news_head_topic_'+(lastDiv)).getElements('img')[0].style.zIndex = 0;
				
				$('news_head_topic_'+(nextDiv)).getElements('div')[0].style.zIndex = 99;
				$('news_head_topic_'+(nextDiv)).getElements('div')[1].style.zIndex = 100;
				$('news_head_topic_'+(nextDiv)).getElements('img')[0].style.zIndex = 98;
			}
//			if(valueIncr>=50) {
//				$('news_head_topic_'+(nextDiv)).getElements('div')[1].filters.item("alpha").opacity = valueIncr;
//				$('news_head_topic_'+(lastDiv)).getElements('div')[1].filters.item("alpha").opacity = valueDecr;
//			}
			if (valueIncr==70) {
				$('news_head_topic_'+(nextDiv)).getElements('div')[1].style.filter = "alpha(opacity=100)";
			}
			
			if (valueDecr==0 && valueIncr==100) {
				clearInterval(cssIe);
				ieFadeLock = 1;
				//$('banner_right').innerHTML += "fertig" + "<br>";
			}
		}, 1);
	
		
	} 
	
	
	
});
var timer;
var slidesh0w;
var ieFadeLock = 1;

function fx() {
	
	slidesh0w.start();
}
function startfx() {
	slidesh0w = new SlideShow("news_head_topic_0");
//	for (i = 0; i < slidesh0w.topicsCount; i++) {
//		if ($('news_head_topic').childNodes[i].nodeValue != null) $('news_head_topic').removeChild($('news_head_topic').childNodes[i]);
//		//alert("Text" + $('news_head_topic').childNodes[i].nodeValue);
//	}
//	alert(slidesh0w.topicsCount);
	timer = fx.periodical(4500);
}
window.addEvent("domready", function() {
	$('news_head_topic').addEvent("mouseover", function() {
		//alert("test");
		$clear(timer);
	});
	$('news_head_topic').addEvent("mouseout", function() {
		timer = fx.periodical(4500);
	});
	
	startfx();
	
	//alert("test???");
	
	for(i=0;i<slidesh0w.topicsCount;i++) {
		for (j=0;j<slidesh0w.topicsCount;j++) {
			
			//alert("test" + $('slideshow_pagebrowser_'+i).getElements("a")[j].innerHTML);
			$('slideshow_pagebrowser_'+i).getElements("a")[j].addEvent("click", function() {
				
				if (slidesh0w.nextDiv == (parseInt(this.innerHTML)-1)) return false;
				if (ieFadeLock != 1) return false;
				
				slidesh0w.manipulate=true;
				slidesh0w.lastDiv=slidesh0w.nextDiv;
				slidesh0w.nextDiv=(parseInt(this.innerHTML)-1);
				//alert("lastDiv: " + slidesh0w.lastDiv + ", " + "nextDiv: " + slidesh0w.nextDiv);
				fx();
			
			});
			//alert(j);
		}
	}
});
