var w, c;
var csel = false;
window.addEvent('domready', function(){
	var offset = 0;
	c = document.getElement('div.content');
	w = $('widget');
	var myEffect = new Fx.Tween($('widget'));
	var qlinks = $('widget').getElements('a');
	qlinks.each(function(e){
		var o = offset;
		e.getParent('div').addEvents({
			'mouseover':function(){
				qlinks.each(function(q){q.getParent('div').removeClass('selected'); });
				e.getParent('div').addClass('selected');
				$('widget').setStyle('background-position', o+'px bottom');
			},
			'mouseout':function(){
				if(csel)csel.fireEvent('mouseover');
			}
		});
		if (e.getParent('div').hasClass('selected')) {
			e.getParent('div').fireEvent('mouseover');
			csel = e.getParent('div');
		}
		offset = offset - 320;
	});
	window.addEvents({ 'resize': keepMenuTop, 'scroll': keepMenuTop });
	fixTargets();
});

function keepMenuTop(){
	var toTop = Window.getScrollTop() - 260;
	if (toTop > 0 && (c.getHeight() - 600) > toTop)  w.setStyle('margin-top', toTop);
	else if (toTop < 0) w.setStyle('margin-top', 30);
}
function fixTargets(){$(document.body).getElements('a').each(function(e){var hr=e.get('href');if(hr!=null && hr.match(/^http:\/\//g)) e.set('target','_blank');});}
