/*Copyright(c)2010,alan*/
(function($){
    var piaofu = function(options){
        this.show = function(options){
            var pf = $.extend({
                'divid': null,
                'imgid': null,
                'width': '200',
                'height': '150',
				'delay':10
            }, options);
//			if ($('body').find('#'+pf.divid).length==1) {
//				
//			}
            $('#' + pf.divid).css({
                position: 'absolute',
				display:'block',
                zIndex: '1001',
				width:pf.width,
				height:pf.height,
                top: yPos + document.body.scrollTop,
                left: xPos + document.body.scrollLeft
            });
			 $('#' + pf.imgid).css({
				width:pf.width,
				height:pf.height
            });
            var xPos = 0;
            var yPos = 0;
            var step = 1;
            var height = 0;
            var yon = 0;
            var xon = 0;
            var exwidth = document.body.clientWidth;
            var exheight = document.body.clientHeight;
            start();
			$('#'+pf.divid).hover(function(){
				pause();
			},function(){
				start();
			});
//			$(window).resize(function(){
//				alert (exheight);
//				changePos();
//			});
            function changePos(){
                if (yon) {
                    yPos = yPos + step;
                } else {
                    yPos = yPos - step;
                }
                if (yPos < 0) {
                    yon = 1;
                    yPos = 0;
                }
                if (yPos >= (exheight - pf.height)) {
                    yon = 0;
                    yPos = (exheight - pf.height);
                }
				if (xon) {
					xPos = xPos + step;
				}else {
					xPos = xPos - step;
				}
				if (xPos < 0){
					xon = 1;
					xPos = 0;
				} 
				if (xPos >= (exwidth - pf.width)){
					xon = 0;
					xPos = (exwidth - pf.width);   
				} 
                $('#' + pf.divid).css({
                    top: yPos + document.body.scrollTop,
                    left: xPos + document.body.scrollLeft
                });
            }
			function start(){
			    interval = setInterval(changePos, pf.delay);
			}
			function pause(){
				clearInterval(interval);
			}
        };
    };
    $.extend({
        piaofu: new piaofu()
    });
})(jQuery);

