﻿tableHover = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("matchdatenbank");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="TR") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
window.addEvent('domready', function() {
	loadTabelle('1', '2a', 'Stammkneipe CSCL 2a');
	loadRSS();
	
	$$('.tooltip').each(function(element,index) {  
		var content = element.get('title').split('::');  
		element.store('tip:title', content[0]);  
		element.store('tip:text', content[1]);  
	});
	var tooltip = new Tips('.tooltip', { className: 'tooltipbox'});
	
	$('league_dropdown').addEvent('click', function() {
		if($('league_dropdown_show').style.display == 'block') {
			$('league_dropdown_show').style.display = 'none';
		} else {
			$('league_dropdown_show').style.display = 'block';
		}
	});
	$('roster_dropdown').addEvent('click', function() {
		if($('roster_dropdown_show').style.display == 'block') {
			$('roster_dropdown_show').style.display = 'none';
		} else {
			$('roster_dropdown_show').style.display = 'block';
		}
	});
	
	var teams = $$(".players_container .players");
	teams.each(function(team, q) {
		var kwicks = team.getChildren();
		var nSize = $$('.players_container')[0].getStyle('width').toInt();
		var nFull = 120;
		var nNormal = (nSize / kwicks.length).round();
		var nNormalLast = (nSize - (nNormal * (kwicks.length-1)))+2;
		var nSmall = ((nSize / kwicks.length) - ((nFull - (nSize / kwicks.length)) / kwicks.length)).round();
		var nSmallLast = (nSize - (nSmall * (kwicks.length-2)) - nFull)+2;
		
		kwicks.setStyle('width', nNormal);
		kwicks.getLast().setStyle('width', nNormalLast);
		
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.Sine.easeOut});
		kwicks.each(function(kwick, i) {
			kwick.addEvent("mouseenter", function(event) {
				var o = {};
				var n = 0;
				o[i] = {width: [kwick.getStyle("width").toInt(), nFull]}
				kwicks.each(function(other, j) {
					if(i != j) {
						n++;
						if(n != (kwicks.length-1)) {
							var w = other.getStyle("width").toInt();
							if(w != nSmall) o[j] = {width: [w, nSmall]};
						} else {
							var w = other.getStyle("width").toInt();
							if(w != nSmallLast) o[j] = {width: [w, nSmallLast]};
						}
					}
				});
				fx.start(o);
			});
		});
		$$(".players").addEvent("mouseleave", function(event) {
			var o = {};
			var n = 0;
			kwicks.each(function(kwick, i) {
				n++;
				if(n != (kwicks.length)) {
					o[i] = {width: [kwick.getStyle("width").toInt(), nNormal]}
				} else {
					o[i] = {width: [kwick.getStyle("width").toInt(), nNormalLast]}
				}
			});
			fx.start(o);
		})
	});
});

function loadTabelle(type, liga, liganame) {
	var tabelle = new Request({ url: '/templates/inc/_tabelle.inc.php', method: 'get', data: 'type='+type+'&liga='+liga+'&cache='+cache });
	tabelle.addEvent('success', function(response, xml) {
		$('ajaxLeague').set('html', response);
		$('league_headline').set('text', liganame);
		$('ajaxLeague').style.backgroundImage = '';
	});
	tabelle.addEvent('request', function(instance) {
		$('league_headline').set('text', 'Lade Tabelle ...');
		$('ajaxLeague').set('text', ' ');
		$('ajaxLeague').style.backgroundImage = 'url(/templates/el/loading.gif)';
	});
	tabelle.send();
}

function loadRSS() {
	var rss = new Request({ url: '/templates/inc/_schlagzeilen.inc.php' });
	rss.addEvent('success', function(response, xml) {
		$('esports_headlines').set('html', response);
		$('headlines_headline').innerHTML = 'eSports Schlagzeilen';
		$('esports_headlines').style.backgroundImage = '';
	});
	rss.addEvent('request', function(instance) {
		$('headlines_headline').innerHTML = 'Lade Schlagzeilen ...';
		$('esports_headlines').innerHTML = ' ';
		$('esports_headlines').style.backgroundImage = 'url(/templates/el/loading.gif)';
	});
	rss.send();
}

function loadRoster(id, teamname) {
	var containers = $$(".players_container");
	containers.setStyle('display', 'none');
	
	$('squad'+id).setStyle('display', 'block');
	$('roster_headline').innerHTML = teamname;
	
	/*
	var roster = new Request({ url: '/templates/inc/_memberswitch.inc.php', method: 'get', data: 'rosterSquadId='+id+'&cache='+cache });
	roster.addEvent('success', function(response, xml) {
		$('ajaxRoster').set('html', response);
		$('roster_headline').innerHTML = teamname;
		$('ajaxRoster').style.backgroundImage = '';
	});
	roster.addEvent('request', function(instance) {
		$('roster_headline').innerHTML = 'Lade Team ...';
		$('ajaxRoster').innerHTML = ' ';
		$('ajaxRoster').style.backgroundImage = 'url(/templates/el/loading.gif)';
	});
	roster.send();*/
}

function hideDropdowns() {
	$('roster_dropdown_show').style.display = 'none';
	$('league_dropdown_show').style.display = 'none';
}

function toggle(id) {
	if($(id).style.display == 'none') {
		$(id).style.display = 'block';
	} else {
		$(id).style.display = 'none';
	}
}
