/*
 * Sticky footer plugin for jQuery
 */
;(function( $, window, document, undefined ){

$.stickyfooter = function (element, options) {
	var self = this;

	self.settings = {};

	var $footer = $(element),
		footer = element,
		$window = $(window),
		$page = $('#page'),
		$page_height = $page.height();
		$page_top = $page.offset().top;
	$.extend(self, {
		init : function () { 
			self.settings = $.extend({}, $.stickyfooter.defaults, options);
			$footer.wrap('<div><div style="width:100%"></div></div>').parent().parent().css({'width': '100%', 'height':$footer.height()});
			$window.bind('resize.stickyfooter', function () {
				setFooterPosition();
			});
			setFooterPosition();
		}
	});
	var setFooterPosition = function() {
		var document_height;
		if($.browser.msie && parseInt(jQuery.browser.version, 10) == 8 && document.documentMode == 8){
			document_height = document.documentElement.scrollHeight;
		}else{
			document_height = $(document).height();
		}
		if ( document_height - $window.height() <= 0) {
			$footer.parent().css({position: 'fixed', left: '0px', bottom: 0});
			$footer.css({width: $('body').width(),margin:'0 auto'});
			$('#page .inner').stop().css('paddingBottom',$footer.offset().top-$page_top-$page_height);
		} else {
			$footer.parent().stop().css({position: 'relative', bottom: 'auto'});
			$('#page .inner').stop().css('paddingBottom',0);
		}
	};

	self.init();
};

$.stickyfooter.defaults = {

};

$.fn.stickyfooter = function (options) {
	return this.each(function () {
		new $.stickyfooter(this, options);
	});
};

})( jQuery, window , document );

jQuery(document).ready(function($) {
	jQuery('#footer').stickyfooter();
});
