/**
 *      按比例缩放图片
 *      @param int maxW 允许的最大宽度
 *      @param int maxH 允许的最大高度
 *		@author yeahoo2000@163.com
 */
$.fn.fixsize = function(maxW, maxH, speed, callback){
    speed = speed - 0 ? speed : 100;
    this.each(function(){
        fixImg(this, maxW, maxH, speed);
    });

    function fixImg (img, maxW, maxH, speed){
        var oImg = new Image();
        oImg.src = img.src;
        var oRatio = oImg.width / oImg.height;
        var ratio = maxW / maxH;
        var w,h;
        if(oImg.width > maxW && oRatio >= ratio){
            w = maxW;
            h = maxW / oRatio;
        }else if (oImg.height > maxH  && oRatio <= ratio){
            w = maxH * oRatio;
            h = maxH;
        }else {
            w = oImg.width;
            h = oImg.height;
        }

        $(img).attr({width:w, height:h}).css({width:w, height:h});
        $(img).animate({opacity:'show'}, speed, callback);
    }
}
$.winopen = function(
    src		//窗口内容地址
    ,width	//宽度
    ,height	//高度
    ,s		//是否允许滚动条
){
    //弹出窗口并自动居中显示
    s = (s)?',resizable=1,scrollbars=yes':'';
    aa=window.open(src,'_blank','width='+width+','+'height='+height+s);
    b=screen.width;
    c=screen.height;
    b=(b-width)/2;
    c=(c-height)/2;
    aa.moveTo(b,c);
}

//购物车代码
var shoppingCart = null;
function showShoppingCart(src){ 
    width = 500;
    height = 280;
    win=window.open(src,'ShoppingCart','width='+width+','+'height='+height+',resizable=1,scrollbars=yes');
    w=screen.width;
    h=screen.height;
    w= w-width-50;
    h= h-height-120;
    win.moveTo(w,h);
    return win;
}
function addItem(src){
    if(shoppingCart && !shoppingCart.closed){
        shoppingCart.location.replace(src);
    }
    else{
        shoppingCart = showShoppingCart(src);
    }
    shoppingCart.focus();
}

