// JavaScript Document
//DOCUMENTATION OF PROTOTYPE API http://www.prototypejs.org/api

Event.observe(window, 'load', globalInit);

userAgent = navigator.userAgent.toLowerCase();
isIE     = ((userAgent.indexOf("msie") != -1) && (userAgent.indexOf("opera") == -1));
isOpera  = (userAgent.indexOf("opera") != -1);
isMac     = (userAgent.indexOf("mac") != -1);
isMacIE = (isIE && isMac);
isWinIE = (isIE && !isMac);
isSafari = (userAgent.indexOf("safari") != -1);
isGecko  = (navigator.product == "Gecko" && !isSafari);


function globalInit()
{
	Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
	Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
	Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;

	if($('loginLink')){
		$('loginLink').observe('click', function(e){ e.stop(); displayLoginForm(); })
	}
	initMenu();
	highlightCurrentSubSection();
	makeEventsFromLinks();
	switchCssToJs();
	//if (!isgamerclient && isloggedin){
	if (isloggedin){
		ki_checkfornewmessages();
		getQueue();
	}
	$$(".confirmfirst").each(function(obj){ confirmFirst(obj);});
	
	$$(".js-countdown").each(function(obj){ countdown(obj);});

	// admin for translations
	if(isAdminForTranslations) {
		Translations.init();
	}
	
/* 	if (isgamerclient){
		var height = document.all? document.documentElement.clientHeight : window.innerHeight;		
		if ($("wrapper").offsetHeight < height) $("wrapper").style.height = height-30 + "px";
	} */
	
	if ($("liveTicker")){
		liveTicker(10000, 60000);
	}
	//bookmark.init();
	ToggleTrigger.init();
	ToggleTriggerLeftbar.init();
	ToggleTriggerServerlist.init();
	ToggleTriggerByClassName.init();
	dropDownMenu.initialize();
	ToggleTriggerFragLive.init();
	$$(".answertext").each(function(e) {e.hide();});
	$$(".highlight").each(function(e) {Effect.Pulsate(e,{from:0.2,pulses:4})});

	
	$$(".main-games-sublink").each(function(obj){//alert(1);
		Event.observe(obj,"mouseover",function(){//alert(1);
			$$(".main-games-sublink").each(function(obj){obj.removeClassName("active");});
			this.addClassName("active");
			var gamesCategory = this.id.replace(/main\-games\-sublink\-/,"");
			$$(".main-games-all").each(function(obj){obj.style.display="none";});
			$$(".main-games-"+gamesCategory).each(function(obj){obj.style.display="block";});
		});
	});
	//$$(".action.close").invoke('observe', 'click', function(e) {Effect.BlindUp(this.up(), {duration:0.3})});
	
	$$(".action.closeandsave").invoke('observe', 'click', function(e) {		
		Effect.BlindUp(this.up(), {duration:0.3});
		
		if((this.up().id != '') && isloggedin) {	
			var url = site_base_dir + 'ajaxcall/setelementstatus/'+this.up().id+'/0';
			new Ajax.Request(url, {
			  method: 'get',
			  onSuccess: function(transport) { }
			});
		}
	});
	closeToggleTriggerContent();
	

	var popuponhoverTimeout;
	$$(".popuponhover").each(function(obj) {
		var text = obj.title;
		Event.observe(obj, "mouseover",	function(e) {toolTip(e,text);
														//popuponhoverTimeout = window.setTimeout(function(e,text){ toolTip(e,text);},2000);
													});
		Event.observe(obj, "mouseout",function(){ //window.clearTimeout(popuponhoverTimeout);
												toolTip();
												});
		obj.title="";
	});
	
	if ($("tipOfTheDayClose")){
		Event.observe("tipOfTheDayClose", 'click', function(e) {	
			Effect.BlindUp(this.up(), {duration:0.3});
			
			if((this.up().id != '') && isloggedin) {	
				var url = site_base_dir + 'ajaxcall/setelementstatus/'+this.up().id+'/0';
				new Ajax.Request(url, {
				  method: 'get',
				  onSuccess: function(transport) { }
				});
			}
		});
		Effect.Pulsate("tipOfTheDay", { pulses: 2, duration: 0.6 });
	}
	
	if ($("learnmoreSectionData"))learnMoreReArrange();
	
	markAsPremium();
	
	// if(!isgamerclient) {
		// if ($("leftBar")!=undefined && $("leftbarFadeout-spacer") && ($("content").offsetHeight>($("leftBar").offsetHeight+50))){
			// $("leftbarFadeout-spacer").hide();
		// } else if ($("leftBar")!=undefined && $("content").offsetHeight-$("leftBar").offsetHeight-50<50 && $("content").offsetHeight>$("leftBar").offsetHeight){
			// $("leftbarFadeout-spacer").className = "spacer" + 10*Math.floor(($("content").offsetHeight+40-$("leftBar").offsetHeight)/10);
		// }
	// }
	
	$$(".hide-text-on-focus").each(function(obj){
		var text = obj.value;
		Event.observe(obj, 'focus', function(){if (obj.value==text)obj.value="";});
		Event.observe(obj, 'blur', function(){if (obj.value=="")obj.value=text;});
	});
	
	$$(".home-games-menu-area").each(function(obj){
		var factor = obj.id.replace(/home\-games\-menu\-/,"");
		var left = factor * -180;
		var games_menu = $("home-games-menu");
		
		Event.observe(obj, 'mouseover', function(){
			games_menu.style.backgroundPosition="" + left + "px 0";
		});
		Event.observe(obj, 'mouseout', function(){
			games_menu.style.backgroundPosition="0 0";
		});

	});
	
	//Event.observe("home-video", 'mouseover', switchVideoSize.enlarge);
	//Event.observe("home-video", 'mouseout', switchVideoSize.reduce);
	//Event.observe("home-video-click", 'click', switchVideoSize.change);
}

