window.addEvent('domready',function() {
	$$('.droplink').each(function(a) {
		var d = $(a.get('id')+'_dropdown');
		if (!d) return;
		var p = a.getParent();
		var u = d.getChildren('ul')[0];
		var H = u.getChildren().length*24;
		var hideTimer = null;
		var fx = new Fx.Morph(d,{'link':'cancel'});
		d.setStyle('height','0px');
		a.addEvent('mouseover',function() {
			if (hideTimer) { $clear(hideTimer); hideTimer = null; };
			c = p.getCoordinates();
			if (d.hasClass('down')) { // top row
				d.setStyles({'display':'block','left':c.left,'top':c.bottom,'position':'absolute','overflow':'hidden'});
				fx.start({'height':H});
			}else{
				d.setStyles({'display':'block','left':c.left,'position':'absolute','overflow':'hidden'});
				if (parseInt(d.getStyle('top')) < c.top-H) { d.setStyle('top',c.top); }
				fx.start({'height':H,'top':c.top-H})
			}
		});
		d.addEvent('mouseover',function() { if (hideTimer) { $clear(hideTimer); hideTimer = null; }; });
		[a,d].each(function(x) { x.addEvent('mouseout',function() {
			if (hideTimer) $clear(hideTimer);
			hideTimer = function() { 
				c = p.getCoordinates();
				if (d.hasClass('down')) fx.start({'height':'0px'});
				else fx.start({'height':'0px','top':c.top});
				hideTimer = null;
			}.delay(100);
		});});
	});

	$$('.rcwhite20').each(function(r) {
		r.setStyle('position','relative');
		var c = r.getSize();
		var t; var t2;
		for (var k = 0; k < 4; k++) {
			var p1 = (Math.floor(k/2)==0?'t':'b'); var p2 = k%2==1?'l':'r';
			t = new Element('div');
			t.setStyles({'background':'url(/content/rc_white20_'+p1+p2+'.png)','position':'absolute','width':'20px','height':'20px',
										'left':k%2==1?'0px':(c.x-20)+'px','top':p1=='t'?'0px':(c.y-20)+'px'});
			t.inject(r);

		}


	});
	
	if ($$('.header_image').length) {
		$$('.header_image').set('tween',{duration:2000});
		header_on = $$('.header_image').length-1;
		switch_header.periodical(10000);
	}
});

var header_on = 0;
function switch_header() {
	var i = $$('.header_image');
	if (i.length == 1) return;
	i[header_on].tween('opacity',0.0);
	header_on = (header_on+1)%i.length;
	i[header_on].tween('opacity',1.0);
}
