jQuery(document).ready(function($) {
								
								
		//deschide postul daca e singur
        var posts = jQuery('div.x-post');
        if (posts.length == 1) {
            posts.find('.rx-open').trigger('click');
        }

/* 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);
	});
}
//

// 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();
				}
			}
		);
	});
}
//

// menu clickable : toggling
// 19/09/09
var RX_clickMenu = function(Q) {
	this.init = function() {
		$(Q.c_par+Q.c_act).click(function() {
			var i = $(this).parent(Q.c_node);

			if (!i.hasClass(Q.select)) {
				hideNode();
				i.find(Q.c_elm).slideDown('fast');
				i.addClass(Q.select);
			} else {
				hideNode();
			}
			return false;
		})
	}
	//

	function hideNode() {
		var i = $(Q.c_par+'>'+Q.c_node+'.'+Q.select);
		i.removeClass(Q.select);
		i.find(Q.c_elm).slideUp('fast');
	}
	//
}
//

// sliding menu
// 15/01/10
jQuery.fn.RX_slideMenu = function(Q) {
	this.each(function() {
		var I = $(this);

		I.children('li').mouseenter(function() {
				var J = $(this),
            i = J.position(),
            j = i.left + Math.floor(J.outerWidth(true) / 2 - Q.coef);
				I.stop().animate({backgroundPosition:j}, '79');
		});
	});
}
//

// 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).animate({opacity:1}, 'fast');
				}
			},
			function() {
				if (!$(this).hasClass(Q.c_dis)) {
					$(this).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;
	});
}
//

// mouse wheel & slider
// 30.09.09
jQuery.fn.RX_scroller = function(Q) {
	if ($.browser.mozilla) { _wheel_coef = 39; }
	else if($.browser.safari) { _wheel_coef = 29; }
	else { _wheel_coef = 34; }

	this.each(function() {
		var n_par = $(this);

		n_par.find(Q.n_scroll).bind('mousewheel', function(event, delta) {
				var node = n_par.find(Q.n_hiding);

				if ( node.attr('scrollHeight') > node.outerHeight() ) {
					var speed = node.height() / node.attr('scrollHeight') * (_wheel_coef),
							nv = node.scrollTop() - delta * speed;
					node.scrollTop(nv);
					var s_hande =  node.scrollTop() / ( node.attr('scrollHeight') -  node.height() ) * 100;

					n_par.find(Q.n_slider).slider('option', 'value', -s_hande );
					return false;
				}

				return true;
		});

		n_par.find(Q.n_slider).slider({
			animate: false,
			orientation: "vertical",
			min: -100,
			max: 0,
			slide: function(event, ui) {
				var node = n_par.find(Q.n_hiding);
				if ( node.attr('scrollHeight') > node.outerHeight() ) {
					var ratio = node.attr("scrollHeight") - node.height();
					node.attr( { scrollTop: -ui.value * (ratio / 100) } );
				} else {
					return false;
				}
				return true;
			}
		});
		//

	});
}
//

// comments view/add toggle
// 13/01/10
jQuery.fn.RX_toggleComment = function(Q) {
	this.each(function() {
		var I = $(this),
				i, j;

		I.find(Q.act).each(function() {
			$(this).click(function() {
				var i = $(this).attr('class'),
						j = I.children('.'+i);

				if (i != '') {
					if (!j.hasClass(Q.sel)) {
						I.children('.'+Q.sel).removeClass(Q.sel);
						j.addClass(Q.sel);
					}
					return false;
				}

        return true;
			});
		});
	});
}
//

// open/close elements
// 30/10/09
jQuery.fn.RX_toggleBlocks = function(Q) {
	return this.each(function() {
		var I = $(this);

		$.each(Q.elm, function(i, item) {
			I.find('a'+item).click(function() {
        var i = I.find('form'+item);
				i.slideToggle('fast');
        if ( i.css('display') == 'block' ) {
          $().scrollTo(I, 'normal', {offset:0});
        }
				return false;
			});
		});

	});
}
//

// post toggling + scroll document to post + show state + external open
// 25/01/10
var RX_postToggle_fx = function(Q) {
  var _busy = false;

  var f_show = function(I, state, func) {
    _busy = true;

    var i = $('.'+Q.select);
    i.removeClass(Q.select);
    i.find(Q.c_hide).slideDown('fast');
    i.find(Q.c_show).css('display', 'none');
    tx_change(i, true);

    I.find(Q.c_hide).slideUp('normal', function() {});

    I.find(Q.c_show).slideDown('fast', function() {
      I.addClass(Q.select);
      tx_change(I, false);

      if (!state) {
        $().scrollTo(I, 'fast', { onAfter:function() {
              _busy = false;
              if (func) { func(); }
            }
          }, {offset: '0'}
        );
      } else {
        _busy = false;
        if (func) { func(); }
      }

    });
  }, f_hide = function(I) {
    $().scrollTo(I, 'fast', {
      onAfter:function() {
        I.find(Q.c_show).slideUp('fast');
        tx_change(I, true);
        var i = I.find(Q.c_hide);
        if (i.size()) {
          i.slideDown('normal', function() {
            I.removeClass(Q.select);
            _busy = false;
          });
        } else {
            I.removeClass(Q.select);
            _busy = false;
        }
      }
    }, {offset: '0'} );
  }
  //

  if (Q.c_txt) {
    var tx_change = function(I, state) {
      var i = I.find(Q.a_toggle).children('span');
      (state) ? i.text(Q.c_txt[0]) : i.text(Q.c_txt[1]);
    }
    //
  } else {
    tx_change = function() {}
  }

  this.init = function() {
    $(Q.c_elm).each(function() {
      var I = $(this);

      I.find(Q.a_open).click(function() {
        f_show(I);
        return false;
      });

      I.find(Q.a_close).click(function() {
        f_hide(I);
        return false;
      });

      I.find(Q.a_toggle).click(function() {
        if (I.hasClass(Q.select)) {
          f_hide(I);
        } else {
          f_show(I);
        }
        return false;
      });
    });
  }
  //

  this.openPost = function(elm, func) {
    if (!elm.hasClass(Q.select)) {
      f_show(elm, false, func);
    } else {
      func();
    }
  }
  //

}
//

	$('a.rx-el, .rx-el a').RX_externalLink();

	$('.menu-navy, .menu-site, .x-archives ul, .list-link, .l-root .l-left').RX_markSides({
		c_first : 'rx-first',
		c_last : 'rx-last'
	});

  /*
  $('.menu-navy ul').RX_slideMenu({
    coef : 26 // width/2 of menu-navy-sel.png
  });
  */

	var rx_post = new RX_postToggle_fx({
		c_elm  : '.x-post',
		c_body : '.body',

		c_hide : '.title .l-d',
		c_show : '.body',

    a_toggle : '.rx-toggle',
		a_open : '.rx-open',
		a_close : '.rx-close',
		select : 's-open',

    c_txt : false,
	});
  rx_post.init();

  $('.social p a').RX_smoothHover({
    c_dis : '.rx-disable',
    hide : .79
  });

	$('.x-comment').RX_toggleBlocks({
		elm : [ '.rx-comm-add', '.rx-comm-email' ]
	});

  $('.rx-scrolltop').click(function() {
    $().scrollTo('.L-head', 'fast');
    return false;
  });

  /*
	$('.x-comment').RX_scroller({
		n_scroll: '.screen',
		n_hiding: '.screen',
		n_slider: '.rx-scroll'
	});
  */
  
    var posts = jQuery('div.x-post');
        if (posts.length == 1) {
            posts.find('.rx-open').trigger('click');
        }

});

