﻿var web_txt=new Array();
var Ticker=new Class({
	Implements:[Options],
	options:{
		speed:2,
		pause:1,
		clone:1,
		start:'r'
	},
	initialize:function(element,options){
		this.setOptions(options);
		this.timer=null;
		this.speed=!document.all?Math.max(1,this.options.speed-1):this.options.speed;
		var obj=$(element);
		var cls=obj.getProperty('class')||'ticker';
		var content=obj.innerHTML;
		obj.setStyles({'visibility':'hidden','position':'absolute','white-space':'nowrap'});
		this.content_w=obj.getSize().x;
		this.container=new Element('div',{'class':cls,'styles':{'position':'relative','overflow':'hidden'}}).replaces(obj);
		if(this.options.pause==1)
			this.container.addEvents({'mouseover':this.stop.bind(this),'mouseout':this.start.bind(this)});
		this.container_w=this.container.getSize().x;
		var holder=new Element('div',{'styles':{'position':'absolute','white-space':'nowrap','left':(this.options.start=='r'?this.container_w:0)}}).inject(this.container);
		this.clone_cnt=(this.options.clone==1)?Math.ceil(this.container_w/this.content_w):1;
		for(c=0;c<this.clone_cnt;c++){
			var tmp=new Element('span',{'html':content}).inject(holder);
		}
		this.holder_w=this.clone_cnt*this.content_w;
		if(this.options.clone==1)
			var holder_clone=holder.clone().injectAfter(holder).setStyle('left',this.holder_w+(this.options.start=='r'?this.container_w:0));
		this.start();
	},	
	start:function(){
		if(!this.timer)
			this.timer=this.scroll.periodical(20,this);
	},
	stop:function(){
		this.timer=$clear(this.timer);
	},
	scroll:function(){
		this.container.getChildren('div').each(function(o,i){
			var l=o.getStyle('left').toInt()-this.speed;
			if(l+this.holder_w<0)
				l=(this.options.clone==1)?this.holder_w+(l+this.holder_w):this.container_w;
			o.setStyle('left',l);
		},this);
	}
});
/*  */
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);
		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},'html':content});
		this.showBox=new Fx.Morph(this.box,{duration:500,transition:Fx.Transitions.Quad.easeOut});
		box_cnt++;
		this.cnt=box_cnt;
		boxes[box_cnt]=this;
		if(this.box.getElement('a.message_box_close'))
			this.box.getElement('a.message_box_close').addEvent('click',function(){
				Cookie.write('hideMessageBox',1,{path:'/'});
				this.hide();
				return false;
			}.bind(this));
	},	
	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;
		this.box.getElement('a.message_box_close').addEvent('click',function(){
			Cookie.write('hideBox',1,{path:'/'});
			this.hide();
			return false;
		}.bind(this));
	}
});

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));
		}
	}
});

window.addEvent('domready',function(){
	//var ticker=new Ticker('ticker',{speed:2});
	
	/*var boxx=new MessageBox('tesst');
	var boxx2=new MessageBox('tesst2');
	var boxx3=new MessageBox('tesst3');
	
	$('content').addEvent('dblclick',function(){boxx.setcontent('lobogo');boxx.show()});	
	$('header').addEvent('dblclick',function(){boxx3.show()});
	$('leftbox').addEvent('dblclick',function(){boxx2.show()});  */
	
	//alert('xxx');
	
	
	//var sbox=new ShaddowBox('shaddowbox_content');
	
	
	/* $('test1').addEvent('click',function(){
		sbox.show();
		return false;
	});
	$('test2').addEvent('click',function(){
		sbox.hide();
		return false;
	}); */
	
	

									
	menu_onload();
	$$('a[rel=_blank]').setProperty('target','_blank');
	
	if($('set_sorting')){
		var form=$('set_sorting')
		var els=form.getElements('input[name=page]');
		var l=new URI(location.href);
		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){
					l.setData({page:(this.value-1),per_page:''},true);
					var q=l.get('query').cleanQueryString();
					l.set('query',q);
					l.go();
				}
			},
			'blur':function(){
				if(this.value==''||this.value==0)
					this.value=$('page_nr').value;
				l.setData({page:(this.value-1),per_page:''},true);
				var q=l.get('query').cleanQueryString();
				l.set('query',q);
				l.go();
			}
		});
		if($('per_page')){
			$('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(this.value.toInt()>max_val.toInt())
						this.value=max_val;
					if(this.value.toInt()==0)
						this.value=1;
					if(event.code==13){
						l.setData({per_page:this.value,page:''},true);
						var q=l.get('query').cleanQueryString();
						l.set('query',q);
						l.go();
					}
				},
				'blur':function(){
					if(this.value==''||this.value==0)
						this.value=10;
					max_val=$('record_cnt').value;
					if(this.value.toInt()>max_val.toInt())
						this.value=max_val;
					l.setData({per_page:this.value,page:''},true);
					var q=l.get('query').cleanQueryString();
					l.set('query',q);
					l.go();
				}
			});
		}
	}
});