﻿var web_txt=new Array();
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 wm_load_swf=function(){
	$$('div.wm_flash').each(function(o,i){
		var n=o.get('id');
		var cls=o.get('class');
		var wr=/width:[0-9]+/;
		var hr=/height:[0-9]+/;
		var w=(cls.match(wr))?cls.match(wr)[0].split(':')[1]:'100%';
		var h=(cls.match(hr))?cls.match(hr)[0].split(':')[1]:'100%';
		var vr=/vars:[^ ]+/;
		var v=(cls.match(vr))?cls.match(vr)[0].split(':')[1]:'';
		if(v!=''){
			v=v.split(',');
			var vv='';
			for(c=0;c<v.length;c++){
				s=v[c].split('=');
				vv+=s[0]+':"'+s[1]+'"'+(c<(v.length-1)?',':'');				
			}
			wm_vars=eval('new Object({'+vv+'})');
		}
		else
			var wm_vars=new Object();
		var pr=/params:[^ ]+/;
		var p=(cls.match(pr))?cls.match(pr)[0].split(':')[1]:'';
		if(p!=''){
			p=p.split(',');
			var vv='';
			for(c=0;c<p.length;c++){
				s=p[c].split('=');
				vv+=s[0]+':"'+s[1]+'"'+(c<(p.length-1)?',':'');				
			}
			wm_params=eval('new Object({'+vv+'})');
		}
		else
			var wm_params=new Object();		
		new Swiff(absPath+'templates/gfx/swf/'+n+'.swf',{id:n+"_swf",width:w,height:h,params:wm_params,vars:wm_vars}).inject(o);		
	});
}
window.addEvents({'domready':function(){
	menu_onload();
	$$('a[rel=_blank]').setProperty('target','_blank');
	$$('a.button_back').addEvent('click',function(){
		history.go(-1);
		return false;
	});
	var rcnt=0;
	$$('table.odd_even tr').each(function(el){
		el.addClass(rcnt++%2==0?'odd_row':'even_row');
	});
	wm_load_swf();
	if($('nl_subscribe')){
		$('newsletter').addEvents({
			'focus':function(){
				if(this.value==this.title)
					this.value='';
			},
			'blur':function(){
				if(this.value=='')
				this.value=this.title;
			}
		});	
		$('nl_form').addEvent('submit',function(){
			val=$('newsletter').get('value');
			if(val=='')
				return false;
			new Request.HTML({url:absPath+'index.php',method:'get',onSuccess:function(tree,elements,html,js){
				$('nl_box').set('html',html);
			}}).send('webmin_ajax=1&action_type=nl_subscribe&nl_email='+encodeURI(val));
			return false;
		});
	}
	
	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();
				}
			});
		}
	}
	
	if($('counter')){
	
		new MooCountdown.Date($('counter'),{
            date: '03/06/2012 11:59am',
            text:[' rokov ','&nbsp;dní&nbsp;','&nbsp;hod.&nbsp;','&nbsp;min.&nbsp;',' sek. ']
        });
	}

},
	'load':function(){
		if($('pf')){
			var pfoff=function(){$('pf').tween('opacity',0);}
			$('pf').addEvent('click',function(){pfoff();});
			pfoff.delay(10000);
		}
	}

});
