/* rx-library.js */

// add classes to "first" and "last" children of node (fast routine)
// 17/09/09
jQuery.fn.RX_markSides = function(Q) {
	var $ = jQuery.noConflict();
	return this.each(function() {
		$(this).children(':first').addClass(Q.c_first);
		$(this).children(':last').addClass(Q.c_last);
	});
}
//

// menu drop down : toggling + callbacks
// 24/08/09
jQuery.fn.RX_menu = function(Q) {
	var $ = jQuery.noConflict();
	return this.each(function() {
		$(this).hover(
			function() {
				var t = $(this),
						i = t.children('ul');

				if(i.size()) {
					t.addClass('rx-selected');
					//t.parents('.rx-expand').animate({'height' : i.outerHeight(true)}, 'fast');
					i.css( {visibility:'visible', display:'none'}).slideDown('fast');
					//Q.onHover();
				}
			},
			function() {
				var t = $(this),
						i = t.children('ul');
	//					k = (i.size()==0) ? 0 : i.outerHeight('true');

				if(i.size()) {
					t.removeClass('rx-selected');
					i.css( {visibility:'hidden'} );
					//Q.onOut();
				}
//				t.parents('.rx-expand').stop().animate({'height' : k}, 'fast');

			}
		);
	});
}
//

jQuery.fn.RX_expand = function(Q) {
	var $ = jQuery.noConflict();
	this.each(function() {
		var p = $(this),
				s = 0;

		p.children('li').each(function() {
			var i = $(this).children('ul').children('li').size() * 15;
			s = (i>s) ? i : s;
		});

		p.parents('.rx-expand').hover(
			function() {
				$(this).animate({'height':s}, 79);
			},
			function() {
				$(this).animate({'height':0}, 79);
			}
		);

	});
}

// smooth hover effect based on animated opacity
// 19/09/09
jQuery.fn.RX_smoothHover = function(Q) {
	var $ = jQuery.noConflict();
	this.each(function() {
		$(this).hover(
			function() {
				if (!$(this).hasClass(Q.c_dis)) {
					$(this).children('a').animate({opacity:1}, 'fast');
				}
			},
			function() {
				if (!$(this).hasClass(Q.c_dis)) {
					$(this).children('a').animate({opacity:Q.hide}, 'fast');
				}
			}
		);
	});
}
//

// open links in another window
// 01/09/09
jQuery.fn.RX_externalLink = function() {
	var $ = jQuery.noConflict();
	return this.each(function() {
		$(this).click(function() {
			window.open($(this).attr('href'));
			return false;
		})
		return;
	});
}
//

// open/close elements
// 30/10/09
jQuery.fn.RX_toggleBlocks = function(Q) {
	var $ = jQuery.noConflict();
	return this.each(function() {
		var par = $(this);

		$.each(Q.elm, function(i, item) {
			par.find('a'+item).click(function() {
				par.find('form'+item).slideToggle('fast');
				return false;
			});
		});

	});
}
//

jQuery(window).load(function() {
	var $ = jQuery.noConflict();
	$('a.rx-el, .rx-el a').RX_externalLink();

	$('.menu-navy, .menu-links, .x-comment ul, .x-comment .screen, .menu-aux').RX_markSides({
		c_first : 'rx-first',
		c_last : 'rx-last'
	});

	$('.menu-navy li, .menu-aux li').RX_menu();

	$('.menu-aux').RX_expand();

	$('.x-comment').RX_toggleBlocks({
		elm : [ '.rx-add', '.rx-send' ]
	});

	//

	$('.rx-close').click(function() {
		var n   = $(this),
				par = n.parents('.x-comment'),
				elm = par.find('.screen'),
				c_t = 'rx-selected',
				tx1 = 'close comments',
				tx2 = 'open comments';

		if (n.hasClass(c_t)) {
			elm.slideDown(function() {n.removeClass(c_t);n.html(tx1);});
		} else {
			elm.slideUp(function() {n.addClass(c_t);n.html(tx2);});
		}

		return false;
	});

});


jQuery(function(){
    Cufon.replace('div.x-post h2, div.x-post div.postmeta');
})