﻿GameBaseClient = new Hash.Cookie('GAMEBASE_CL',{duration:365,path:'/'});

function startSlideshow(){
	if($('heading')){
		headerSlideshow = new gallery($('heading'),{
		elementSelector: "div.container",
		titleSelector: "h3",
		subtitleSelector: "p",
		imageSelector: "img",
		showArrows: false,
		showCarousel: false,
		embedLinks: false,
		timed: true,
		//showInfopane:false,
		baseClass: "headerSlideshow",
		defaultTransition: "crossfade",
		slideInfoZoneSlide: false,
		slideInfoZoneOpacity: 1
		
	});
	
$('heading').addEvent('mouseenter',function(){
		$('heading').getElement('h2 a').setStyle("display","none");
		$('heading').getElement('.slideInfoZone').setStyle("display","block");
		
});
$('heading').addEvent('mouseleave',function(){
		$('heading').getElement('h2 a').setStyle("display","block");
		$('heading').getElement('.slideInfoZone').setStyle("display","none");

});
}
}



function loginFields(){
	var qAutologinVisible = false;
	
	/*var showAutologin = new Fx.Style("qLogin","height",{
		duration:100,
		onStart:function(){qAutologinVisible=true;}
		});*/
	
	if($('lNick')){
	
	var showAutologin = new Fx.Tween("qLogin",{
		duration:100//,
		//onStart:function(){qAutologinVisible=true;}
		}).start('height');
	
	var lNick = $('lNick');
	var lPass = $('lPass');
	//var lPassText = $('lPassText');
	
	//neues passwort feld erzeugen
	var lPassText = new Element("input",{
		"type":"text",
		"name":"passText",
		"id":"lPassText",
		"value":qLoginPass ,//text kommt aus der webseite
		"class":"formField ffInput",
		"styles":{
			"display":"inline"
		}
	});
	
	lPassText.inject("lPass","after");
	
	//lPassText.setStyle('display','inline');
	
	lPass.setStyle('display','none');
	
	//submitbutton ndern
	
	var statusSubmit = new Element("a",{
		"class":"statusBarSubmit",
		"href":"#"
	});
	
	var statusText = new Element("span").set('text', qLoginSubmit)
	statusSubmit.adopt(statusText);
		
	statusSubmit.inject($("qLogin").getElement("button"),'before');
	$("qLogin").getElement("button").addClass("ieFakeSubmit");
	
	
	lNick.addEvent('focus',function(evt){
		if(!qAutologinVisible){
			
			showAutologin.start('height','50');
			}
		if(lNick.value == lNick.defaultValue)
			lNick.value = "";
	});
	
	lNick.addEvent('blur',function(evt){
		if(lNick.value == "")
			lNick.value = lNick.defaultValue;
	});

	
	lPass.addEvent('blur',function(evt){
		if(lPass.value == ""){
			lPass.setStyle('display','none');
			lPassText.setStyle('display','inline');
		}
	});
	
	lPassText.addEvent('focus',function(evt){
		if(!qAutologinVisible)
			showAutologin.start('height','50');
		lPassText.setStyle('display','none');
		lPass.setStyle('display','inline');
		lPass.focus();
	});

}

/*submit mit normalem link*/


if($('qLogin')){

	$('qLogin').getElement('.statusBarSubmit').addEvent('click',function(){
			if($('lNick').value == $('lNick').defaultValue)
				$('lNick').value = '';
			$('qLogin').submit();
	});
/*
	$('qLogin').addEvent('keydown',function(event){
			event = new Event(event);
			if(event.key == 'enter'){
				if($('lNick').value == $('lNick').defaultValue)
					$('lNick').value = '';
				$('qLogin').submit();
			}
	});*/

}
}