function makeEventsFromLinks(){
	$$(".makeEvent").each(function(e) {
								//e.hide();
								Event.observe(e,"click",function(){ location.href = e.href});
	});
}

var switchVideoSize = {
	status: 0,
	inprocess:0,
	enlarge: function(){
		if (switchVideoSize.status==0 && !switchVideoSize.inprocess){
			switchVideoSize.status = 1;
			switchVideoSize.inprocess = 1;
			//$("home-video").morph('width:952px; height:340px;');
			new Effect.Morph('home-video', {
				style: 'width:952px; height:388px;', // CSS Properties
				//duration: 0.8, // Core Effect properties
				afterFinish: function(){switchVideoSize.inprocess=0;}
			})
		}
	},
	reduce: function(){
		if (switchVideoSize.status==1 && !switchVideoSize.inprocess){
			switchVideoSize.status = 0;
			switchVideoSize.inprocess = 1;
			//$("home-video").morph('width:350px; height:125px;');
			new Effect.Morph('home-video', {
				style: 'width:350px; height:388px;', // CSS Properties
				//duration: 0.8, // Core Effect properties
				afterFinish: function(){switchVideoSize.inprocess=0;}
			});

		}
	},
	change: function(){
		if (switchVideoSize.status) switchVideoSize.reduce();
		else switchVideoSize.enlarge();
	}
}
var Translations = {
	all : {},
	inUse : false,
	obj : false,
	remoteObj: false,
	init: function(){
		$$(".translation").each(function(obj){Translations.attach(obj);});
		
		Event.observe($("translationEditBoxClose"), 'click', function(){Effect.Fade('translationEditBox', { duration: 0.2 });Translations.inUse = false;});
		Event.observe($("translationDoneButton"), 'click', function(){Effect.Fade('translationEditBox', { duration: 0.2 });Translations.inUse = false;});
	},
	attach: function (obj){
		var update = obj.hasClassName("noupdate") ? false : true;
		Event.observe(obj, 'contextmenu', function(e){Translations.edit(e,obj,update);Event.stop(e);return false;});
		Translations.collectParams(obj);
	},
	collectParams: function(obj){
		var data = obj.title.match(/\[[a-zA-Z ]+:[a-zA-Z0-9_\-]+\]/g);
		var tmp = [];
		var params = {};
		for (var i=0; i<data.length; i++){
			tmp = data[i].replace(/[\[\]]/g,"").split(":");
			params[tmp[0]] = tmp[1];
		}
		if (params.key!=undefined){
				params.ns = params.ns==undefined ? "Default Namespace" : params.ns;
				params.ns = params.ns.replace(/ /g,"_-_-_");
				if (Translations.all[params.ns]==undefined)Translations.all[params.ns]={};
				if (Translations.all[params.ns][params.key]==undefined)Translations.all[params.ns][params.key]=[];
				Translations.all[params.ns][params.key].push(obj);
		}
	},
	edit: function(e,obj,update){
		Translations.obj = obj;
		if (Translations.inUse) return;
		Translations.inUse = true;
		var data = obj.title.match(/\[[a-zA-Z ]+:[a-zA-Z0-9_\-]+\]/g);
		var tmp = [];
		var params = {};
		for (var i=0; i<data.length; i++){
			tmp = data[i].replace(/[\[\]]/g,"").split(":");
			params[tmp[0]] = tmp[1];
		}
		if (params.key==undefined) return false;
		params.ns = params.ns==undefined ? "Default Namespace" : params.ns;
		
		var mouse = Mouse (e);
		e.preventDefault();
		Translations.popup(params.ns,params.key,mouse);
		
		Event.observe($("translationSubmitButton"), 'click', function(e){Event.stop(e);
			$('translation-blocker').style.display = "block";
			AjaxSetTranslation($('translation-key').innerHTML, $('translation-ns').innerHTML, $('translation-value').value);
			var translation = AjaxGetTranslation($('translation-key').innerHTML, $('translation-ns').innerHTML);
			$('translation-value').value = translation;
			if(update) Translations.obj.innerHTML = translation;
			var savens = params.ns.replace(/ /g,"_-_-_");
			if(update) Translations.all[savens][params.key].each(function(obj){ obj.innerHTML = translation;});
			$('translation-blocker').style.display = "none";
			Translations.obj=false;	
			Effect.Fade('translationEditBox', { duration: 0.2 });
			Translations.inUse = false;
		});
		Event.stop(e);

		Translations.obj=false;
		return false;
	},
	popup: function (ns,key,mouse){
		var obj = $("translationEditBox");
		obj.style.display="none";
		var spans = obj.getElementsByTagName("span");
		
		for (var i=0; i<spans.length; i++){
			if (spans[i].id=="translation-ns") spans[i].innerHTML = ns;
			if (spans[i].id=="translation-key") spans[i].innerHTML = key;
		}
		var tas = obj.getElementsByTagName("textarea");
		for (var i = 0; i < tas.length; i++) {
			if (tas[i].id == "translation-value") {
				tas[i].value = AjaxGetTranslation(key, ns);
			}
		}
		
		obj.style.top = (mouse.Y+10) + "px";
		obj.style.left = (mouse.X+10) + "px";
		
		var innerWidth = window.innerWidth ? window.innerWidth : (document.body.clientWidth? document.body.clientWidth : document.documentElement.clientWidth);
		var scrollX = window.pageXOffset ? window.pageXOffset : (document.body.scrollLeft? document.body.scrollLeft : document.documentElement.scrollLeft);
		obj.style.display="block";
		if ((obj.offsetWidth+obj.offsetLeft-scrollX)>innerWidth)obj.style.left = innerWidth-obj.offsetWidth-22+scrollX + "px";
		obj.style.display="none";
		obj.appear({ duration: 0.2 });
	}
};

