(function($) {
	$.fn.floatWindow = function(setting){
		var _settings = {
			posx: 0,
			posy: 100,
			fpos:{
				r: false
			}
		};
		if(setting){
			$.extend(_settings , setting);
		}
		return new floatWindowPlugin().instance(this);
		
		function floatWindowPlugin(){
			return {
				obj: null,
				instance: function(obj){
					this.obj = obj;
					return this;
				},
				
				_init: function(){
					if($.browser.msie){
						this.obj[0].style.position = 'absolute';
					}else{
						this.obj[0].style.position = 'fixed';
					}
					var l = this._posx();
					var t = this._posy();
					this.obj[0].style.left = l+'px';
					this.obj[0].style.top = t+'px';
				},
				
				_posx: function(){
					if(_settings.fpos.r){
						return Math.max(0 , ($(window).width() - _settings.posx));
					}
					return Math.min(_settings.posx , ($(window).width()-this.obj.width()));
				},
				
				_posy: function(scroll){
					scroll = scroll || false;
					return Math.min(($(window).height() - this.obj.height() + (scroll ? $(window).scrollTop() : 0)) , (_settings.posy + (scroll ? $(window).scrollTop() : 0)));
				},
				
				_fire: function(){
					if($.browser.msie){
						$(window).bind('scroll' , {fwindow:this} , function(e){
							var l = e.data.fwindow._posx();
							var t = e.data.fwindow._posy(true);
							e.data.fwindow.obj[0].style.left = l+'px';
							e.data.fwindow.obj[0].style.top = t+'px';
						});
					}
				},
				
				start: function(){
					this._init();
					this._fire();
				}
			}
		}
	}
})(jQuery);


$(document).ready(function(){
	if(document.getElementById("top-nav")){
		var sfEls = document.getElementById("top-nav").getElementsByTagName("li");
		if(!sfEls){
			return;
		}
		for (var i = 0 ; i < sfEls.length ; i++){
			sfEls[i].onmouseover = function(){
				this.className += (this.className.length > 0? " ": "") + "sfhover"; 
			}
			sfEls[i].onMouseDown = function(){
				this.className+=(this.className.length > 0? " ": "") + "sfhover"; 
			}
			sfEls[i].onMouseUp = function(){
				this.className+=(this.className.length > 0? " ": "") + "sfhover"; 
			}
			sfEls[i].onmouseout=function(){
				this.className = this.className.replace(new RegExp("( ?|^)sfhover\\b") , ""); 
			}
		}
	}
	if($('#service-hline').length){
		var fwindow = $('#service-hline').floatWindow();
		fwindow.start();
	}
});
