var CONFIG =
{
	BASE_URL: '',
	<!--IBASE_URL: 'http://localhost/saharaNext-28-09-2008/www4/',-->
	<!--MAGE_DIR: 'data/navigation/',-->
	IMAGE_DIR: 'images/',
	NAVIGATION: {
		BG_IMG: 'bg-navigation-main-item.png',
		BG_IMG_HOVER: 'bg-navigation-main-item-hover.png'
	}
}

window.addEvent('domready', function()
{
	var objNavTop = new NavTop();
});

var NavTop = new Class(
{	
	startY				: 0,
	incrementY			: 35,
	
	initialize: function()
	{		
		var i = 0;
		$$('ul.level0 li a').each(function(node)
		{
			node.nodeParent = node.getParent();
			level = node.nodeParent.getParent().className;
						
			switch(level)
			{
				case 'level0' :
				
					this.setupItem0(node, this, i);
					
					node.nodeParent.addEvents(
					{
						'mouseenter': this.mouseOver0,
						'mouseleave': this.mouseOut0
					});
					
					i++;
					
					break;
					
				case 'level1' :
				
					this.setupItem1(node, this);
					
					node.nodeParent.addEvents(
					{
						'mouseenter': this.mouseOver1,
						'mouseleave': this.mouseOut1
					});	
					
					node.addEvents(
					{
						'click': this.mouseClick1
					});	
					
					break;
			}
			
		}.bind(this));
		
		$('header').getElement('div.navigation-main ul').setStyle('visibility', 'visible');
	},
	
	setupItem0: function(node, classRef, i)
	{			
		node.setStyles(
		{
			'background-image'			: 'url('+CONFIG.IMAGE_DIR+CONFIG.NAVIGATION.BG_IMG+')',
			'background-position'		: 'left '+( classRef.startY - 8 )+'px'
		});
		
		node.getElement('span').dispose();
						
		if(node.getParent().getElement('ul'))
		{
			node.addClass('has-submenu');
			
			submenu = node.getParent().getElement('ul');
									
			if(Browser.Engine.trident)
			{
				submenuWidth = submenu.getParent().getSize().x + 100;
				
				submenu.getElements('li a').each(function(subitem)
				{
					subitem.setStyle('width', submenuWidth);
				});
				
				submenu.setStyle('margin-left', -node.getParent().getSize().x);
			}
			
			submenu.setStyle('display', 'none');
				
			new Element('li').addClass('last-border').injectInside(node.getParent().getElement('ul'));
		}
		
		node.hasSubmenu = $chk( node.getParent().getElement('ul') );
		
		node.backgroundYPos = classRef.startY;
		node.activeItem = false;
			
		classRef.startY -= classRef.incrementY;
	},
	
	mouseOver0: function()
	{	
		if(this.activeItem) { return; }
		this.activeItem = true;
		
		if(!this._href)
		{
			this._href = this.getElement('a');
		}
		
		this.toggleClass('hover');
		
		this._href.setStyles(
		{
			'background-image'			: 'url('+CONFIG.IMAGE_DIR+CONFIG.NAVIGATION.BG_IMG_HOVER+')',
			'background-position'		: 'left '+( this._href.backgroundYPos + 1 )+'px'
		});
		
		if(this._href.hasSubmenu)
		{
			if(!this.submenu)
			{
				this.submenu = this.getElement('ul');
			}
			
			this.submenu.setStyle('display', 'block');
		}
	},
	
	mouseOut0: function()
	{
		if( !this.activeItem) { return; }
		this.activeItem = false;
		
		if(!this._href)
		{
			this._href = this.getElement('a');
		}
		
		this.toggleClass('hover');
		
		this._href.setStyles(
		{
			'background-image'			: 'url('+CONFIG.IMAGE_DIR+CONFIG.NAVIGATION.BG_IMG+')',
			'background-position'		: 'left '+( this._href.backgroundYPos - 8 )+'px'
		});
		
		if(this._href.hasSubmenu)
		{
			if(!this.submenu)
			{
				this.submenu = this.getElement('ul');
			}
			
			this.submenu.setStyle('display', 'none');
		}
	},
	
	setupItem1: function(node, classRef)
	{
		if(node.getParent().getElement('ul'))
		{
			submenu = node.getParent().getElement('ul');
		}
		node.hasSubmenu = $chk( node.getParent().getElement('ul') );
	},
	
	mouseOver1: function()
	{
		if(this == this.getParent().getLast().getPrevious())
		{
			this.getParent().getElement('li.last-border').setStyle('background-color', '#ef4a26');
		}	
	},
	
	mouseOut1: function()
	{
		this.getParent().getElement('li.last-border').setStyle('background-color', '#262626');
	},
	
	mouseClick1: function()
	{		
		if(this.hasSubmenu)
		{
			if(!this.nodeParent.submenu)
			{
				this.nodeParent.submenu = this.nodeParent.getElement('ul');
			}
			
			if(!this.nodeParent.submenuHeight)
			{
				this.nodeParent.submenuHeight = this.nodeParent.submenu.getSize().y;
			}
			
			if(!this.nodeParent.animSub)
			{
				this.nodeParent.animSub = new Fx.Tween(this.nodeParent,{duration:300});
			}
			
			if(this.nodeParent.submenuHeight == this.nodeParent.getStyle('padding-bottom').toInt())
			{
				this.toggleClass('active');
				this.nodeParent.animSub.start('padding-bottom', 0);			
			}
			else
			{
				this.toggleClass('active');
				this.nodeParent.animSub.start('padding-bottom', this.nodeParent.submenuHeight);							
			}
			
			return false;
		}
	}
});

var FlashFile = new Class(
{
	initialize: function(page_id)
	{
		var flashElm = $('content').getElement('div.pushbox');
		
		if(!flashElm) { return; }
		
		var objSwf = new Swiff('swf/homePage.swf', 
		{
   			id			: 'pushboxSwf',
			container	: flashElm,
			width		: 779,
			height		: 305,
			params		:
			{
				wMode	: null,
				wmode	: 'opaque',
				allowScriptAccess : 'always',
				bgcolor	: '#262626'
			},
			vars		: 
			{
				baseurl		: CONFIG.BASE_URL,
				page_id		: page_id
			}
		});
		
	}
});