function displayLoginForm()
{
	if($('loginform')){
		if($('loginform').visible()){
			Effect.SlideUp("loginform", {duration:0.3,scope: 'loginformscope',queue:'end', limit:2,afterFinish:function(){/*Effect.Appear("time");*/ $('loginLink').update('Login');}});
		}else{
			//$('time').hide();
			$('loginLink').update('');
			Effect.SlideDown("loginform", {duration:0.3,scope: 'loginformscope',queue:'end', limit:2,afterFinish: function(){$('usernamesmall').focus();$('loginLink').update('Hide Login');}});
		}
	}
}

function confirmFirst(obj){
	if (obj.href==undefined || obj.title==undefined) return;
	var href = obj.href.replace(/\//g,"--2F");
	href = href.replace(/:/g,"--3A");
	href = href.replace(/\./g,"--E2");
	var link = site_base_dir + "ajaxcall/confirm/" + obj.title + "/" + encodeURIComponent(href);
	obj.href="javascript: AjaxShowPopup('"+link+"', false);";
	obj.title=null;
}

function  closeToggleTriggerContent(){
	var toggleTriggersToClose = document.getElementsByClassName("closeToggleTriggerContent");

	for (var i=0;i<toggleTriggersToClose.length;i++){
		$(toggleTriggersToClose[i].id+"-content").toggle();
	}
}


function switchCssToJs(){	
	//startGameMenu();
	var links = getElementsByClassName('LegalLink');	
	for (var i=0; i<links.length; i++){
		links[i].className = "LegalLinkNoCss";
		links[i].onmouseover = function(){this.className="LegalLinkHover"};
		links[i].onmouseout = function(){this.className="LegalLinkNoCss"};
	}
}
var dropDownMenu =
{
	initialize: function(elem){
		$$(".dropDownMenu").each(function(e){ e = dropDownMenu.init(e);});
	},
	init: function(elem) {
		//get all li children and for those that have an ul as child add an observer and  put them as DropDownMenu
		var menuItems = elem.immediateDescendants();
		menuItems.each(function(e){
			if(e.getElementsBySelector('ul').size() > 0){
				e.observe('mouseover', dropDownMenu.displayDropdown);
				//e.observe('mouseout', dropDownMenu.hideDropdown)
			};
		});
	},
	displayDropdown: function(elem) {
		//alert(this.id);
		var subMenu = this.getElementsBySelector('div')[0];
		if(!subMenu.visible()){
			Effect.SlideDown(subMenu, {duration:0.1});
			//subMenu = dropDownMenu.init(subMenu);
		}
	},
	hideDropdown: function(elem) {
		// alert(this.id);
		var subMenu = this.getElementsBySelector('div')[0];
		if(subMenu.visible()){
			setTimeout(function(){Effect.SlideUp(subMenu, {duration:0.3})},2000);
		}
	}

}

var ToggleTrigger = {
	init: function(event) {
		//get array of all elements with class "toggletrigger" and add a click handler
		$$(".toggletrigger").invoke('observe', 'click', ToggleTrigger.clickHandler);
	},
	clickHandler: function(event){		
		//toggle class name of trigger to "active"
		var elemId = this.id;
		//add "-content" to the trigger id to have box id and toggle visibility
		var contentId = elemId +'-content';
		
		$(elemId).toggleClassName("active");				
		$(contentId).toggle();
	
		event.stop();
	}
};


var ToggleTriggerServerlist = {
	init: function(event) {
		//get array of all elements with class "toggletrigger" and add a click handler
		$$(".toggletriggerserverlist").invoke('observe', 'click', ToggleTriggerServerlist.clickHandler);
	},
	clickHandler: function(event){
		if(isloggedin) {
			//toggle class name of trigger to "active"
			var elemId = this.id;
			//add "-content" to the trigger id to have box id and toggle visibility
			var contentId = elemId +'-content';
			
			$(elemId).toggleClassName("active");
			
			// seems to be wrong way
			if($(elemId).hasClassName("active")) {			
				saveElementStatus(contentId, 'active');
			} else {
				saveElementStatus(contentId, 'collapsed');
			}		
			
			$(contentId).toggle();			
		}
		
		event.stop();
	}
};


var ToggleTriggerLeftbar = {
	init: function(event) {
		//get array of all elements with class "toggletrigger" and add a click handler
		$$(".toggletriggerleftbar").invoke('observe', 'click', ToggleTriggerLeftbar.clickHandler);
	},
	clickHandler: function(event){
		if(isloggedin) {
			//toggle class name of trigger to "active"
			var elemId = this.id;
			//add "-content" to the trigger id to have box id and toggle visibility
			var contentId = elemId +'-content';
			
			$(elemId).toggleClassName("active");
			
			// seems to be wrong way
			if($(elemId).hasClassName("active")) {			
				saveElementStatus(contentId, 'active');
			} else {
				saveElementStatus(contentId, 'collapsed');
			}		
			
			$(contentId).toggle();			
		}
		
		event.stop();
	}
};

var ToggleTriggerByClassName =
{
	init: function(event) {
		//get array of all elements with class "toggletrigger" and add a click handler
		$$(".toggleByClassName").invoke('observe', 'click', ToggleTriggerByClassName.clickHandler);
	},
	clickHandler: function(event){
		//toggle class name of trigger to "active"
		var elemId = this.id;
		
		var toggleObjs = document.getElementsByClassName(elemId+"-content");
		for (i = 0; i < toggleObjs.length; i++){
			//alerttoggleObjs[i]);
			toggleObjs[i].toggle();
		}
		
		
		
		$(elemId).toggleClassName("active");
		//add "-content" to the trigger id to have box id and toggle visibility
		// var contentId = elemId +'-content';
		// $(contentId).toggle();
		event.stop();
	}
};

var ToggleTriggerFragLive =
{
	init: function(event) {
		//get array of all elements with class "toggletrigger" and add a click handler
		$$(".toggletriggerfraglive").invoke('observe', 'click', ToggleTriggerFragLive.clickHandler);
	},
	clickHandler: function(event){
		var flServers = document.getElementsByClassName('toggletriggerfraglive');		
		
		for(i=0; i < flServers.length; i++) {
			var currentID = flServers[i].id;
			var curContentId = currentID +'-content';
			if ($(curContentId).visible()) {
				if(currentID != this.id) {
					$(currentID).removeClassName("active");
					$(curContentId).toggle();
					$(curContentId).removeClassName("active");
					try	{
						window.clearInterval(AjaxSessionInfosUpdaters[currentID]);
					} catch(Exception) {}
				}
			}
		}
		
		//toggle class name of trigger to "active"
		var elemId = this.id;
		$(elemId).toggleClassName("active");
		//add "-content" to the trigger id to have box id and toggle visibility
		var contentId = elemId +'-content';
		//alert('hier')
		$(contentId).toggle();
		if ($(contentId).visible())
		{
			//start data request
			AjaxSessionInfosUpdaters[elemId] = window.setInterval("AjaxRequestSessionInfo("+elemId+")",10000);
			AjaxRequestSessionInfo(elemId);
		}
		else
		{
			try	{
				window.clearInterval(AjaxSessionInfosUpdaters[elemId]);
			} catch(Exception) {}
			
			// to toggle the button to correct state in some directjoin cases
			$(elemId).removeClassName("active");
		}
		
		//stop event propagation
		event.stop();
	}
};

function startGameMenu(){	
	links = $("gameMenu");
	if(links){
		links.id = "gameMenuWithJS";
		links.onclick = function(){
			if(this.id == "gameMenuWithJS"){
				this.id="gameMenuWithJSHover";
				firstclick = 1;
				document.onclick = function(event) {
					if(firstclick == 1){
						firstclick = 0;
						return;
					}
					event = event ? event : window.event;
					if(event.target)
						eventobj = event.target;
					else
						eventobj = event.srcElement;				

					if(eventobj.className.indexOf("popup") == -1){
						links.id = "gameMenuWithJS";
					}
				};
				document.onmouseover = function(event) {
					event = event ? event : window.event;
					if(event.target)
						eventobj = event.target;
					else
						eventobj = event.srcElement;			

					if(eventobj.className.indexOf("popup") == -1){
						if(popupclosing == null)
							popupclosing = window.setTimeout("links.id = 'gameMenuWithJS';", 600);
					} else {
						window.clearTimeout(popupclosing);
						popupclosing = null;
					}
				};
			} else {
				this.id="gameMenuWithJS";
				document.onclick = null;
				document.onmouseover = null;
			}			
		};
	}
}
/**
 * dropDownMenu v0.5 sw edition
 * An easy to implement dropDown Menu for Websites, that may be based on styled list tags
 *
 * Works for IE 5.5+ PC, Mozilla 1+ all Plattforms, Opera 7+
 *
 * Copyright (c) 2004 Knallgrau New Medias Solutions GmbH, Vienna - Austria
 *
 * Original written by Matthias Platzer at http://knallgrau.at
 *
 * Modified by Sven Wappler http://www.wappler.eu
 *
 * Use it as you need it
 * It is distributed under a BSD style license
 */


/**
 * Container Class (Prototype) for the dropDownMenu
 *
 * @param idOrElement     String|HTMLElement  root Node of the menu (ul)
 * @param name            String              name of the variable that stores the result
 *                                            of this constructor function
 * @param customConfigFunction  Function            optional config function to override the default settings
 *                                            for an example see Menu.prototype.config
 */
var menu;

function configMenu() {
  this.closeDelayTime = 300;
}

function initMenu() {
  menu = new Menu('root', 'menu', configMenu);
}

var Menu = Class.create();
Menu.prototype = {

	initialize: function(idOrElement, name, customConfigFunction) {

		this.name = name;
		this.type = "menu";
		this.closeDelayTimer = null;
		this.closingMenuItem = null;

		this.config();
		if (typeof customConfigFunction == "function") {
			this.customConfig = customConfigFunction;
			this.customConfig();
		}
		this.rootContainer = new MenuContainer(idOrElement, this);
	},

	config: function() {
	  this.collapseBorders = true;
	  this.quickCollapse = true;
	  this.closeDelayTime = 500;
	}

}

var MenuContainer = Class.create();
MenuContainer.prototype = {
	initialize: function(idOrElement, parent) {
		this.type = "menuContainer";
  		this.menuItems = [];
		this.init(idOrElement, parent);
	},

	init: function(idOrElement, parent) {
	  this.element = $(idOrElement);
	  if (this.element == null)
		return;
	  this.parent = parent;
	  this.parentMenu = (this.type == "menuContainer") ? ((parent) ? parent.parent : null) : parent;
	  this.root = parent instanceof Menu ? parent : parent.root;
	  this.id = this.element.id;
	  
	  if (this.type == "menuContainer") {
	  	if (this.element.hasClassName("level1")) this.menuType = "horizontal";
		else if (this.element.hasClassName("level2")) this.menuType = "dropdown";
		else this.menuType = "flyout";

	    if (this.menuType == "flyout" || this.menuType == "dropdown") {
	      this.isOpen = false;
		  Element.setStyle(this.element,{
	      	position: "absolute",
	      	top: "0px",
	      	left: "0px",
	      	visibility: "hidden"});
	    } else {
	      this.isOpen = true;
	    }
	  } else {
	    this.isOpen = this.parentMenu.isOpen;
	  }

	  var childNodes = this.element.childNodes;
	  if (childNodes == null) return;

	  for (var i = 0; i < childNodes.length; i++) {
	    var node = childNodes[i];
	    if (node.nodeType == 1) {
	      if (this.type == "menuContainer") {
	        if (node.tagName.toLowerCase() == "li") {
	          this.menuItems.push(new MenuItem(node, this));
	        }
	      } else {
	        if (node.tagName.toLowerCase() == "ul") {
	          this.subMenu = new MenuContainer(node, this);
	        }
	      }
	    }
	  }
	},

	getBorders: function(element) {
	  var ltrb = ["Left","Top","Right","Bottom"];
	  var result = {};
	  for (var i = 0; i < ltrb.length; ++i) {
	    if (this.element.currentStyle)
	      var value = parseInt(this.element.currentStyle["border"+ltrb[i]+"Width"]);
	    else if (window.getComputedStyle)
	      var value = parseInt(window.getComputedStyle(this.element, "").getPropertyValue("border-"+ltrb[i].toLowerCase()+"-width"));
	    else
	      var value = parseInt(this.element.style["border"+ltrb[i]]);
	    result[ltrb[i].toLowerCase()] = isNaN(value) ? 0 : value;
	  }
	  return result;
	},

	open: function() {
	  if (this.root.closeDelayTimer) window.clearTimeout(this.root.closeDelayTimer);
	  this.parentMenu.closeAll(this);
	  this.isOpen = true;
	  if (this.menuType == "dropdown") {
		Element.setStyle(this.element,{
			left: (Position.positionedOffset(this.parent.element)[0]) + "px",
			top: (Position.positionedOffset(this.parent.element)[1] + Element.getHeight(this.parent.element)) + 4 +"px",
			zIndex: (999)
		});
		var currentLeft = this.element.getStyle("left").replace(/px/,"");
		var currentWidth = this.element.offsetWidth;
		var availWidth = $("root").offsetWidth;
		if ((availWidth-currentWidth-currentLeft)<0){
			var newLeft = availWidth-currentWidth;
			Element.setStyle(this.element,{
				left: newLeft + "px"
			});
		}
		
	  } else if (this.menuType == "flyout") {
	    var parentMenuBorders = this.parentMenu ? this.parentMenu.getBorders() : new Object();
	    var thisBorders = this.getBorders();
	    if (
	      (Position.positionedOffset(this.parentMenu.element)[0] + this.parentMenu.element.offsetWidth + this.element.offsetWidth + 20) >
	      (window.innerWidth ? window.innerWidth : document.body.offsetWidth)
	    ) {
			Element.setStyle(this.element,{
	      		left: (- this.element.offsetWidth - (this.root.collapseBorders ?  0 : parentMenuBorders["left"])) + "px"
			});
	    } else {
			Element.setStyle(this.element,{
	    		left: (this.parentMenu.element.offsetWidth - parentMenuBorders["left"] - (this.root.collapseBorders ?  Math.min(parentMenuBorders["right"], thisBorders["left"]) : 0)) + "px"
			});
	    }
		Element.setStyle(this.element,{
	    	top: (this.parent.element.offsetTop - parentMenuBorders["top"] - this.menuItems[0].element.offsetTop) + "px"
		});
	  }
	  Element.setStyle(this.element,{visibility: "visible"});
	},

	close: function() {
		Element.setStyle(this.element,{visibility: "hidden"});
		this.isOpen = false;
		this.closeAll();
	},

	closeAll: function(trigger) {
		for (var i = 0; i < this.menuItems.length; ++i) {
			this.menuItems[i].closeItem();
		}
		
	}

}

var MenuItem = Class.create();

Object.extend(Object.extend(MenuItem.prototype, MenuContainer.prototype), {
	initialize: function(idOrElement, parent) {
		var menuItem = this;
		this.type = "menuItem";
		this.subMenu;
		this.init(idOrElement, parent);
		if (this.subMenu) {
			this.element.onmouseover = function() {
				menuItem.subMenu.open();
			}
		} else {
		if (this.root.quickCollapse) {
		  this.element.onmouseover = function() {
			menuItem.parentMenu.closeAll();
		  }
		}
		  }
		  var linkTag = this.element.getElementsByTagName("A")[0];
		  if (linkTag) {
		 linkTag.onfocus = this.element.onmouseover;
		 this.link = linkTag;
		 this.text = linkTag.text;
		  }
		  if (this.subMenu) {
		 this.element.onmouseout = function() {
			  if (menuItem.root.openDelayTimer) window.clearTimeout(menuItem.root.openDelayTimer);
			  if (menuItem.root.closeDelayTimer) window.clearTimeout(menuItem.root.closeDelayTimer);
			  eval(menuItem.root.name + ".closingMenuItem = menuItem");
			  menuItem.root.closeDelayTimer = window.setTimeout(menuItem.root.name + ".closingMenuItem.subMenu.close()", menuItem.root.closeDelayTime);
			}
		  }
	},

	openItem: function() {
	  this.isOpen = true;
	  if (this.subMenu) { this.subMenu.open(); }
	},

	closeItem: function(trigger) {

	  this.isOpen = false;
	  if (this.subMenu) {
	    if (this.subMenu != trigger) this.subMenu.close();
	  }
	}
});




var rotatePartners = {
	init: function(event) {
		var partnerRotator = window.setInterval("rotatePartners.rotate()", 5000);
	},
	rotate: function(event){
		var partners = $$(".rotatePartner");
		var distance = partners[0].offsetWidth;
		new Effect.Move('pa_partners_move', { x: -distance, y: 0, mode: 'relative' });
		window.setTimeout("rotatePartners.reform()", 2000);
	},
	reform: function(event){
		var partners = $$(".rotatePartner");
		//partners[0].style.display ="none";
		$('pa_partners_move').insertBefore(partners[0],partners[partners.length-1].nextSibling);
		$('pa_partners_move').style.left="0";
		
	}
};

var bookmark = {
	init: function(){
		$$(".bookmark").each(function(e) {bookmark.create(e);});
	},
	create: function(obj){
		var service = obj.title;
		var bookmarkers = {
			wong: {
				name: "Mister Wong",
				url: "http://www.mister-wong.de/index.php?action=addurl&amp",
				params: new Array ("bm_url", "bm_description")
			},
			delicious: {
				name: "del.icio.us",
				url: "http://del.icio.us/post?",
				params: new Array ("url", "title")
			},
			digg: {
				name: "digg.com",
				url: "http://digg.com/submit?phase=2&",
				params: new Array ("url")
			},
			technorati: {
				name: "technorati",
				url: "http://technorati.com/cosmos/search.html?",
				params: new Array ("url")
			},
			blinklist: {
				name: "blinklist",
				url: "http://blinklist.com/index.php?Action=Blink/addblink.php&",
				params: new Array ("url", "title")
			},
			webnews: {
				name: "Webnews",
				url: "http://www.webnews.de/einstellen?",
				params: new Array ("url", "title")
			},
			bonitrust: {
				name: "BoniTrust",
				url: "http://www.bonitrust.de/account/bookmark/??",
				params: new Array ("bookmark_url")
			},
			oneview: {
				name: "Oneview",
				url: "http://www.oneview.de/quickadd/neu/addBookmark.jsf?",
				params: new Array ("URL", "title")
			},
			linkarena: {
				name: "Linkarena",
				url: "http://linkarena.com/bookmarks/addlink/?",
				params: new Array ("url", "title", "desc","tags")
			},
			favoriten: {
				name: "Favoriten",
				url: "http://www.favoriten.de/url-hinzufuegen.html?",
				params: new Array ("bm_url", "bm_title")
			},
			seekxl: {
				name: "Seekxl",
				url: "http://social-bookmarking.seekxl.de/?",
				params: new Array ("add_url", "title")
			},
			kledy: {
				name: "Kledy",
				url: "http://www.kledy.de/submit.php?",
				params: new Array ("url")
			},
			readster: {
				name: "Readster",
				url: "http://www.readster.de/submit/?",
				params: new Array ("url", "title")
			},
			publishr: {
				name: "Publishr",
				url: "http://www.publishr.de/account/bookmark/?",
				params: new Array ("bookmark_url")
			},
			icio: {
				name: "Icio",
				url: "http://www.icio.de/add.php?",
				params: new Array ("url")
			},
			bookmarkscc: {
				name: "Bookmarks.cc",
				url: "http://www.bookmarks.cc/bookmarken.php?action=neu&amp;",
				params: new Array ("url", "title")
			},
			favit: {
				name: "Favit",
				url: "http://www.favit.de/submit.php?",
				params: new Array ("url")
			},
			newsider: {
				name: "Newsider",
				url: "http://www.newsider.de/submit.php?",
				params: new Array ("url")
			},
			linkssilo: {
				name: "Linksilo",
				url: "http://www.linksilo.de/index.php?area=bookmarks&amp;func=bookmark_new&amp;",
				params: new Array ("addurl", "addtitle")
			},
			yigg: {
				name: "Yigg",
				url: "http://yigg.de/neu?",
				params: new Array ("exturl")
			},
			facebook: {
				name: "Facebook",
				url: "http://www.facebook.com/sharer.php?",
				params: new Array ("u", "t")
			},
			reddit: {
				name: "Reddit",
				url: "http://reddit.com/submit?",
				params: new Array ("url", "title")
			},
			jumptags: {
				name: "Jumptags",
				url: "http://www.jumptags.com/add/?",
				params: new Array ("url", "title")
			},
			simpy: {
				name: "Simpy",
				url: "http://www.simpy.com/simpy/LinkAdd.do?",
				params: new Array ("href", "title", "note","tags")
			},
			stumbleupon: {
				name: "StumbleUpon",
				url: "http://www.stumbleupon.com/submit?",
				params: new Array ("url", "title")
			},
			slashdot: {
				name: "Slashdot",
				url: "http://slashdot.org/bookmark.pl?",
				params: new Array ("url", "title")
			},
			propeller: {
				name: "Propeller",
				url: "http://www.propeller.com/submit/?",
				params: new Array ("U", "T")
			},
			yahoo: {
				name: "Yahoo",
				url: "http://myweb2.search.yahoo.com/myresults/bookmarklet?",
				params: new Array ("u", "t","d","tag")
			},
			spurl: {
				name: "Spurl",
				url: "http://www.spurl.net/spurl.php?v=3&amp;",
				params: new Array ("url", "title", false,"tags")
			},
			google: {
				name: "Google",
				url: "http://www.google.com/bookmarks/mark?op=add&amp;hl=de&amp;",
				params: new Array ("bkmk", "title", "annotation","labels")
			},
			blogmarks: {
				name: "Blogmarks",
				url: "http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;",
				params: new Array ("url", "title", "content","public-tags")
			},
			diigo: {
				name: "Diigo",
				url: "http://www.diigo.com/post?",
				params: new Array ("url", "title", "comments","tag")
			},
			newsvine: {
				name: "Newsvine",
				url: "http://www.newsvine.com/_wine/save?popoff=1&amp;",
				params: new Array ("u", "blurb",false,"tags")
			},
			blinkbits: {
				name: "Blinkbits",
				url: "http://www.blinkbits.com/bookmarklets/save.php?v=1&amp;",
				params: new Array ("source_url", "title", false,false,"rss_feed_url","source_image_url")
			},
			netvouz: {
				name: "Netvouz",
				url: "http://www.netvouz.com/action/submitBookmark?",
				params: new Array ("url", "title", "description","tags")
			}
		};
		
		var url = bookmarkers[service].url;
		var name = bookmarkers[service].name;
		var params = bookmarkers[service].params;
		
		var bookmarkLink = url + params[0] + "=" + encodeURIComponent(location.href);
		
		var description = "Cash in on your skills: play your favorite games and earn money!";
		var tags = "PlayAll,FragLive,FragPot,Gaming,Counter strike,Call of Duty, Team Fortress";
		var rsslink = site_base_dir + "rss/20/overview";
		var favicon = site_base_dir_img + "playall_favicon.png";
		
		if (params.length>1 && params[1]) bookmarkLink += "&" + params[1]+ "=" + encodeURIComponent(document.title);
		if (params.length>2 && params[2]) bookmarkLink += "&" + params[2]+ "=" + encodeURIComponent(description);
		if (params.length>3 && params[3]) bookmarkLink += "&" + params[3]+ "=" + encodeURIComponent(tags);
		if (params.length>4 && params[4]) bookmarkLink += "&" + params[4]+ "=" + encodeURIComponent(rsslink);
		if (params.length>5 && params[5]) bookmarkLink += "&" + params[5]+ "=" + encodeURIComponent(favicon);
		
		var img = Builder.node("img",{src:site_base_dir_img + "bookmark/" + service + ".gif"});
		obj.appendChild(img);
		
		obj.href = bookmarkLink;
		obj.title = "bookmark this on " +  name;
	}
};
	
		
String.prototype.getOptions = function() {
	var data = this.match(/\[[a-zA-Z]+::[a-zA-Z0-9_;\+%\-# \.\?\!\\\/:=&\|\(\)\{\}]+\]/g);
	var tmp = [];
	var valArray = [];
	var params = {};
	for (var i=0; i<data.length; i++){
		tmp = data[i].replace(/[\[\]]/g,"").split("::");
		if (tmp==undefined || tmp[0]==undefined || tmp[1]==undefined) continue;
		if (!tmp[1].match(/\|/g)) params[tmp[0]] = tmp[1];
		else{
			valArray = tmp[1].split("|");
			params[tmp[0]] = valArray;
		}
	}
	return params;
};


function learnMoreReArrange(){
	var ref = $("learnmoreSectionData");
	var whereToMove = $("learnMoreSecondColumn");
	var whereToMoveSecond = $("learnMoreThirdColumn");
	var allContainer = ref.getElementsByTagName("div");
	var container = [];
	var containerHeights = [];
	var sumHeight=0;
	var heightToReach;
	var currentHeight =0;
	
	for (var i=0; i<allContainer.length; i++){
		if (allContainer[i].className.match(/container/)){
			container.push(allContainer[i]);
			containerHeights.push(allContainer[i].offsetHeight);
			sumHeight += allContainer[i].offsetHeight;
		}					
	}
	
	heightToReach = sumHeight/2;
	i=0;
	while (currentHeight < heightToReach){
		currentHeight += containerHeights[i];
		i++;
	}
	if (Math.abs(currentHeight-heightToReach) > Math.abs(currentHeight-containerHeights[i-1] -heightToReach)) i--;
	
	for (j = i; j<container.length; j++){
		whereToMove.appendChild(container[j]);
	}
}

function markAsPremium(){
	try {
		var obj = $("mark-id-as-premium");
		if (obj){
			var id = obj.innerHTML;
			if($(id)) {
				obj.classNames().each(function(str){$(id).addClassName(str);});
			}
		}
	} catch(e) { }
}

function countdown(obj){
	var time_left = obj.title-1;
	obj.title = time_left;
	if (time_left==undefined || time_left<=0){
		time_left=0;
	}	
	if (time_left>86400){
		var days = Math.floor(time_left/86400);
		obj.innerHTML = days + " day(s)";
		return;
	}
	var hours = Math.floor(time_left/3600);
	var minutes = Math.floor((time_left-hours*3600)/60);
	var seconds = time_left - hours*3600 - minutes*60;
	hours = hours<10 ? "0" + hours : "" + hours;
	minutes = minutes<10 ? "0" + minutes : "" + minutes;
	seconds = seconds<10 ? "0" + seconds : "" + seconds;
	
	obj.innerHTML = hours + ":" + minutes + ":" + seconds;
	if (time_left>0) setTimeout(function(){countdown(obj);}, 1000);
	return;
}