Element.implement({
	round_it:function()
	{
		var size = this.getProperty('vnround');
		new roundedCorners(this, size)
		var top = new Element('div');
		var bottom = new Element('bottom');		
	},
	fitToWindow:function()
	{		
		this.setStyle('height', 'auto');
						
		var elHeight 		= this.getSize().y;
		var windowHeight 	= window.getScrollSize().y;
		var viewHeight		= window.getSize().y;
		//if (this.resize != null && viewHeight < windowHeight) viewHeight = windowHeight;
		var diff = windowHeight - elHeight;
		//var top = this.getCoordinates().top;
		if (this.top == null)		this.top = this.getCoordinates().top;
		if (this.bottom == null)	this.bottom = diff - this.top;
		
		var diff2 = this.top + this.bottom;
		var newHeight = viewHeight - diff2;
		
		/*
		if (this.counter == null  || this.counter ==5)
		{
			if (this.counter == null) 	this.counter = 1;
			else						this.counter++;
			this.counter = 1;
			var insert = $('avartar').getElement('div.message');			
			insert.empty();
			insert.adopt(new Element('p').set('text', 'step 1 '+windowHeight+' - '+elHeight+'= '+diff));
			insert.adopt(new Element('p').set('text', 'step 2 '+viewHeight+' - '+diff2+'= '+(viewHeight - diff)));
			insert.adopt(new Element('p').set('text', 'top bottom '+this.top+' + '+this.bottom));			
		}
		*/
		
		//this.setStyle('overflow', 'auto');
		if (newHeight <=  330)  newHeight = 331;
		this.setStyle('height', newHeight+'px');
		this.resize = true;
	}
	
}
);

var roundedCorners = new Class({
	initialize: function(el, size)
	{
		this.el = el;
		this.size = 20;
		this.image = 'img/round.gif';
		this.init();			
	},
	init: function()
	{
		if (Browser.Engine.name == 'trident')
		{		
			this.initIE();
		}
		else if (Browser.Engine.name == 'gecko')
		{
			this.initFF();
		}
		else if (Browser.Engine.name == 'presto')
		{
			//this.initOpera();
			this.initOther();
		}
		else
		{
			this.initOther();
			alert (Browser.Engine.name);
		} 
			
			
		
	},
	initIE:function()
	{
		var wrapper = new Element('div');
		var opac = this.el.getProperty('vnopacity');
		if (opac != null)	wrapper.setProperty('vnopacity', opac);
			wrapper	.setStyle('height', this.size+'px')
				.setStyle('width', this.el.getSize().x)
				.setStyle('padding-top', 0)
				.setStyle('margin-right', 	this.el.getStyle('margin-right'))
				.setStyle('margin-left', 	this.el.getStyle('margin-left'))
				.setStyle('overflow', 'hidden')
			;
			
		var inner = new Element('div');
			inner.setStyle('background-color',this.el.getStyle('background-color'))
				.setStyle('float', 'left')
				.setStyle('height', this.size+'px')
				.setStyle('width', (this.el.getSize().x  - (2*this.size))+'px');
				
		var cornerbox = new Element('div');
			cornerbox.setStyle('height', this.size+'px')
					.setStyle('width', this.size+'px')
					.setStyle('background-color', 'transparent')
					.setStyle('background-repeat', 'no-repeat')
					.setStyle('background-image', 'url('+this.image+')');
		
		var topWrap 	= wrapper;
		var bottomWrap 	= wrapper.clone();
		
		inner.inject(topWrap);
		inner.clone().inject(bottomWrap);
		
		var cornersLeftTop 		= cornerbox.clone()
			cornersLeftTop.setStyle('background-position', 'top left').setStyle('float', 'left');
			cornersLeftTop.inject(topWrap, 'top');
		var cornersRightTop 	= cornerbox.clone();
			cornersRightTop.setStyle('background-position', 'top right').setStyle('float', 'right');
			cornersRightTop.inject(topWrap);
		var cornersLeftBottom	= cornerbox.clone();
			cornersLeftBottom.setStyle('background-position', 'bottom left').setStyle('float', 'left');
			cornersLeftBottom.inject(bottomWrap, 'top');
		var cornersRightBottom	= cornerbox.clone();
			cornersRightBottom.setStyle('background-position', 'bottom right').setStyle('float', 'right');
			cornersRightBottom.inject(bottomWrap);
		
		
		topWrap.inject(this.el, 'before');
		bottomWrap.setStyle('margin-bottom', this.el.getStyle('margin-bottom'));
		this.el.setStyle('margin-bottom', '0');
		this.el.setStyle('padding-top', '0');
		this.el.setStyle('padding-bottom', '0');
		bottomWrap.inject(this.el, 'after');
		

	},
	initIE2:function()
	{
		var border = 2;
		var opac = this.el.getProperty('vnopacity');
		var top = new Element('div');
			if (opac != null)	top.setProperty('vnopacity', opac);
			top	.setStyle('height', this.size+'px')
				.setStyle('width', this.el.getSize().x)
				.setStyle('padding-top', 0)
				.setStyle('margin-right', this.el.getStyle('margin-right'))
				.setStyle('margin-left', this.el.getStyle('margin-left'))
				.setStyle('overflow', 'hidden')
				;
		var image = new Element('img');
			image.setProperty('src', 'img/round.gif')
					.setStyle('padding', '0')
					.setStyle('margin', '0')
					.setStyle('width', (this.size*2)+'px')
					.setStyle('height', (this.size*2)+'px');
		var	imageWrapper = new Element('div');
			imageWrapper.setStyle('width', (this.size)+'px')
					.setProperty('vnopacity', opac)
					.setStyle('height', (this.size)+'px')
					.setStyle('overflow', 'hidden')
			imageWrapper.adopt(image);
			
			var inner = new Element('div');
			inner.setStyle('background','#ffffff')
				.setStyle('float', 'left')
				.setStyle('height', this.size+'px')
				.setStyle('width', (this.el.getSize().x  - (2*this.size))+'px')
			
		var left = new Element('div');
			left.setStyle('height', this.size+'px')
				.setStyle('width', this.size+'px')
				.setStyle('overflow', 'hidden')
				.adopt(imageWrapper);
				//.setStyle('background-image', 'url(img/round.png)')
				//.setStyle('background-repeat', 'no-repeat');
			
			left.setStyle('background-position', 'top left');
		var right = left.clone();			
			right.setStyle('background-position', 'top right')
				 .setStyle('float', 'right');			
			right.addClass('right');
			
			right.getElement('img').setStyle('margin-left', '-20px');
			
			left.setStyle('background-position', 'top left')
				.setStyle('float', 'left');		
			left.addClass('left');		
			
		top.inject(this.el, 'before');
		top.adopt(left, inner, right);
		
		var bottom = top.clone();
		bottom.setStyle('position', 'relative')
		bottom.setStyle('top', '-'+this.size+'px');
		bottom.getElement('div.left').getElement('img').setStyle('margin-top', - this.size+'px');
		bottom.getElement('div.right').getElement('img').setStyle('margin-top', - this.size+'px');
		bottom.inject(this.el, 'after');
		
		
	},
	initOther: function()
	{
		this.initIE();		
	},
	initFF:function()
	{
		this.el.setStyle('-moz-border-radius', this.size+'px');
	},
	initSafari:function()
	{
		this.el.setStyle('-webkit-border-radius', this.size+'px');
	},
	initOpera:function()
	{
		this.el.setStyle('-presto-border-radius', this.size+'px');
	}
	
	
	
	
})

