Ajax.prototype.old_request = Ajax.prototype.request;
Ajax.prototype.request = function(url) {
	if (url) {
		this.old_url = this.url;
		this.url = this.url + url;
		this.old_request();
		this.url = this.old_url;		
	} else {
		this.old_request();
	}
}

window.addEvent('domready',function(ev){
	if ($('subnav')) {
		var base = '/' + window.location.pathname.split('/')[1] + '/';
		var req = new Ajax(base,{
			onComplete: function(text) {
				new Element('div', { id: 's_slider_wrapper'}).setStyles({
					overflow: 'hidden',
					position: 'relative',
					width: $E('#main .body').getSize().size.x,
					height: $('main').getSize().size.y + 'px'
				}).injectInside($('main')).adopt(new Element('div',{ id: 's_slider' }).setStyles({
						width: '2000px',
						height: '10000px'
				}));
				$E('#main .body').setStyles({
					width: $E('#main .body').getSize().size.x,
					float: 'left',
					position: 'relative'
				})
				text = text.trim().substr(18).substr(0,(text.trim().length - 18 - 6));
				$('s_slider').adopt($E('#main .body')).adopt(
					new Element('div').addClass('body').setStyles({
						width: $E('#main .body').getSize().size.x + 'px',
						float: 'left'
					}).setHTML(text).addClass('body')
				);
				do_text();
				$E('#main .body').effect('margin-left').start(-$E('#main .body').getSize().size.x);
				$('s_slider_wrapper').effect('height',{
					onComplete: function() {
						$E('#main .body').remove();
						$E('#main .body').injectBefore('s_slider_wrapper');
						$('s_slider_wrapper').remove();
					}
				}).start($$('#main .body')[1].getSize().size.y)
			}
		});
		$$('#subnav a').each(function(n){
			n.addEvent('click',function(ev) {
					new Event(ev).stop();
					var href = n.getProperty('href');
					if ($E('#subnav .active a') != n) {
						updateLinks(href);
						req.request(href.split('/')[2] + '/ajax/');
					}
			});
		});
	}
});

window.addEvent('load',function(ev){
	var func = function(obj) {
		return (function(ev){
			if(window.gecko) {
				window.event = ev;
			}
			obj.blur();
			var node = $(obj.parentNode);
			while(node.getTag() != 'a') {
				node = node.getParent();
			}
			node.fireEvent('click');
		});
	}
	$$('#subnav embed, #subnav object').each(function(n){
		if (window.ie) {
			n.onfocus = func(n);
		} else {
			n.addEvent('click',func(n));
		}
	})
});

function updateLinks(href) {
	$$('#subnav a').each(function(n){
		n.getParent().getParent().removeClass('active');
		var s = sIFR.getCallbackByFlashElement(n.getFirst().getFirst());
		if (s) { s.changeCSS(css.inactive); }
		if (n.getProperty('href') == href) {
			s = sIFR.getCallbackByFlashElement(n.getFirst().getFirst())
			if (s) { s.changeCSS(css.active); }
			n.getParent().getParent().addClass('active');
		}
	});
}
