
Array.prototype.end  = function (){
	return this[this.length -1];	
}


var Class = {
	create: function() {
	return function() {
		this.initialize.apply(this, arguments);
		}
	}
}

var Gmenu = Class.create();

Gmenu.prototype = {

	tab :"mainmenutopbg",
	menus : new Array,
	
	initialize: function (){
						
		a = this._id(this.tab).getElementsByTagName("a");	
		for (var i = 0; i<a.length; i++){
						
			rel = String(a[i].getAttribute("rel"));
			this.menus.push(rel);		
			this.preloadImages(a[i].childNodes[0].src);
			
			if(rel == initialMenu[0] ) {
				this.changeImage(a[i]);							
				this.changeMenu(rel);
			}
			
				a[i].onmouseover = function(){
	
							Gmenu.prototype.changeImage(this);
							Gmenu.prototype.changeMenu(this.rel);
					}
				
				
				//a[i].onclick = function(){return false;}
				a[i].onfocus = function () {this.blur();}
			
		}
		
		
	},
	
	changeImage: function(id){
		
			a = this._id(this.tab).getElementsByTagName("a");	
			for (var i = 0; i<a.length; i++){
				n = a[i].childNodes[0].src.split('.');
				a[i].childNodes[0].src = a[i].childNodes[0].src.replace("1."+n.end(),"2."+n.end());
			}
			n = id.childNodes[0].src.split('.');
			id.childNodes[0].src = id.childNodes[0].src.replace("2."+n.end(),"1."+n.end());
		
	},

	changeMenu: function(rel){
				
		for(var i = 0; i<this.menus.length; i++){
			if(this._id(this.menus[i]))
			this._id(this.menus[i]).style.display = "none";	
		}
		if(this._id(rel))
		this._id(rel).style.display = "block";
		
	},
	
	preloadImages: function (name){
		
		n = name.split(".");
		img = new Image();
		img.src = name.replace("2."+n.end(),"1."+n.end());
			
	},
	_id: function (id){
	
		return document.getElementById(id);
	
	}
	
	
}

function loadMenu() { 
	new Gmenu();
}

if (window.addEventListener){
	window.addEventListener("load", loadMenu, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", loadMenu);
}
else if (document.getElementById){
	window.onload=loadMenu;

}

function top(e){

	var posy = 0;
	if (!e) var e = window.event;
	
	if (e.pageY) 	{
		posy = e.pageY;				
	}
	else if (e.clientY) 	{
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;			
	}

	return przewin(posy);
	
}


function przewin(pos){
		p = pos-(pos*0.1);
		if(p<1 ) return ;
		else {
			window.scroll(0,p);
			setTimeout("przewin('"+p+"')",10);
		}
		
}