﻿// JScript 文件
//----------------------浮动窗口开始--------------------------------
function ShowDetail(obj, htmlContent) {

    var conspan = 0; //插入图片的深度
    var htmlContent = htmlContent;
    var newObj = GetWH($(obj));
    newObj.left = GetLeftOrTop(obj, "left");
    newObj.top = GetLeftOrTop(obj, "top");
    var objImgWH = GetWH($("#imgICO"));
    var objDialogWH = GetWH($("#detail"));
    var left = newObj.left;
    var broderWidth = 1;
    var scrollTop = document.documentElement.scrollTop;
    var autoWidth = 0;

    objDialogWH.top = parseInt(document.documentElement.clientHeight) - (newObj.top - scrollTop) - objDialogWH.h;
    if (objDialogWH.top < 0) {
        objDialogWH.top = newObj.top + objDialogWH.top - 3;
        if (objDialogWH.top < 0) objDialogWH.top = scrollTop;
    } else {
        objDialogWH.top = newObj.top;
    }
    objImgWH.top = newObj.top + 30;
    objDialogWH.left = document.documentElement.clientWidth - left - parseInt(objDialogWH.w) - parseInt($(obj).css("width")) - conspan;

    if (left > document.documentElement.clientWidth - left - parseInt($(obj).css("width"))) {
        objDialogWH.left = left - objDialogWH.w - objImgWH.w + conspan + broderWidth + 1 + autoWidth - 3;
        objImgWH.left = left - objImgWH.w + conspan + broderWidth * 2 + autoWidth - 3;

        $("#detail").html(htmlContent);
        $("#imgICO").css("background-position", "0 25px");
    } else {
        objImgWH.left = newObj.left + parseInt($(obj).css("width")) - conspan + autoWidth;

        objDialogWH.left = objImgWH.left + objImgWH.w - broderWidth;
        $("#detail").html(htmlContent);
        $("#imgICO").css("background-position", "0 0");

    }

    $("#imgICO").css("left", objImgWH.left + "px");
    $("#imgICO").css("top", objImgWH.top + "px");

    $("#detail").css("left", objDialogWH.left + "px");

    $("#detail").css("top", objDialogWH.top + "px");

    if (objdml == null) {
        ShowDetailHide();
        return false;
    }
    $("#imgICO").show();
    $("#detail").show();
    $("#detail").bgiframe();
    if (objImgWH.top > (objDialogWH.top + objDialogWH.h - objImgWH.h))
        $("#imgICO").hide();
    //alert(document.getElementById("detail").outerHTML)
}
function ShowDetailHide() {
    $("#imgICO").hide(); ;
    $("#detail").hide();
}
function GetWH(obj) {
    var objwh = new ObjWH();
    objwh.w = parseInt(obj.css("width"));
    objwh.h = parseInt(obj.css("height"));
    return objwh;
}
function ObjWH() {
    this.top = 0;
    this.left = 0;
    this.w = 0;
    this.h = 0;
}
function GetLeftOrTop(obj, strName) {
    var num = 0;
    do {
        if (strName == "left") {
            num += obj.offsetLeft;
        }
        else {
            num += obj.offsetTop;
        }

        obj = obj.offsetParent;
    } while (!(obj == null || obj.tagName == "BODY"));
    return num;
}
function Point(iX, iY) {
    this.x = iX;
    this.y = iY;
}
//----------------------浮动窗口结束--------------------------------

var objdml = null;
function PushObj() {
    objdml = null;
    ShowDetailHide();
}
function SetObj(obj) {
    objdml = obj;
    setTimeout("ShowProductInfo()", 500);
}

function ShowProductInfo() {
    if (objdml == null) {
        return false;
    }
    var obj = objdml;
    var productInfo = new ProductInfo();
    var productObj = "";
    var content = "";
    var imgWidth = 0;
    var imgHeight = 0;
    $($(obj).html()).each(function(i) {
        if ($(this).attr("class") == "productInfo") {
            productObj = $(this);
        }
    });
    if (productObj == "")
        return;
    $(productObj.html()).each(function() {
        SetProductInfo($(this), productInfo);
    });

    $("#detail").attr("class", "fc03");
    content = "<div style=\"text-align:center\"><img src=\"/images/loading.gif\"/></div>";
    ShowDetail(obj, content);


    $("<img src=\"" + productInfo.ProductPic + "\">").load(function() {
        var img = new Image();
        img.src = productInfo.ProductPic;

        if (img.width == "570")//修改为570
        {
            $("#detail").attr("class", "fc");
            imgWidth = 440;
            imgHeight = 340;
        }
        else {
            $("#detail").attr("class", "fc02");
            imgWidth = 440;
            imgHeight = 340;
        }
        content = DetailStr(productInfo);

        ShowDetail(obj, content);
        $("#driftImg").LoadImage(true, imgWidth, 310, "<img src=\"/images/loading.gif\"/>");
    }
    );
    $("<img src=\"" + productInfo.ProductPic + "\">").error(function() {
        $("#detail").attr("class", "fc02");
        imgWidth = 270;
        imgHeight = 310;
        content = DetailStr(productInfo);
        ShowDetail(obj, content);
    });


}
function ShowDiv() {
    var s = "";
}
function SetProductInfo(obj, productInfo) {
    switch (obj.attr("class")) {
        case "ProductName":
            productInfo.ProductName = obj.html();
            break;
        case "pic":
            productInfo.ProductPic = obj.html();
            break;
    
    }
}
function ProductInfo() {
    this.ProductPic = "";
    this.ProductCode = "";
    this.ProductName = "";
    this.ProductPrice = "";
    this.ProductVPrice = "";
    this.ProductSPrice = "";
    this.PointPrice = "0";
    this.Points = "0";
    this.ProductImgUrl = "";
    this.CommentsNumber = "";
    this.Comments = "";
    this.SalesFlag = "0";
    this.IsPoint = "0";
}
function DetailStr(productInfo) {
    var s = "<p align=\"center\" class=\"jJ\"><img src=\"" + productInfo.ProductPic + "\" id=\"driftImg\"  /></p>";
 return s;
}
function IsIE() {
    if (isFirefox = navigator.userAgent.indexOf("MSIE") > 0)
        return true;
    return false;
}
