

(function(jQuery) {
	jQuery.fn.stickybar = function(options) {
		return this.each(function() {
			this.settings = {
				showstickybarOnLoad: 'false',
				close: 'none',
				dontShow: 'none',
				dontShowExpire: 0,
				stickybarPosition: 'bottom',
				animation: 'slide',
				animationSpeed: 'slow',
				height: 'auto',
				background: 'none',
				id: jQuery(this).attr('id'),
				closeTimer: 0
			}
		
			if(options){
				jQuery.extend(this.settings, options);
			}
			
			var settings = this.settings;
			
			if(jQuery.browser.msie && jQuery.browser.version <= 8){
				
				if (settings.height != 'auto') {
					settings.height = settings.height + 2;
				}
				
				jQuery(this).css({'height':settings.height+'px'});
			}
			
			
				
			
			
			if (settings.height != 'auto') {
				settings.height = settings.height + 'px';
			}
						
			jQuery('html, body').css({'margin':'0', 'padding':'0', 'height':'100%'});
			jQuery(this).show().wrap('<div id="stickybar-wrap-'+settings.id+'"><div id="stickybar-container-'+settings.id+'">' + '</div></div>');
			
			jQuery('#stickybar-wrap-'+settings.id).css({'position':'fixed', 'width':'100%', 'height': settings.height}).css(settings.stickybarPosition,"-1");
			
			jQuery('#stickybar-container-'+settings.id).css({'background': settings.background, 'height': settings.height});
			//Give the close and dontShow elements a cursor (there's no need to use a href)
			jQuery(settings.close+","+settings.dontShow).css({"cursor":"pointer"});
			
			if(jQuery.browser.msie && jQuery.browser.version <= 8){
				jQuery('html, body').css({'height':'100%', 'width':'100%', 'overflow':'hidden'});
				jQuery('#stickybar-wrap-'+settings.id).css({'position':'absolute', 'bottom':'-3px'});				
				
				jQuery("body").children()
					.filter(function (index) {
						return jQuery(this).attr("id") != "stickybar-wrap-"+settings.id;
					})
				.wrapAll('<div id="ie6-content-container-'+settings.id+'">', '</div>');
				jQuery('#ie6-content-container-'+settings.id).css({'position':'relative', 'overflow':'auto', 'width':'100%', 'height':'100%'});
				//Check if ie6-content-container has a scrollbar present. If it does we need to move the stickybar container over 17px
				var element = document.getElementById('ie6-content-container-'+settings.id);
				if ((element.clientHeight < element.scrollHeight)&&(settings.height != 100+'%')) {
					jQuery('#stickybar-container-'+settings.id).css({'margin-right':'17px'});		
				}
				var bodyStyle = document.body.currentStyle;	
				var bodyBgStyles = bodyStyle.backgroundColor +" "+ bodyStyle.backgroundImage +" "+ bodyStyle.backgroundRepeat +" "+ bodyStyle.backgroundAttachment +" "+ bodyStyle.backgroundPositionX +" "+ bodyStyle.backgroundPositionY;
				jQuery('body').css({'background-image' : 'none'});
				jQuery('#ie6-content-container-'+settings.id).css({'background' : bodyBgStyles});
			}
			
			if((settings.animation == "slide")&&(settings.showstickybarOnLoad != "true")){			
				jQuery('#stickybar-wrap-'+settings.id).hide().slideDown(settings.animationSpeed);
				jQuery(settings.close).click(function(){
					jQuery("#stickybar-wrap-"+settings.id).slideUp();							
				});
				
				jQuery(settings.dontShow).click(function () {
					jQuery("#stickybar-wrap-"+settings.id).slideUp();	
				});
			} else if((settings.animation == "fade")&&(settings.showstickybarOnLoad != "true")) {
				jQuery('#stickybar-wrap-'+settings.id).hide().fadeIn(settings.animationSpeed);
				jQuery(settings.close).click(function(){
					jQuery("#stickybar-wrap-"+settings.id).fadeOut(settings.animationSpeed);								
				});
				
				jQuery(settings.dontShow).click(function () {			
					jQuery("#stickybar-wrap-"+settings.id).fadeOut();	
				});	
			} else if ((settings.showstickybarOnLoad == "true")&&(settings.animation == "slide")){
				jQuery('#stickybar-wrap-'+settings.id).show();
				jQuery(settings.close).click(function(){
					jQuery("#stickybar-wrap-"+settings.id).slideUp();							
				});
				
				jQuery(settings.dontShow).click(function () {
					jQuery("#stickybar-wrap-"+settings.id).slideUp();	
				});
			} else if ((settings.showstickybarOnLoad == "true")&&(settings.animation == "fade")){
				jQuery('#stickybar-wrap-'+settings.id).show();
				jQuery(settings.close).click(function(){
					jQuery("#stickybar-wrap-"+settings.id).fadeOut(settings.animationSpeed);								
				});
				
				jQuery(settings.dontShow).click(function () {			
					jQuery("#stickybar-wrap-"+settings.id).fadeOut();
				});
			}
			
			if (settings.closeTimer > 0) {
				if (settings.animation == "slide") {
					setTimeout(function(){jQuery("#stickybar-wrap-"+settings.id).slideUp();}, (settings.closeTimer * 1000));
				} else if (settings.animation == "fade") {
					setTimeout(function(){jQuery("#stickybar-wrap-"+settings.id).fadeOut();}, (settings.closeTimer * 1000));
				}
			} 
		});
	}
})(jQuery);