var BM2_almenuk=[];

var BM2={
//////////////////////////////////////
// kell hozzá: BM2_almenuk[] tömb!!!
//////////////////////////////////////
menuDelay: 500, //elrejtés késleltetése
ani_speed: 4, //(pixel: nagyobb szám=gyorsabb)
ani_speedIE: 10, //(pixel: nagyobb szám=gyorsabb)
ani_time: 20, //(itervall time: kisebb szám=gyorsabb)
//////////////////////////////////////
rejtID: null,
timerOn : false,
next:"",
activ_menuItem:"",
offsw: 0,
offsh: 0,
temp_hided_selbox:[],

aniTimerID:0,
aniRateW:"",
aniRateH:"",

isIE:false,
ieVers: -1,

//////////////////////////////////////

init: function(){
	var is_ie, rv;
 
	is_ie=((navigator.userAgent.toLowerCase().indexOf("msie") != -1) &&  (navigator.userAgent.toLowerCase().indexOf("opera") == -1));
	this.isIE=is_ie;
	
	rv = -1;	
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		var ua = navigator.userAgent;
		var re  = new RegExp(/MSIE ([0-9]{1,}[\.0-9]{0,})/);
		if (re.exec(ua) !== null)
		{
			//rv = parseFloat( RegExp.$1 );
			rv = parseInt( RegExp.$1,10 );
		}
	}
	this.ieVers=rv;
},

mutat: function(id){

	if(this.timerOn===true)
	{
		this.next=id;
	}
	else
	{
		this.next="";
		this.hideAll();
		this.showDiv(id);
		this.activ_menuItem=id;
	}		
},

rejt_delayed: function(){
	this.hideAll();
	this.next_mutat();
	this.timerOn = false;
	this.rejtID=null;
},

rejt: function(){
	if (this.timerOn === false)
	{
		this.timerOn = true;
		this.rejtID=setTimeout(function(){
		BM2.rejt_delayed();
		}, this.menuDelay);
	}
},

next_mutat: function(){
	this.hideAll();
	if(this.next!="")
	{
		this.showDiv(this.next);
		this.activ_menuItem=this.next;
	}
},

showDiv: function(id){
	var obj;
	if(document.getElementById)
	{
		obj=document.getElementById(id);
	}	
	else if(!document.getElementById && document.all)
	{
		obj=document.all[id];
	}
	
	if(this.activ_menuItem!==id || this.next==="")
	{
		obj.style.display='block';
		this.get_offsSize(id);
		
		var r=this.offsw/this.offsh;
		
		if(this.isIE && this.ieVers==8)
		{
			this.aniRateH=this.ani_speedIE;
			this.aniRateW=r*this.ani_speedIE;
		}
		else
		{
			this.aniRateH=this.ani_speed;
			this.aniRateW=r*this.ani_speed;
		}

		obj.style.width="0";
		obj.style.height="0";

		BM2.aniTimerID=window.setInterval(function(){
		BM2.mutat_ani(id);
		},this.ani_time);
	}
	else
	{
		obj.style.display='block';
	}

	//hide and save selectboxes in IE4-6:
	if(this.isIE && this.ieVers<7)
	{
		var selects = document.all.tags('select');
		var i;
		var sl=selects.length;
		for(i=0;i<sl;i++)
		{
			if(selects[i].style.visibility!="hidden" && selects[i].style.display!="none")
			{
				selects[i].style.visibility="hidden";
				this.temp_hided_selbox.push(selects[i]);
			}
		}//end for		
	}
},

get_offsSize: function(id){
	if(document.getElementById)
	{
		if(document.getElementById(id).offsetHeight)
		{
			this.offsw=document.getElementById(id).offsetWidth;
			this.offsh=document.getElementById(id).offsetHeight;
		}
	}
	else if(!document.getElementById && document.all)
	{
			if(document.all(id).offsetHeight)
			{
				this.offsw=document.all(id).offsetWidth;
				this.offsh=document.all(id).offsetHeight;
			}
	}
},


mutat_ani: function(id){
	var elm;
	if(document.getElementById)
	{
		elm=document.getElementById(id);
	}
	else if(!document.getElementById && document.all)
	{
		elm=document.all[id];
	}

	var esw=parseInt(elm.style.width,10);
	var esh=parseInt(elm.style.height,10);

	if (esw < BM2.offsw || esh < BM2.offsh)
	{
		if (esw < BM2.offsw )
		{
			elm.style.width = ((esw+BM2.aniRateW)<BM2.offsw) ? (esw+BM2.aniRateW)+"px" : BM2.offsw+"px";
		}
		if (esh < BM2.offsh)
		{
			elm.style.height = (esh+BM2.aniRateH)<BM2.offsh ? (esh+BM2.aniRateH)+"px" : BM2.offsh+"px";
		}
	}	
	else
	{
		window.clearInterval(BM2.aniTimerID);
		BM2.aniTimerID=0;
	}
},

hideAll: function(){
	if(BM2_almenuk.length>0)
	{
		var i;
		var il=BM2_almenuk.length;
		for (i=0;i<il;i++)
		{
			if(document.getElementById)
			{
				document.getElementById(BM2_almenuk[i]).style.display='none';
			}
			else if(!document.getElementById && document.all)
			{
				document.all[BM2_almenuk[i]].style.display='none';
			}
		}
	}

	//Show hided selectboxes in IE4-6:	
	if(this.isIE && this.ieVers <7)
	{
		var sl=this.temp_hided_selbox.length;
		var j;
		for(j=0;j<sl;j++)
		{
			this.temp_hided_selbox[j].style.visibility="visible";
		}		
	}
	
	//empty array
	this.temp_hided_selbox.splice(0,this.temp_hided_selbox.length);	
},

