// JavaScript Document
window.addEvent('domready',ini);
var ie6=false;

var db;
var t;
var scr;
var pg = window.location.pathname.split('/');//.nl
urls.each(function(item, index){
  if(item[0].toLowerCase()==String(pg[0]).toLowerCase()) db=item[1];
});

var _log = function(o) {
  if(console) {
      console.log(o);
  }
}

function ini(){
	var _layer;
  
	if(db=='ag' || db=='news' || db=='info'||(db=='pro' && pg.length>1)){ 
		if(pg[1] && db=="pro")db=pg[1];
		var kol=$('nws_scr');
		if(kol)mkKolScroll(kol,$ES('div','nws_scr').length);		
	}else if(db==null){
		var fls=$ES('.nws_fl',$('.pan_nws'));
		if(fls.length>1){
			setFlits(fls);	
		}
	}
	
	if((_layer = $('layer')) != null && _layer.getSize().size.y>274) {
	    _layer = function(ob) {
		var ms = [ob.getParent().getParent().getNext()];
		ms.push(ms[0].getNext());
		
		ms.each(function(item,index){
			item.act = false;
			item.setStyle('display','block');
			item.top=((index%2)? 0 : 274-ob.getSize().size.y);
			item.i=index;
			item.ob = ob;//$(ob).getElementById(l);
			$(item.ob).setStyle('top','0px');
			item.addEvent('mouseup',function(){
				this.style.background = "url('/BEEM/LIB/GFX/"+((this.i%2)? 'd.gif': 'u.gif')+"')";
				this.act = false;
				$clear(this.loop);
			});
			item.addEvent('mousedown',function(){
				if(this.act === false){
					this.act = true;
					this.loop=((this.i%2)? scrollUp.periodical(40,this): scrollDown.periodical(40,this) );
					this.style.background="url('/BEEM/LIB/GFX/"+((this.i%2)?  'd_o.gif':'u_o.gif')+"')";
				}
			});
		});
	    }(_layer);
	    
	}
	//if(document.getElementById('nws_w_bg') && ie6)fixPNG(document.getElementById('nws_w_bg'));
	/*if($('layer')){
		if($('layer').getSize().size.y>274){
			mkLayerScroll($('layer').getParent().getParent().getParent(),(274-$('layer').getSize().size.y),'layer');
		}
	}
	if($('l_1')){
		if($('l_1').getSize().size.y>408){
			mkLayerScroll($('l_1').getParent().getParent(),(408-$('l_1').getSize().size.y),'l_1');
		}
	}
	if($('l_2')){
		if($('l_2').getSize().size.y>408){
			mkLayerScroll($('l_2').getParent().getParent(),(408-$('l_2').getSize().size.y),'l_2');
		}
	}*/
}

if(db=="pro"){
	window.onload=function(){	
	if(document.getElementById('nws_w_bg') && ie6)fixPNG(document.getElementById('nws_w_bg'));				
		if($('layer')){
			if($('layer').getSize().size.y>274){
				mkLayerScroll($('layer').getParent().getParent().getParent(),(274-$('layer').getSize().size.y),'layer');
			}
		}
		if($('l_1')){
			if($('l_1').getSize().size.y>408){
				mkLayerScroll($('l_1').getParent().getParent(),(408-$('l_1').getSize().size.y),'l_1');
			}
		}
		if($('l_2')){
			if($('l_2').getSize().size.y>408){
				mkLayerScroll($('l_2').getParent().getParent(),(408-$('l_2').getSize().size.y),'l_2');
			}
		}
	}
	
}
function mkKolScroll(kol,n){
	window.addEvent('unload',function (){Cookie.set(db+'Kol',t,{path : '/'});});
	var up= new Image();
	up.src='/BEEM/LIB/GFX/n_u_bg_o.png';
	var down= new Image();
	down.src='/BEEM/LIB/GFX/n_d_bg_o.png';
	t=Cookie.get(db+'Kol');
	if(t!=null){
		$(kol).setStyle('top',t);
		Cookie.remove(db+'Kol');
	}
	for(var i=0; i<2; i++){
		var u=$('nws_kol').getElementById(((i)? 'nws_d':'nws_u'));
		u.top=((i)?  25-((n-6)*50):0);
		u.i=i;
		u.n=kol;
		$(u).addEvent('mouseover',function(){this.style.background="url('/BEEM/LIB/GFX/"+((this.i%2)? 'n_d_bg_o': 'n_u_bg_o')+".png')";});
		$(u).addEvent('mouseout',function(){this.style.background="url('/BEEM/LIB/GFX/"+((this.i%2)? 'n_d_bg':'n_u_bg' )+".png')";});
		$(u).addEvent('mousedown',function(){
			var p=parseInt($(this.n).getStyle('top'));
			if(this.i){
				if(p>this.top){
					$(this.n).setStyle('top',(p-50));
					t=p-50;
				}
			}else{
				if(p<25){
					$(this.n).setStyle('top',(p+50));
					t=p+50;
				}
			}
		});
	}
}

function mkLayerScroll(ob,off,l){
	var ms=$ES('div',ob);
	ms.each(function(item,index){
		//var m=$ES('div',ob);
		//var m=$(ob).getElementById(((i)? 'down' : 'up'));
		item.setStyle('display','block');
		item.top=((index%2)? 0 : off);
		item.i=index;
		item.ob=$(ob).getElementById(l);
		$(item.ob).setStyle('top','0px');
		item.addEvent('mouseup',function(){
			this.style.background="url('/BEEM/LIB/GFX/"+((this.i%2)? 'd.gif': 'u.gif')+"')";
			this.act=false;
			$clear(this.loop);
		});
		item.addEvent('mousedown',function(){
			if(!this.act){	
				this.act=true;
				//scr= setInterval('scrollUp('+this+')',40) : setInterval('scrollDown('+this+')',40));
				this.loop=((this.i%2)? scrollUp.periodical(40,this): scrollDown.periodical(40,this) );//sayHi.periodical(1000,this);
				this.style.background="url('/BEEM/LIB/GFX/"+((this.i%2)?  'd_o.gif':'u_o.gif')+"')";
			}
		});
	});
	
}

function scrollUp(nr){
	if(parseInt($(this.ob).getStyle('top'))){
		$(this.ob).setStyle('top',parseInt($(this.ob).getStyle('top'))+6);
	}else{
		$clear(this.loop);
	}
}

function scrollDown(nr){
	if(parseInt($(this.ob).getStyle('top'))>this.top){
		$(this.ob).setStyle('top',parseInt($(this.ob).getStyle('top'))-6);
	}else{
		$clear(this.loop);
	}
}

function setFlits(fls){
	fls.each(function(item,index){
		var myFx = new Fx.Style(item, 'left',{
			onComplete:function(item){
				if(parseInt(item.getStyle('left'))<0){
					item.setStyle('left',9+((fls.length-1)*261));
				}
			}
		})			  
		item.move=function(){
			//alert(this)
			X=parseInt(this.getStyle('left'));
			myFx.start(X,(X-261));
		}
		item.move.periodical(6000,item);
	});
}

function fixPNG(myImage) {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
}

