/***************************************************
创建日期：2009-08-16
函数描述：jQuery effects ins
***************************************************/
/* 无缝滚动 */
(function($) { 
 $.fn.jMarquee = function(o) {
    o = $.extend({
    speed:30,
    step:1,
    direction:"left",
    visible:1,
    fix:true
    }, o || {});
    
    var i=0;
    var div=$(this);
    var ul=$("ul",div);
    var tli=$("li",ul);
    var liSize=tli.size();
    if(o.direction=="left")
        tli.css("float","left");
    var liWidth=tli.innerWidth();
//		var liWidth=parseInt(tli.css("width"));
//    alert(liWidth);
    var liHeight=tli.height();
    var ulHeight=liHeight*liSize;
    var ulWidth=liWidth*liSize;
  

    if(liSize>o.visible){
        ul.append(tli.slice(0,o.visible).clone())
        li=$("li",ul);
        liSize=li.size();
        

        div.css({"position":"relative","overflow":"hidden"});
        ul.css({"position":"relative","width":"100%","height":"100%"});
        li.css({"position":"relative"});
        
        switch(o.direction){
            case "left":
		            if(!o.fix){
		            	div.css("width",(liWidth*o.visible)+"px");
		            }
                ul.css("width",(liWidth*liSize)+"px");
                li.css("float","left");
                break;
            case "right":
		            if(!o.fix){
		            	div.css("width",(liWidth*o.visible)+"px");
		            }
                ul.css("width",(liWidth*liSize)+"px");
                li.css("float","left");
                div.scrollLeft(ulWidth);
                break;
            case "up":
		            div.css({"height":(liHeight*o.visible)+"px"});
                ul.css("height",(liHeight*liSize)+"px");
                break;
        }
        
       
        var MyMar=setInterval(ylMarquee,o.speed);
        ul.hover(
            function(){clearInterval(MyMar);},
            function(){MyMar=setInterval(ylMarquee,o.speed);}
        );
    };
    function ylMarquee(){
         
        if(o.direction=="left"){
            if(div.scrollLeft()>=ulWidth){
                div.scrollLeft(0);
            }
            else
            {
                var leftNum=div.scrollLeft();
                leftNum+=parseInt(o.step);
                div.scrollLeft(leftNum);
            }
        }
        
        if(o.direction=="right"){
            if(div.scrollLeft()<=0){
                div.scrollLeft(ulWidth);
            }
            else
            {
                var leftNum=div.scrollLeft();
                leftNum = leftNum - parseInt(o.step);
                div.scrollLeft(leftNum);
            }
        }
        
        if(o.direction=="up"){
            if(div.scrollTop()>=ulHeight){
               div.scrollTop(0);
                
            }
            else{
               var topNum=div.scrollTop();
               topNum+=parseInt(o.step);
               div.scrollTop(topNum);
            }
        }
    };
};  
})(jQuery);
/* 图片放大（鼠标） */
(function($){
	$.fn.lsrc = function(para){
		para = $.extend({
			width:200,
			height:200,
			x : 15,
			y : 15
		}, para || {});
		var o = $("img[lsrc]");

		o.mouseover(function(){
			var lsrc = $(this).attr("lsrc");
			if(lsrc!=""){
				show(lsrc,para.width,para.height);
			}
			else{
				return false;
			}
		});
	
		o.mouseout(function(){
			hide();
		});

		o.mousemove(function(e){
			
			var offset_x = $(".show_lsrc_box img").width();
			var offset_y = $(".show_lsrc_box img").height();
			$(".show_lsrc_box").css("top",(e.pageY-offset_y-para.y)+"px");
			$(".show_lsrc_box").css("left",(e.pageX-offset_x-para.x)+"px");
			
		});

	}
	function show(lsrc,width,height){
		$(".wrapper").append("<div class='show_lsrc_box'></div>");
		$(".show_lsrc_box").css({
			"width":width+"px",
			"height":height+"px",
			"position":"absolute",
			"z-index":"2",
			"border":"5px solid #CCCCCC",
			"background-image":"url(/content/image/loading.gif)",
			"background-repeat":"no-repeat",
			"background-position":"center"
		});
		$(".show_lsrc_box").html("<img width="+(width+'px')+" height="+(height+'px')+" src="+lsrc+" />");
		$(".show_lsrc_box img").loadOneImg({src:lsrc});
	}
	function hide(lsrc){
		$(".show_lsrc_box").remove();
	}
})(jQuery);

/* 加载图片（一个） */
(function($){
	$.fn.loadOneImg = function(options){
		options = $.extend({
			 src : ""
		},options);
		var _self = this;
		_self.hide();
		var img = new Image();
		$(img).load(function(){
			_self.attr("src", options.src);
			_self.fadeIn("slow");
		}).attr("src", options.src);  //.atte("src",options.src)要放在load后面，
		return _self;
	}
})(jQuery);
/* 图片居中（一个） */
(function($){
	$.fn.ImgCenter = function(){
		var _self = this;
		var img_width = _self.width();
		var img_height = _self.height();
		var parent = _self.parent();
		var parent_width = parent.width();
		var parent_height = parent.height();

		if(img_width == 0){
			return false;
		}
		
		var left = parseInt((parent_width - img_width)/2);
		var top = parseInt((parent_height - img_height)/2);
		
		alert(_self.attr("src"));
		alert(parent_width);
		alert(img_width);
		
		this.css("margin-left",left+"px");
		this.css("margin-top",top+"px");
		
	}
})(jQuery);
