// JavaScript Document

function shownewaddress(div_id)
{
	$("#"+div_id).toggle();
}

function hide(div_id)
{
	$("#"+div_id).hide();
}

function popupDiv(div_id)
    {
        
		
		var div_obj = $("#"+div_id);
        //窗口宽高
    	//var windowWidth = document.body.clientWidth;
        //var windowHeight = document.body.clientHeight;	
		var windowWidth = screen.width;
		var windowHeight = screen.height;
		
        //弹出层宽高
    	var popupHeight = div_obj.height();
        var popupWidth = div_obj.width();
		
		var v_left=(windowWidth-popupWidth)/2; 
		var v_top=(windowHeight-popupHeight)/2; 
		
        //目标位置
   		var btn= $("#checklist");
        var Coordinate= $("#checklist").offset();				

        div_obj.css({"position": "absolute"}).animate( { left:v_left,top:v_top,opacity: "show"    }, "slow" );
		//div_obj.css({"position":"absolute","z-index":"1000","top"})show();
		
		
		


}
   
   
   
   
function cartScroll(div_id)
{
	var name = "#"+div_id;
	var menuYloc = null;
	
	$(document).ready(function(){			
			menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")));
			//alert(menuYloc);
			$(window).scroll(function () { 
				offset = menuYloc+$(document).scrollTop()+"px";
				$(name).animate({top:offset},{duration:500,queue:false});
			});
		}); 


}

   
   function hideDiv(div_id) {
        $("#mask").remove();
        $("#" + div_id).animate({right: 0, top: 200, opacity: "hide" }, "slow");
    }




(function($){
$.fn.extend({
        Scroll:function(opt,callback){
                //参数初始化
                if(!opt) var opt={};
                var _btnUp = $("#"+ opt.up);//Shawphy:向上按钮
                var _btnDown = $("#"+ opt.down);//Shawphy:向下按钮
                var timerID;
                var _this=this.eq(0).find("ul:first");
                //var     lineH=_this.find("ul:first").height(), //获取行高
				var     lineH=_this.height(),//获取行高
                        line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数，默认为一屏，即父容器高度
                        speed=opt.speed?parseInt(opt.speed,10):500; //卷动速度，数值越大，速度越慢（毫秒）
                        timer=opt.timer //?parseInt(opt.timer,10):3000; //滚动的时间间隔（毫秒）
                if(line==0) line=1;
                var upHeight=0-line*lineH;
				
                //滚动函数
                var scrollUp=function(){
                        _btnUp.unbind("click",scrollUp); //Shawphy:取消向上按钮的函数绑定
                        _this.animate({
                                marginTop:upHeight
                        },speed,function(){
                                for(i=1;i<=line;i++){
                                        _this.find("ul:first").appendTo(_this);
										
                                }
                                _this.css({marginTop:0});
                                _btnUp.bind("click",scrollUp); //Shawphy:绑定向上按钮的点击事件
                        });

                }
                //Shawphy:向下翻页函数
                var scrollDown=function(){
                        _btnDown.unbind("click",scrollDown);
                        for(i=1;i<=line;i++){
                                _this.find("ul:last").show().prependTo(_this);								
                        }
                        _this.css({marginTop:upHeight});
                        _this.animate({
                                marginTop:0
                        },speed,function(){
                                _btnDown.bind("click",scrollDown);
                        });
                }
               //Shawphy:自动播放
                var autoPlay = function(){
                        if(timer)timerID = window.setInterval(scrollUp,timer);
                };
                var autoStop = function(){
                        if(timer)window.clearInterval(timerID);
                };
                 //鼠标事件绑定
                _this.hover(autoStop,autoPlay).mouseout();
                _btnUp.click( scrollUp ).hover(autoStop,autoPlay);//Shawphy:向上向下鼠标事件绑定
                _btnDown.click( scrollDown ).hover(autoStop,autoPlay);

        }       
})
})(jQuery);


$(document).ready(function(){
        //$(".carts").Scroll({line:4,speed:500,timer:1000,up:"btn1",down:"btn2"});
	if ($(".carts").length>0) {
		$(".carts").Scroll({line:7,speed:500,up:"btn1",down:"btn2"});
	}
});




function  ShoppingListScroll(mouseClickid,scrollId)
{
	var name = "#"+mouseClickid;
	var menuYloc = null;
	
}

function addToFavorite(goodsId, goodsName, goodsImg, marketPrice) {
	$.ajax({
		type: "POST",
		url: "goods.do",
		data: {action: "favorite", goodsId: goodsId, goodsName: goodsName, goodsImg: goodsImg, marketPrice: marketPrice},
		success: function(data) { var ret=eval("("+data+")"); alert(ret.message); },
		error: function() { alert("Service Error"); }
	}); 
}

function LTrim(str){ 
	var i;
	for(i=0;i <str.length;i++){
		if(str.charAt(i)!=" "&&str.charAt(i)!=" ") 
		break;
	}
	str = str.substring(i,str.length);
	return str;
}
function RTrim(str){
	var i;
	for(i=str.length-1;i>=0;i--){
		if(str.charAt(i)!=" "&&str.charAt(i)!=" ") 
		break;
	}
	str = str.substring(0,i+1);
	return str;
}
function Trim(str){ 
	return LTrim(RTrim(str)); 
}