/*
example :

<script type="text/javascript" src="js/fit_slider/jquery.fit_slider.js"></script>
<link href="js/fit_slider/jquery.fit_slider.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" >
	$(function(){
		$('.fit-float').fit_float({ 'bodywidth' : 940 });
	});
</script>
<div class="fit-float">
	<img src="themes/cn/image/tab_bg.jpg" />
</div>

*/

;(function($) {
	
	$.fn.fit_float = function(options) {
		
		if (!$(this).length) {
			return this;
		}

		settings = {
			//url    : '' ,        //service地址
			bodywidth : '990' ,
			position  : 'left'          // left right 
		}
		
		//合并设置
		if(options) {            
            $.extend(settings, options);
		}
		
		var thisobj = this;
			
		//判断是否为ie6
		var is_ie6 = window.XMLHttpRequest ? false : true;
		
		//显示
		thisobj.show();
		var postions = is_ie6 ? 'absolute' : 'fixed';
		thisobj.css("position" , postions );
		
		if ( is_ie6 ) {
			window.onscroll =function(){   
				posFloat( thisobj , settings );
			}
		}
		
		$(window).bind('resize', function() {
   		 	posFloat( thisobj , settings );	    	
		});

		posFloat( thisobj , settings);
	}


	function posFloat( bhobj , settings) {
		var is_ie6 = window.XMLHttpRequest ? false : true;
		
		Leftfix = -5;
		Topfix = 5;
		body_width = 940 ;
		bhTop = document.documentElement.clientHeight - bhobj.height() ;
		bhTop = is_ie6 ? bhTop + document.documentElement.scrollTop : bhTop;
		//bhLeft = document.documentElement.clientWidth - bhobj.width() - Leftfix ;
		var client_width = document.documentElement.clientWidth;
		if ( client_width > ( body_width + bhobj.width() * 2 ) ) {
			bhLeft = client_width/2 + body_width/2 - Leftfix ;
		} else {
			bhLeft = client_width - bhobj.width() - Leftfix ;
		}
	
		bhobj.css("top", bhTop - Topfix) ;
		bhobj.css("left", bhLeft) ;
		
		//$('#error').html( 'body_width:' +  settings.position );
		//alert(bhLeft);
		
	}


})(jQuery);

