/* VARS */

var DELAY = 500;
var SPEED = 250;
var MARGE = 70;
var IS_FIRST_TIME = true;

//

var position = undefined;
var padding_bottom = undefined;
var height = undefined;

/* FUNCTIONS */

function setFooter() {

	if( $("#footer").length > 0 ) {
		
		if( IS_FIRST_TIME ) {
		
			MARGE = $("#footer").height();
			
		} else {
		
			MARGE = 0;
		
		}
		
		//
		
		position = $("#content").position();
		padding_bottom = parseInt( $("#content").css("padding-bottom").substr(0, 2) );
		height = parseInt( $("#content").height() + position.top + padding_bottom );
		
//		console.log( top );
//		console.log( padding_bottom );
//		console.log( height );
//		console.log( height + " - " + $(window).height() );

		/*  */

		if( height > ( $(window).height() - $("#footer").height() ) ) {
			
//			console.log("A");
			
			$("#footer").css("top", ( height + MARGE ) + "px");
		
		} else {
		
//			console.log("B");
			
			$("#footer").css("top", ( ( $(window).height() - $("#footer").height() ) + MARGE ) + "px");
		
		}
		
		/*  */
		
		$("#footer").css("display", "block");
		
		/*  */
		
		if( IS_FIRST_TIME ) {
		
			$("#footer").delay(DELAY).animate( {
				top: "-=" + MARGE
				}, SPEED, function() {
			
					
					
			} );
			
		}

	}

}

/* INIT */

$(window).load( function() {setFooter();} );

$(window).resize( function() {
	
	IS_FIRST_TIME = false;
	
	//
	
	setFooter();
	
} );
