﻿var box_cnt=0,boxes=new Array(),shown_cnt=0;
var MessageBox=new Class({
	initialize:function(content){
		this.box=new Element('div',{'class':'message_box'}).inject(document.body);
		this.box.set('html',content);
		var s=this.box.getSize();
		this.shown=0;
		this.h=s.y;
		this.w=s.x;
		this.box.set('styles',{'right':0,'bottom':-this.h});
		this.showBox=new Fx.Morph(this.box,{duration:700,transition:Fx.Transitions.Quad.easeOut});
		box_cnt++;
		this.cnt=box_cnt;
		boxes[box_cnt]=this;
		links=this.box.getElements('a');
		links[0].addEvent('click',function(){
			Cookie.write('hideBox',1,{path:'/'});
			this.hide();
			return false;
		}.bind(this));
		links[1].addEvent('click',function(){
			Cookie.write('hideBox',1,{path:'/'});
			location.href='/downloadFile.php';
			return false;
		});
	},	
	show:function(){
		if(this.shown==0){
			this.box.setStyle('right',(shown_cnt*this.w));
			this.showBox.start({'bottom':0});
			this.shown=1;
			shown_cnt++;
		}
	},
	hide:function(){
		this.showBox.start({'bottom':-this.h});
		this.shown=0;
		this.cnt=0;
		shown_cnt--;		
		var s_c=0;		
		for(c=1;c<=box_cnt;c++){
			if(boxes[c].shown==1){
				boxes[c].showBox.start({'right':(s_c*this.w)});
				s_c++;
			}					
		}
	},
	setcontent:function(content){
		this.box.innerHTML=content;	
	}
});

var ShaddowBox=new Class({
	initialize:function(content){
		this.shown=0;
		this.alpha=new Element('div',{'id':'alpha'}).inject(document.body);
		this.box_holder=new Element('div',{'id':'shaddowbox_holder'}).inject(document.body);
		this.box=new Element('div',{'id':'shaddowbox'}).inject(this.box_holder);
		var b_r=new Element('div',{'class':'shaddowbox_r'});
		this.box_body=new Element('div',{'class':'shaddowbox_body'}).inject(b_r);
		this.box_content=$(content);
		this.box_content.setStyles({
   			opacity:0,
    		display:'block'
		});
		this.box_body.grab(this.box_content);
		this.box.adopt([new Element('div',{'class':'shaddowbox_t'}),new Element('div',{'class':'shaddowbox_tr'}),b_r,new Element('div',{'class':'shaddowbox_bl'}),new Element('div',{'class':'shaddowbox_b'}),new Element('div',{'class':'shaddowbox_br'})]);
		this.showBox=new Fx.Tween(this.box_holder,{duration:700,transition:Fx.Transitions.Quad.easeIn});
		this.showBox.onComplete=function(){
			if(this.shown==0){
				this.box_content.set('opacity',0);
				this.alpha.setStyle('display','none');
				$$('html').setStyle('overflow','auto');
				
			}
			else{
				this.box_content.tween('opacity',1);	
			}
		}.bind(this);
	},
	show:function(){
		if(this.shown==0){
			$$('html').setStyle('overflow','hidden');
			this.alpha.setStyles({
				display:'block',
				height:window.getScrollSize().y,
				opacity:.5
			});
			this.shown=1;
			s=this.box.getCoordinates();
			s_h=this.box_holder.getCoordinates();
			if(s.height>s_h.height)
				shift_y=10;
			else if((s_h.height-s.height)<50)
				shift_y=(s_h.height-s.height)/2;
			else
				shift_y=50;			
			this.showBox.start('top',window.getScroll().y+shift_y);
		}
	},
	hide:function(){
		if(this.shown==1){
			this.shown=0;
			s=this.box.getCoordinates();
			this.showBox.start('top',-(s.height+s.top));
		}
	}
});

