var NavItem = new Class({
							   
	initialize:function(e)
	{
		this.e = e;
		
		this.startIndex = 250;
		var coordinates = this.e.getCoordinates();
		this.w = coordinates.width;
		this.h = coordinates.height;
		this.left = coordinates.left;
		this.top = coordinates.top;
		this.right = coordinates.right;
		this.bottom = coordinates.bottom;
		
		if(this.e.hasClass('selected'))
		{
			this.selected = true;
		}else{
			this.selected = false;	
		}
		
		this.wrap();
		//this.setEdges();
		this.setIndicator();
		if(!this.selected)
		{
			this.setEvents();
		}else{
			this.overlay.setStyle('visibility' , 'visible');	
		}
		
	},
	
	
	setEdges:function()
	{
		var positions = Array('TL','TR','BL');
	
		var which = Math.floor(Math.random()*2)+1;
		var i = Math.floor(Math.random()*3);
		
		switch(positions[i])
		{
			case 'TL':
			var bgpos = 'left top';
			break;
			case 'TR':
			var bgpos = 'right top';
			break;
			case 'BR':
			var bgpos = 'right bottom ';
			break;
			case 'BL':
			var bgpos = 'left bottom';
			break;
		}
		
		this.e.setStyles( 
		{
			'background-image' : 'url("/site/img/edge' + positions[i] + which + '.png")',
			'background-position' : bgpos,
			'background-repeat' : 'no-repeat'
		});
		//alert(this.e.getStyle('background'));
	},
	
	wrap: function()
	{
		this.container = new Element('div', 
		{
			'styles': 
			{
				'float':'left',
				'width': this.w + 'px',
				'height': (this.h+5) + 'px',
				'margin-right': '1px'
			}
		}
		);
		this.e.removeClass('navItem');
		this.container.set('class','navItem');
		this.container.wraps(this.e);

	},
	
	setIndicator: function()
	{
		this.overlay = new Element('div', 
		{
			'styles': 
			{
				'background': 'url("/site/img/arrowBlack.png") center top no-repeat',
				'width': this.w + 'px',
				'height': '5px',
				'margin-top': this.h + 'px',
				'visibility': 'hidden'
			}
		}
		);
		
		this.overlay.inject(this.container, 'bottom');
	},
	
	setEvents: function()
	{
		this.e.addEvents
		({
			'mouseover': this.doMouseover.bind(this),
			'mouseout': this.doMouseout.bind(this)
		});
		
		this.e.onmouseover = function()
		{
			return false;
		};
		
		this.e.onmouseout = function()
		{
			return false;
		};
	},
	
	doMouseover: function(ev)
	{
		this.overlay.setStyle('visibility', 'visible');
	},
	
	doMouseout: function(ev)
	{
		this.overlay.setStyle('visibility', 'hidden');
	},
	
	styleToInt: function(e, style)
	{
		var styleAsString = e.getStyle(style);
		var styleAsInt = parseInt(styleAsString.substring(0, (styleAsString.length-2)));
		return styleAsInt;
	}

})

