(function($){
    $.fn.adaptToParent = function(){
        return this.each(function () {
        	/*
        		Adapte une div à son parent
        	*/
			var parent = $(this).parent().css ('position', 'relative');

			$(this).css ({
				'width' : parent.width(),
				'height' : (parent.height() == 0 ? '50px' : parent.height()),
				'position' : 'absolute',
				'top' : 0,
				'left' : 0
			});
        });
    };

	$.fn.inBox = function(w, h){
        return this.each(function () {
        	/*
        		Adapte l'élément aux mesures en gardant son propre ratio
        	*/

			var ratio = Math.min(w/$(this).width(), h/$(this).height());

			$(this).css ({
				'width' : $(this).width() * ratio,
				'height' : $(this).height() * ratio
			});
        });
    };
    
    $.fn.startLoading = function(options){
    	
    	var options = $.extend ({
			'text' : ''
    	}, options);
    	
        return this.each(function () {
        	/*
        		Crée un loading consistant à intégrer une DIV qui s'adapte à son élément parent
        	*/
			var DOMloading = $('<div class="loading">'+options.text+'</div>').css ({
				'position' : 'absolute'
			});
			
			$(this).append (DOMloading);
			DOMloading.adaptToParent();
			
        });
    };
    
    $.fn.stopLoading = function () {
    	$(this).children('.loading').remove();
	};
	
	$.fn.fullScreen = function () {
	
		$(this).css ({
			'position' : 'absolute',
			'top' : 0,
			'left' : 0,
			'width' : '100%',
			'height' : $(document).height(),
			'zIndex' : 9999
		}).addClass ('fullScreen');
		
		return this;
	}
	
	
	
	$.fn.toId = function () {
		var id = $(this).attr('id');
		
		if (id) {
			id = id.split('_')[1]	
		}
		
		return id;
	};
	
	$.fn.objectName = function () {
		var id = $(this).attr('id');
		
		if (id) {
			id = id.split('_')[0]	
		}
		
		return id;
	};
	
	$.fn.anchorToLink = function () {
		if ($(this).attr('href')) {
			return $(this).attr('href').substring(1, $(this).attr('href').length);
		}
	};
	
	$.fn.stripTags = function() {
		return this.replaceWith( this.replace(/<\/?[^>]+>/gi, '') );
	};

	
	$.fn.outterTabs = function () {
		$(this).find ('li a').click (function () {
			
			$(this).parents ('ul').find('li a').each (function () {
				var tempId = $(this).anchorToLink();
				$('#'+tempId).hide();
			});
			var tempId = $(this).anchorToLink();
			$('#'+tempId).show();
			
		});
		
		var idDefault = $(this).find ('li:first a').anchorToLink();
		$('#'+idDefault).show();
	};
	
	$.fn.tip = function (message) {
		if ($('#tip').size() == 0) {
			$('body').append ('<div id="tip"></tip>');
			$('#tip').hide();
		}
		$('#tip')
			.html(message);
		
		$('#tip')
			.css ('top', $(this).offset().top - 20)
			.css ('left', $(this).offset().left)
			.show();
		
		setTimeout(function() {
			$('#tip').hide();
		}, 5000);

		
	};
	
	$(window).resize(function () {
		$(".fullScreen").fullScreen();
	});
	$('body').resize(function () {
		$(".fullScreen").fullScreen();
	});
	
})(jQuery)

		