hideAllDiv:function ()
{
	this.next="";
}

};//end class



//***** FLOATINGDIV *********

var FLOATINGDIV={
/////////////////////
fm_id : 'floatdiv',	//Az úszó div id-je
fromTop: 110,		//távolság (és indítás) az ablak felső részétől)
fromLeft: 0,		//távolság (és indítás) az ablak (menü div) bal szélétől)
////////////////////
target_x : 0,
target_y : 0,
fm_shift_x : "",
fm_shift_y : "",
fm_next_x : "",
fm_next_y : "",
has_inner : typeof(window.innerWidth) == 'number',
has_element : document.documentElement && document.documentElement.clientWidth,
floating_menu : "",
move: false,

move_menu: function(){

	if(this.move===true)
	{
		var scroll_y = this.has_inner ? pageYOffset : this.has_element ? document.documentElement.scrollTop : document.body.scrollTop;

		var scroll_x = this.has_inner ? pageXOffset : this.has_element ? document.documentElement.scrollLeft : document.body.scrollLeft;
	
		if(scroll_y>this.fromTop)
		{
			this.floating_menu.style.left=(this.fm_next_x) + 'px';
			this.floating_menu.style.top=(this.fm_next_y - this.fromTop)+'px';

		}
	
		else if(scroll_x>this.fromLeft)
		{
			this.floating_menu.style.left=(this.fm_next_x - this.fromLeft) +'px';

			if((scroll_y - this.fm_next_y)>this.fromTop)
			{
				this.floating_menu.style.top = this.fm_next_y  + 'px';
			}
			else
			{
				this.floating_menu.style.top = 0;
			}
		}

		else
		{
			this.floating_menu.style.top = 0;
			this.floating_menu.style.left = 0;
		}
	}	
	else
	{
		return;
	}
},

compute_shifts: function(){

	if(this.move===true)
	{
		this.fm_shift_x = this.has_inner ? pageXOffset : this.has_element ? document.documentElement.scrollLeft : document.body.scrollLeft;
		if (this.target_x < 0)
		{
			this.fm_shift_x += this.has_inner ? window.innerWidth : this.has_element ? document.documentElement.clientWidth : document.body.clientWidth;
		}
		this.fm_shift_y = this.has_inner ? pageYOffset : this.has_element ? document.documentElement.scrollTop : document.body.scrollTop;
		if (this.target_y < 0)
		{
			this.fm_shift_y += this.has_inner ? window.innerHeight : this.has_element ? document.documentElement.clientHeight : document.body.clientHeight;
		}
	}
	else
	{
		return;
	}
},

float_menu: function(){
	if(this.move===true)
	{
		var step_x, step_y;
		this.compute_shifts();
		step_x = (this.fm_shift_x + this.target_x - this.fm_next_x) * 0.07;
		if (Math.abs(step_x) < 0.5)
		{
			step_x = this.fm_shift_x + this.target_x - this.fm_next_x;
		}
		step_y = (this.fm_shift_y + this.target_y - this.fm_next_y) * 0.07;
		if (Math.abs(step_y) < 0.5)
		{
			step_y = this.fm_shift_y + this.target_y - this.fm_next_y;
		}
		if (Math.abs(step_x) > 0 || Math.abs(step_y) > 0)
		{
			this.fm_next_x += step_x;
			this.fm_next_y += step_y;
			this.move_menu();
		}
		var timerID=setTimeout(function(){
		FLOATINGDIV.float_menu();
		}, 20);
	}
	else
	{
		return;
	}  
},


windowSize: function()
{
	var myWidth=0, myHeight=0;
	if( typeof( window.innerWidth ) === 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return {w:myWidth, h:myHeight};
},

getScrollerWidth: function ()
{
	var scr = null;
	var inn = null;
	var wNoScroll = 0;
	var wScroll = 0;
	scr = document.createElement('div');
	scr.style.position = 'absolute';
	scr.style.top = '-1000px';
	scr.style.left = '-1000px';
	scr.style.width = '100px';
	scr.style.height = '50px';
	scr.style.overflow = 'hidden';
	inn = document.createElement('div');
	inn.style.width = '100%';
	inn.style.height = '200px';
	scr.appendChild(inn);
	document.body.appendChild(scr);
	wNoScroll = inn.offsetWidth;
	scr.style.overflow = 'auto';
	wScroll = inn.offsetWidth;
	document.body.removeChild(document.body.lastChild);
	return (wNoScroll - wScroll);
},


start: function(fm_id,fromTop,fromLeft){

	this.fm_id = fm_id ;
	this.fromTop =fromTop;
	this.fromLeft =fromLeft;

	if(document.getElementById)
	{
		this.floating_menu=document.getElementById(this.fm_id);
	}
	else if(!document.getElementById && document.all)
	{
		this.floating_menu=document.all[this.fm_id];
	}
	else
	{
		return;
	}
	
	//Csak akkor induljon, ha az ablak magassága nagyobb, mint a menü magassága
	if( this.floating_menu.offsetHeight < (this.windowSize().h - this.getScrollerWidth()) )
	{
		this.move=true;
		this.compute_shifts();
		this.fm_next_x = this.fm_shift_x + this.target_x;
		this.fm_next_y = this.fm_shift_y + this.target_y;
		this.move_menu();
		this.float_menu();
	}
	else
	{
		this.target_x = 0;
		this.target_y = 0;
		this.fm_shift_x = "";
		this.fm_shift_y = "";
		this.fm_next_x = "";
		this.fm_next_y = "";
		this.floating_menu.style.top = 0;
		this.floating_menu.style.left = 0;
		this.fm_shift_x=0;
		this.fm_shift_y=0;
		this.fm_next_x =0;
		this.fm_next_y =0;

		this.move=false;
	}

}

};//end class

//////////////////////////////