var HintBox=new Class({
	initialize:function(content){
		this.shown=0;
		this.box=new Element('div',{'class':'hintbox','html':$(content)}).inject(document.body);
		this.box_body=new Element('div',{'class':'hintbox_body'}).inject(this.box);
		this.box_footer=new Element('div',{'class':'hintbox_footer'}).inject(this.box);
		this.box.setStyle('opacity',0);
		this.showBox=new Fx.Tween(this.box);
	},
	show:function(obj){
		this.shown=1;
		this.box.setStyle('opacity',0);		
		this.showBox.start('opacity',1);
		if(obj.type=='radio')
			d=obj.getNext().getCoordinates();
		else
			d=obj.getCoordinates();
		this.box.setStyles({
			display:'block',
			left:(d.left+d.width+4),
			top:(d.top-2)
		});	
	},
	hide:function(){
		if(this.shown==1){
			this.shown=0;
			this.showBox.start('opacity',0);
		}
	},
	setcontent:function(content){
		this.box_body.set('text',content);	
	}
});

function livehelp(){
	window.open('https://server.iad.liveperson.net/hc/71175134/?cmd=file&amp;file=visitorWantsToChat&amp;site=71175134&amp;referrer=http%3A%2F%2Fwww.anopoker.com','live','menubar=0,toolbar=no,width=400,height=400');
}

window.addEvents({
	'domready':function(){
		menu_onload();
		$$('a[rel=_blank]').setProperty('target','_blank');
		
		if($('set_sorting')){
			var form=$('set_sorting')
			var els=form.getElements('input[name=page]');
			els.addEvents({
				'keydown':function(event){
					eCode=event.code;
					return ((eCode>=48&&eCode<=57)||eCode==37||eCode==39||eCode==8||eCode==46);
				},
				'keyup':function(event){
					max_val=$('page_cnt').value;
					if(this.value.toInt()>max_val.toInt())
						this.value=max_val;
					if(this.value.toInt()==0)
						this.value=1;
					if(event.code==13)
						location.href='?'+$('paging_svn').value+'page='+(this.value-1);
				},
				'blur':function(){
					if(this.value==''||this.value==0)
						this.value=$('page_nr').value;
					location.href='?'+$('paging_svn').value+'page='+(this.value-1);
				}
			});
			if($('record_cnt').value<$('per_page').value)
				$('per_page').value=$('record_cnt').value;
			$('per_page').addEvents({
				'keydown':function(event){
					eCode=event.code;
					return ((eCode>=48&&eCode<=57)||eCode==37||eCode==39||eCode==8||eCode==46);
				},
				'keyup':function(event){
					max_val=$('record_cnt').value;
					if(isNaN(this.value)||this.value.toInt()>max_val.toInt())
						this.value=max_val;	
					if(this.value.toInt()==0)
						this.value=1;
					if(event.code==13)				
						location.href='?'+$('paging_svn').value+'per_page='+(this.value);
				},
				'blur':function(){
					max_val=$('record_cnt').value;
					if(this.value==''||this.value==0)
						this.value=max_val;				
					if(isNaN(this.value)||this.value.toInt()>max_val.toInt())
						this.value=max_val;
					location.href='?'+$('paging_svn').value+'per_page='+(this.value);
				}
			});
		}
		
		var flash_link=function(){location.href=absPath+webLang+'/how-to-deposit-cash-out/';};
				
		$$('a.play_poker').addEvent('mouseover',function(){
			this.tween('color','#fdfe53','#c7110c');	
		});
		if($('registration_ok'))
			location.href='http://www.anopoker.com/downloadFile.php';
	},
	'load':function(){
		if((!Browser.Engine.trident||Browser.Engine.version>4)&&$('play_now_box')&&Cookie.read('hideBox')!=1){
			var boxCnt=Cookie.read('boxCnt');
			if(boxCnt==''||boxCnt<3){
				box_content=$('play_now_box').get('html');
				var poker_box=new MessageBox(box_content);	
				(function(){poker_box.show();}).delay(30);
			}
			if(boxCnt>10)
				Cookie.write('boxCnt',0,{path:'/'});
			else{
				if(!boxCnt)
					cnt=1;
				else
					cnt=(boxCnt.toInt())+1
				Cookie.write('boxCnt',cnt,{path:'/'});
			}
		}
	}
});