function gamesMenu(start){
	var  sideBarGames = new Accordion('#gamesCatTabs a','#gamesBar ul',{
	 	show: start,

		opacity: false,
		onActive: function(toggler, element){
			element.getParent().getElement('.gamesCatHeader').setStyle('display','block');
			$('gamesCatTabs').setStyle('background-position','0px -'+$('gamesCatTabs').getElements('a').indexOf(toggler) * $('gamesCatTabs').getStyle('height').toInt()+'px');
			$(element).setStyle('zoom','1');
		},

		onBackground: function(toggler, element){
			element.getParent().getElement('.gamesCatHeader').setStyle('display','none');
		}
	},$('gamesBar'));
	
	
	
	
	var sideBarTips = new Tips($$('#gamesCatTabs a'),{
		onShow: function(toolTip){
			//toolTip.set('opacity',0);
			toolTip.fade('in');
		},
		onHide: function(toolTip){
			toolTip.fade('out');
		},
	/*
		offsets:{
			y:-40
		},*/
		className: "sideBarTips-tip"
	});
		
}



function setLangMultiFormat(iso){
	var langExpr, loc, mode, langRepl, newLoc;
	/*
	0: findet /en/
	1: findet lang=en oder lang~en
	2: findet id_lang=2 oder id_lang~2
	*/
	langExpr = /[^:]*:\/\/[^\/]*\/(?:(?:[^\/]*\/(\w{2})\/)|(?:.*[\?&~\/](?:(?:id_lang(?:=|~)(\d{1,}))|(?:lang(?:=|~)(\w{2})))))?.*/;
	loc = self.location.href;
	langExpr.exec(loc);

	/*
	0: suchmuster fr /en/
	1: suchmuster fr id_lang=2 oder id_lang~2
	2: suchmuster fr lang=en oder lang~en
	*/	
	langRepl = [/(.*\/)\w{2}(\/.*)/,/(.*[?&~/])id_lang(=|~)\d+(.*)/,/(.*[?&~/])lang(=|~)\w{2}(.*)/];
	
	//welches suchmuster soll angewendet werden
	mode = (RegExp.$1)?'0':(RegExp.$2)?'1':(RegExp.$3)?'2':'3';
	//suchmuster auswhlen
	langRepl = langRepl[mode];

	if(mode == 0){
		newLoc = loc.replace(langRepl, '$1'+iso+'$2');
	}
	else if(mode == 3){
		
		var LangAnchor = /([^#]*)(#?.*)$/; // trennt sprungziel von der url
		var LangType = /(?:(\?|&)|(~)|(.+\/)|((?:~[^/]+)|(?:=[^&]+))|([^?&~/]))$/;// nochmal suchmuster fr urlendungen
		var noPath = /^.*:\/\/[^/]*\/$/;
		/*
		1
		/? => ?
		/& => &
		
		2
		/display/page~ => &lang=de
		
		3
		/display/page~register_start/ => lang.html?lang=de
		
		4
		/display/page~register_start => &lang=de
		
		5
		/display/page~register_start/Registration.html => ?lang=de
		*/

		LangAnchor = LangAnchor.exec(loc);//anker von url trennen
		LangType = LangType.exec(LangAnchor[1]);//suchmuster whlen
		LangType = LangType[1]?'':LangType[2]?'&':LangType[3]?'lang.html?':LangType[4]?'&':'?';//was muss gendert werden
		
		if(noPath.test(loc))
			LangType = '?';
			
		
		
		
		newLoc = LangAnchor[1]+LangType+'lang='+iso+LangAnchor[2];//url zusammenbauen und anker wieder anhngen
		
	
	}
	else{
		newLoc = loc.replace(langRepl, '$1lang$2'+iso+'$3');			
	}
	self.location.href= newLoc;
	
}




function languageMenu(){
	if($('languages')){
		
		var min =$('languages').getElement('li').getSize().y;
		var max =$('languages').getElement('ul').getSize().y;
		
			$('languages').setStyle('height',min);
			

			
			
			
		langMenu = new Fx.Morph('languages',{
				duration:400,
				wait:false,
				transition:Fx.Transitions.Cubic.easeInOut
		});
	
		$('languages').addEvent('mouseenter',function(){
				langMenu.start({
					'height':max
				});
		});
	
		$('languages').addEvent('mouseleave',function(){
				langMenu.start({
					'height':min
				});
		});	
		/*
		document.getElements('a','languages').each(function(el,index){
			
		});
		*/
	}
}


/*currency dings*/
function currencyMenu(){
	if($('currencyContainer') && $('amountOfMoney')){
	
	var min= 0;
	var max= $('currency').getSize().y;
	
	$('currencyContainer').injectInside('amountOfMoney');
	
		var currMenu = new Fx.Morph('currencyContainer', {duration:400, wait:false, transition: Fx.Transitions.Cubic.easeInOut});
	
		$('amountOfMoney').addEvent('mouseenter', function(){
			currMenu.start({
				'height': max
			});
		});
		
		$('amountOfMoney').addEvent('mouseleave', function(){
			currMenu.start({
				'height': min
			});
		});	
	}
}



function fadeTip(element){
	if(element && !(element.getParent().hasClass('casinoTip'))){
		tipStyle = new Fx.Morph(element,{duration:1000, link: 'cancel', transition: Fx.Transitions.Cubic.easeInOut});
		(function(){tipStyle.start({
						'background-color':'#EBF1F7',
						'border-top-color':'#BACFE0',
						'border-right-color':'#BACFE0',
						'border-bottom-color':'#BACFE0',
						'border-left-color':'#BACFE0',
						'color':'#3A3E47'
		});}).delay(2000);
	}
}





window.addEvent('domready',function(){

/*
	var rmgBadge = new Swiff("js/rmgBadge/rmg.swf", {
							 id: 'rmgBadge_movie',
							 width: 45,
							 height:45,
							 container: 'rmgBadge'
							 
							 });
									
	
		if(Browser.Engine.trident4){
		$$('input,select,textarea,button,.ieHover').each(function(el){
			el.addEvent('mouseover',function(){
				el.addClass("hover");
			});
			el.addEvent('mouseout',function(){
				el.removeClass("hover");
			});
			el.addEvent('focus',function(){
				el.addClass("focus");
				
			});
			el.addEvent('blur',function(){
				el.removeClass("focus");
			});
		});
	}
	
*/	
	
	/*
	if(window.ie){//hover,focus fr alle inputelemente - ev noch weitere hinzufgen
		$$('input,select,textarea,button').each(function(el){
			el.addEvent('mouseover',function(){
				el.addClass("hover");
			});
			el.addEvent('mouseout',function(){
				el.removeClass("hover");
			});

			el.addEvent('focus',function(){
				el.addClass("focus");
			});
			el.addEvent('blur',function(){
				el.removeClass("focus");
			});
		});
	}
	*/
	//startSlideshow();
	
	fadeTip();

/*
$$('p,ul,ol,h1,h2,h3,h4,h5,h6').each(function(el){
morphFont = new Fx.Styles(el,{	duration:1500	});
{morphFont.start({
	'text-align':['left','right'],
	'letter-spacing':[-60,0]
	});
});
	*/
	
	loginFields();
	
	languageMenu();

	currencyMenu();

/*der opera schnallts sonnst irgendwie nicht*/
if($('main')){
$('main').getElements('.gameLogo').each(function(el){
	var shade = new Element("span",{
			"class":"shade"
	});	
	shade.inject(el.getElement('a'));	
	
	//keine ahnung warum der opera das da nicht will..
	//&weil er spinnt bekommt ers garnicht
	if(!window.opera)
		el.getElement('img').reflect({height:0.2,opacity:0.3});
});
}

/*
$$('.gameLogo a').each(function(el){
	var shade = new Element("span",{
			'class':'shade'
	});
	
	shade.injectInside(el);

	
});

//reflection

$$('.gameLogo img').each(function(el){
		el.reflect({height:0.2,opacity:0.3});
	});
*/




//das brauchen wir fr den armen ie 6 der mal wieder probs hat - wegen dem reflextion script
//das wird nur gemacht wenn die classe room nicht gesetzt ist - denn da haben wir schon sowas

document.getElements('.gameLogo a').each(function(el){
	if(!el.hasClass("room") && !el.getProperty("rel")){
		el.addEvent('click',function(evt){
			evt.preventDefault();
			self.location.href=el.getProperty('href');
		});
	}
});	
	
	
	/*fr die kleinen icons bei den spielen auf der games seite*/
var gameIcons = new Tips('.gameIcons img',{
		initialize: function(){
			toolName.addClass("gameIcon");
			//this.fx = new Fx.Tween(this.toolTip).set('opacity',0);
		},
		onShow: function(toolTip){
			toolTip.fade('in');
			//this.fx.start(1);
		},
		onHide: function(toolTip){
		toolTip.fade('out');
			//this.fx.start(0);
		},	
	className:"gameIcon-tip"
});	



	/*
var formTips = new Tips($$('.formTips'),{
		fixed:true,
		className:"formTip",
		offsets:{
			y:-10,
			x:375
		}
});
*/
	
	
/*

	if(typeof sIFR == "function"){
		sIFR.replaceElement("#startGame .play", named({
			sFlashSrc: "/xsl_gamebase/_stargames/data/theserifblack.swf",
			sWmode:"transparent",
			sFlashVars: "offsetTop=5&textalign=center"
	
		}));
		
		sIFR.replaceElement(".feature .play", named({
			sFlashSrc: "/xsl_gamebase/_stargames/data/theserifblack.swf",
			sWmode:"transparent",
			sFlashVars: "offsetTop=5"
		}));
	};
	
	*/
	
	
	/*
	if(document.getElement('body[class^=warning_]')){
		$(document.body).addClass("min");
	}
	*/
	
	/*
	if(document.getElement('body[class=games]')){
			top.opener = null;
	}	
	
	else*/ if((document.getElement('body').hasClass("login") && top.opener && !top.opener.closed) || (document.getElement('body[class^=warning_]') && !document.getElement('body').hasClass('warning_disconnect')) || document.getElement('body').hasClass("room")){
		$(document.body).addClass("min");
	}
	
	else if(document.getElement('body[class^=payment]')){
		$(document.body).addClass("payment");
	}
	


if(document.getElement('body[class^=game]')){
		if($('btnGames'))$('btnGames').addClass("active");
}else if(document.getElement('body[class^=tourn]')){
		if($('btnTourn'))$('btnTourn').addClass("active");
}





	//real und fun boxen gleich hoch machen
	
	
	if($('regPlayForFun') && $('regPlayForReal')){
		var theHeight = Math.max($('regPlayForFun').getElement('.container').getStyle('height').toInt(),$('regPlayForReal').getElement('.container').getStyle('height').toInt());
		$('regPlayForFun').getElement('.container').setStyle('height',theHeight);
		$('regPlayForReal').getElement('.container').setStyle('height',theHeight);
	}
	
	

//FUN REAL buttons machen das selbe wie der link in der box

	$$('#regPlayForReal,#regPlayForFun').each(function(el,index){
		
		var theLink = el.getElement('.next a');
		
		el.getElement('button').addEvent('click',function(){
			if(theLink.hasClass("opener")){
				
			loadOpenerNew(theLink);}
			else{
				
			self.location.href = theLink.getProperty("href");}
		});
	});
	
	$$('a.opener').each(function(el){
		el.addEvent('click',function(evt){
			evt.preventDefault();
			loadOpenerNew(el);
		});
	});

	$$('a.profile').each(function(el){
		el.addEvent('click',function(evt){
			evt.preventDefault();
			popupWindowNew(470,400,"scrollbars=yes",el);
		});
	});
	
	$$('a.room_casino').each(function(el){
		el.addEvent('click',function(evt){
		var ratio = 1.25;
		var width = screen.width-100;
		var height = screen.height-100;					 
			evt.preventDefault();
//			openWindow(el.getProperty('href'),'_blank','scrollbars=yes,resizable=yes',+window.getWidth(),window.getHeight());
//doch wieder popups,location=yes,status=yes
			openWindow(el.getProperty('href'),'_blank','resizable=yes',980,764);
		});
	});
	
	$$('a.room').each(function(el){
		el.addEvent('click',function(evt){
			evt.preventDefault();
//			openWindow(el.getProperty('href'),'_blank','scrollbars=yes,resizable=yes',+window.getWidth(),window.getHeight());
//doch wieder popups,location=yes,status=yes
			openWindow(el.getProperty('href'),'_blank','scrollbars=yes,resizable=yes',980,764);
		});
	});
	
	formErrors.each(function(el,index){
		var input = (document.getElement('input[id='+el+']'))?document.getElement('input[id='+el+']'):$(el);
		$(input.parentNode.parentNode).addClass("formError");
	});

//fr die systemcheck eine classe setzen

if(document.getElement(".warning_systemcheck #warningBox"))
	document.getElement(".warning_systemcheck #warningBox").addClass("infoBox");
});



function setGameSize(size){
		top.GameBaseClient.set('gameSize',size);
		top.$('gameSize').selectedIndex = size;
		
		var sizes = ['gameSmall','gameMed','gameLarge']
		
		sizes.each(function(el,i){
			$(top.document.body).removeClass(el);
		});
		$(top.document.body).addClass(sizes[size]);	
	var nWidth = top.$('gameFrame').getStyle('width');
	var nHeight = top.$('gameFrame').getStyle('height');
	var theGame = top.frames[0].document.getElementById("gameApplet");
	//spielgrsse
	theGame.style.height = nHeight;
	theGame.style.width = nWidth;

	//wie gross ist der wrapper
	var wSize = top.$("wrapper").getSize();
	
	var nWidth = wSize.x;//+17//+scrollbar;
	var nHeight = wSize.y+28;//+footer

	if(top.outerHeight) {
		nHeight = nHeight+(top.outerHeight-top.innerHeight);
		nWidth = nWidth+(top.outerWidth-top.innerWidth);
	//resize
		top.resizeTo(Math.min(nWidth+17, screen.availWidth),Math.min(nHeight, screen.availHeight));//17px fr scrollbar
	}
	else {
		ieResize(nWidth,nHeight);
		top.$('gameSettings').setStyle('right', (GetInnerSize()[0] - Math.min(nWidth,GetInnerSize()[0])+27)+'px');
	}
	top.moveTo(Math.max(0,screen.availWidth/2-nWidth/2),Math.max(0,screen.availHeight/2-nHeight/2));
}
		
	
function GetInnerSize() {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (top.document.documentElement && top.document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = top.document.documentElement.clientWidth;
		y = top.document.documentElement.clientHeight;
	}
	else if (top.document.body) // other Explorers
	{
		x = top.document.body.clientWidth;
		y = top.document.body.clientHeight;
	}
	return [x,y];
	}
	
	
function ieResize (w, h) {
	x = top.screenLeft || top.screenX;
	y = top.screenTop || top.screenY;

	top.moveTo(0,0);
	top.resizeTo(screen.availWidth,screen.availHeight);

	var inner = GetInnerSize();

	var ox = screen.availWidth-inner[0];
	var oy = screen.availHeight-inner[1];

	top.resizeTo(w+ox, h+oy);
}





function pgPrint(){
	var theUrl=self.location.href;
	
var theExpr=/.*(\?|~|&).*/;
var delimiter=(theExpr.exec(theUrl))?"&":"?";

	
	var theAnchor = /([^#]*)(#?.*)$/; // trennt sprungziel von der url
	theAnchor = theAnchor.exec(theUrl);
	theUrl = theAnchor[1]+delimiter+'rm=print';
	window.open(theUrl);
}







