jQuery.fn.center = function () {
    this.css("position","absolute");
    if($(window).height() <=  this.outerHeight()){
        this.css("top", 10 + $(window).scrollTop() + "px");
	} else {

                if(this.height() < 50){
                        this.css("top", 30 + "px");
                } else{
                        this.css("top", (($(window).height() - this.height()) / 2) + "px");
                }

		this.css("position","fixed");
    }
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

$(document).ready(function(){

        $('.ajaxer').live('click', function(e){
                e.preventDefault();
				if(!($(this).hasClass('active'))){
	                $('.ajaxer').removeClass('active');
	                var _href= $(this).attr('href');
	                var _this = $(this);
	                $.ajax({
	                        url: _href,
	                        success: function(data){
									$('.rightText').stop();
									_this.addClass('active');
									var alto = $('.longContainer').height();
									$('.longContainer').css('height',alto+'px');
									$('.rightText').fadeOut(500, function(){
										$('.rightText').html(data);
	                                	$('.rightText').fadeTo(500,1);
										$('.longContainer').css('height','auto');
									});
	                        }
	                });
				}
        });

        $('.popup').live('click', function(e){
                e.preventDefault();
                var _href= $(this).attr('href');
                var _this = $(this);
				$('body').append($('#overlay'));
                if(_this.hasClass('photo')){
                        $('.popupReciver').html('<img src="'+_href+'" />');
                        $('.overlay').css('width', $(document).width()+'px');
                        $('.overlay').css('height', $(document).height()+'px');
			$('.overlay').fadeIn();
                        $('.popupWrapper').css('width',(800+12)+'px');
                        $('.popupReciver').fadeIn();
                        $('.popupWrapper').center();
                } else {
                        $.ajax({
                                url: _href,
								cache: false,
								dataType: 'html',
                                success: function(data){
										$('.popupReciver').html(data);
                                        $('.overlay').css('width', $(document).width()+'px');
                                        $('.overlay').css('height', $(document).height()+'px');
										$('.overlay').fadeIn();
                                        $('.popupWrapper').css('width',($('.popupWrapper>div').width()+12)+'px');
                                        $('.popupReciver').fadeIn();
                                        $('.popupWrapper').center();
                                }
                        });
                }
        });

        $('.btnCerrar, .close').live('click', function(e){
                e.preventDefault();
                $('.overlay').fadeOut('fast', function(){
                        $('.popupReciver').html('');
                });
        });

		/* slider soluciones */

	$('.arrow-l').live('click',function(){
			$('.r_clonned').remove();
			var $riel = $('.slider-reel');
			var current_l = $riel.css('margin-left').replace('px','');
			var new_l = (current_l - 159) + 'px';
			var $clon = $riel.find('li:not(.l_clonned):last').clone();
			$riel.find('li:not(.l_clonned):last').addClass('l_clonned');
			$riel.find('li:first').before($clon);
			$riel.css('margin-left',new_l);
			$riel.stop().animate({'margin-left': 0}, 500, function() {
				$riel.find('.l_clonned').remove();
			});
		});


		$('.arrow-r').live('click',function(){
			$('.l_clonned').remove();
			var $riel = $('.slider-reel');
			var $clon = $riel.find('li:not(.r_clonned):first').clone();
			$riel.find('li:not(.r_clonned):first').addClass('r_clonned');
			$riel.find('li:last').after($clon);
			var cant = $('.r_clonned').length;
			var new_l = -159*cant;
			$riel.stop().animate({'margin-left': new_l}, 500, function() {
				$riel.find('.r_clonned').remove();
				$riel.css('margin-left','0px');
			});
		});

		/* fin slider soluciones */

})
