var oetker = {
	src: '/swf/cheltenham.swf'
	,ratios: [7,1.32,11,1.31,13,1.24,14,1.25,17,1.23,19,1.23,27,1.2,34,1.19,42,1.18,47,1.17,48,1.18,69,1.17,74,1.16,75,1.17,1.16]
};

sIFR.useStyleCheck = true;
sIFR.activate(oetker);

function homePageTeasers() {
	var counter = 0;
	var pool = $$('#teasersPool .tease');
	
	pool.each(function(box) {
		var ha3 = box.getElement('h3');
		var alter = ha3.clone();
		alter.injectAfter(ha3);
		alter.addClass('on');
		ha3.addClass('off');
			
		var a = box.getElement('a');
		a.addEvent('mouseover', function(e) {
			box.getElements('h3').each(function(el) {
				if(el.hasClass('on')) el.setStyle('display', 'block');
			});
		});

		a.addEvent('mouseout', function(e) {
			box.getElements('h3').each(function(el) {
				if(el.hasClass('on')) el.setStyle('display', 'none');
			});
		});
			
		a.addEvent('click', function(e) {
			if(a.hasClass('popup')) {
				var e = new Event(e); e.stop();
				var spl1 = String(a.href).split('?');
				var href = spl1[0];
				var hash = spl1[1];
				
				var spl2 = String(hash).split('&');
				var width = parseInt(String(spl2[0]).split('=')[1]);
				var height = parseInt(String(spl2[1]).split('=')[1]);
				
				disp_window(a.href, width, height);
			}
		});
	});
	
	var index = 0;
	if(Cookie.get('oetkerRotator') === false) {
		index = parseInt($random(0, pool.length-1));
	}
	else {
		do {
			var rand = parseInt($random(0, pool.length-1));
			var cook = parseInt(Cookie.get('oetkerRotator'));
		}
		while (rand == cook);
		index = rand;
	}
	
	alterIndex = index;
	
	Cookie.set('oetkerRotator', index);
	for(var i = 0; i < 3; i++) {
		pool[index].setStyle('display', 'block');
		if(!$defined(pool[index+1])) {
			index = 0;
		} 
		else {
			index = index + 1;
		}
	}
	
	if(pool.length == 3) {
		if(alterIndex == 1) { pool[2].injectBefore(pool[1]); }
		else if (alterIndex == 2) { pool[2].injectBefore(pool[0]); }
		else {}
	}
}

function imgChange () {
	var imgNum = Math.floor(Math.random() * 6 + 1);

	if(Cookie.get('oetkerBackground') === false) {
		Cookie.set('oetkerBackground', imgNum);
		document.getElementById("main_content").className = "bg" + imgNum;
	}
	else {
		document.getElementById("main_content").className = "bg" + Cookie.get('oetkerBackground');
	}
}

function kolorweLiterki() {
	var a = document.getElementById('id_firstlvlmenu').getElementsByTagName('a');
	    for (i=0;i<a.length;i++) {
			if (a[i].href.indexOf("fccaa1ff56e3f2994eb77c07225b43f8")!=-1) {
				a[i].innerHTML="<span style='color:#0094D3;'>D</span><span style='color:#E54097;'>l</span><span style='color:#F78E1D;'>a </span><span style='color:#0076C0;'>d</span><span style='color:#EE3423;'>z</span><span style='color:00A5D9;'>i</span><span style='color:00AA4F;'>e</span><span style='color:#F173AC;'>c</span><span style='color:#00A5D9;'>i</span>";
	    	}
		}
        
}

window.onload = function() {
	if($defined($('homepage'))) {
		imgChange();
		homePageTeasers();
	}
	kolorweLiterki();
	sIFR.replace(oetker, {
		selector: '.teaser .box h3.off, .teaser .box ul li, .left_side .teaser .box h3 a.title1'
		,css: [
	
			'.sIFR-root { text-align: left; font-weight: normal; background-color: #fbe9b9; cursor: pointer; color: #776A67 }'
			,'a { text-decoration: none; }'
			,'a:link { color: #776A67 }'
			,'a:hover { color: #c00000 }'
		]
		,wmode: 'transparent'
	});
	
	sIFR.replace(oetker, {
		selector: '.teaser .box h3.on, .teaser .box ul li'
		,css: [
			'.sIFR-root { text-align: left; font-weight: normal; background-color: #fbe9b9; color: #c00000; cursor: pointer }'
		]
		,wmode: 'transparent'
	});
	
	window.setTimeout('dimHighlight();', 500);
}


function dimHighlight() {
	$$('#teasersPool .box h3.on').each(function(h3) { h3.setStyle('display', 'none'); });
}


function disp_window(url, width, height) {
	if(window.lastWindow) {
		if(window.lastWindow.close) {
			window.lastWindow.close();
		}
	}
	var text = String(url).match(/[a-zA-Z0-9]+/g);
	var win_name ="";
	for (var a=0; a<text.length; a++) {
		win_name += text[a];
	}
	var Win = window.open(url, win_name,'width=' + width + ',height=' + height + ',resizable=1,scrollbars=0,status=yes,menubar=no,toolbar=no,left=0,top=0' );
	window.lastWindow = Win;
	Win.creator = self;
}

window.addEvent('domready', function() {
	$$('a[href*=/1d6eacdb12956b9bb43b35a94359632a]').addEvent('click', function(e) {
		e = new Event(e); e.stop();
		window.open(this.href);
	});	
});
