/* rx-library.js */

// add classes to "first" and "last" children of node (fast routine)
// 17/09/09
jQuery.fn.RX_markSides = function(Q) {
	return this.each(function() {
		$(this).children(':first').addClass(Q.c_first);
		$(this).children(':last').addClass(Q.c_last);
	});
}
//

// add classes to "first" and "last" item inside UL. Used for clearing floats.
// use: <ul class="rx-rowsplit rx-rows-3">. 3 - number of items in one row
// 24/08/09
jQuery.fn.RX_rowSplit = function(Q) {
	return this.each(function() {
		var k = 1;
				i = $(this).attr('class').match(/rx-rows\-\d{1}/),
				n = i.toString().substr(8);

		$(this).children('li').each(function() {
			if (k == 1) {
				$(this).addClass(Q.c_first);
			} else if (k == n) {
				$(this).addClass(Q.c_last);
			}

			k = (k == n) ? 1 : k+1 ;
		});

		k = $(this).children('li:last');
		if (!k.hasClass(Q.c_last)) {
			k.addClass(Q.c_last);
		}
	});
}
//

// menu drop down : toggling + callbacks
// 24/08/09
jQuery.fn.RX_menu = function(Q) {
	return this.each(function() {
		$(this).hover(
			function() {
				var i = $(this).children('ul');
				if(i.size()) {
					i.css( {visibility:'visible', display:'none'}).show('fast');
					Q.onHover();
				}
			},
			function() {
				var i = $(this).children('ul');
				if(i.size()) {
					i.css( {visibility:'hidden' } );
					Q.onOut();
				}
			}
		);
	});
}
//

// smooth hover effect based on animated opacity
// 19/09/09
jQuery.fn.RX_smoothHover = function(Q) {
	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() {
	return this.each(function() {
		$(this).click(function() {
			window.open($(this).attr('href'));
			return false;
		})
		return;
	});
}
//

jQuery(document).ready(function() {

	$('.x-archives ul').RX_rowSplit({
		c_first : 'rx-first',
		c_last : 'rx-last'
	});

	 $('a.js-el, .js-el a').RX_externalLink();

});
