﻿/*********
网站名称：福娃网络模板定制中心
QQ:290409929
http:www.mice.org.cn
***********/

var Dtimer = null;
var Dtimer2 = null;
var Mdisplay = false;
var hideDiv;
var Container;
var button;
var jqShowObj;
var offset;
var height;
var width;
var btnHeight;
var btnWidth;

function createCookie(name, value, days, Tdom) {
    var Tdom = (Tdom) ? Tdom : "/";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else {
        var expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=" + Tdom;
};
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') { c = c.substring(1, c.length); }
        if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length, c.length); }
    }
    return null;
};
function getCookie(name) {
    if (document.cookie.length > 0) {
        cookieStart = document.cookie.indexOf(name + "=")
        if (cookieStart != -1) {
            cookieStart = cookieStart + name.length + 1
            cookieEnd = document.cookie.indexOf(";", cookieStart)
            if (cookieEnd == -1) cookieEnd = document.cookie.length
            return unescape(document.cookie.substring(cookieStart, cookieEnd))
        }
    }
    return ""
};
function initDMenu(obj, showobj, Dtimeout, Dspeed) {
    hideDiv = jQuery("<div style='z-index:10000;'></div>");
    Container = jQuery("<div id=\"Container\"></div>");
    hideDiv.append(Container);
    button = jQuery(obj);
    jqShowObj = jQuery(showobj);
    offset = button.offset();
    height = jqShowObj.height();
    width = jqShowObj.width();
    btnHeight = button.height();
    btnWidth = button.width();
    jQuery(document.body).prepend(hideDiv);
};
function showDMenu() {
    if (Mdisplay == true) {
        return false;
    } else {
        Mdisplay = true;
        Container.css({ margin: "0 auto", width: btnWidth + "px", height: btnHeight + "px" });
        hideDiv.css({ position: "absolute", top: offset.top + 16 + "px", left: button.offset().left - 35 + "px", height: height + "px", width: width + "px" }).show();
        Container.css({ border: "1px solid #666666" });
        Container.animate({ marginTop: 10, height: height + 4, width: width + 4, opacity: '100' }, 100, function() {
            jqShowObj.show();
            Container.append(jqShowObj);
            Container.css({ border: "0px" });
            jqShowObj.mouseover(function() {
                clearTimeout(Dtimer); clearTimeout(Dtimer2);
            }).mouseout(function() {
                hideDMenu();
            });
        });
    }
};
function hideDMenu() {
    clearTimeout(Dtimer);
    clearTimeout(Dtimer2);
    Dtimer = setTimeout(function() {
        Container.css({ border: "1px solid #666666" });
        jQuery(document.body).prepend(jqShowObj);
        jqShowObj.hide();
        Container.empty();
        Container.animate({ width: btnWidth, height: btnHeight, marginTop: '0', opacity: '0' }, 100, function() {
            Container.hide();
            hideDiv.hide();
            Mdisplay = false;
        });
    }, 100);
};
jQuery(function() {
    ReadCart();
    initDMenu("#CartSwitch_wrap", "#MyCart");
    jQuery("#CartSwitch_wrap").mouseover(function() {
        ReadCart();
        clearTimeout(Dtimer);
        height = jQuery("#MyCart").height();
        Dtimer = setTimeout("showDMenu()", 100);
    }).bind("mouseleave", function() {
        clearTimeout(Dtimer);
        if (Mdisplay == true) {
            Dtimer2 = setTimeout("hideDMenu()", 100);
        }
    });
});
function gele(nodeId) {
    return document.getElementById(nodeId);
};

function ReadCart() {
    document.getElementById("MyCart").innerHTML = '<div class="MyCart_Tip"></div>';
    var getcartid = getCookie("CartID");
    var x = new AjaxRequest('XML', 'MyCart_Tip');
    x.labelname = "自定义随身购物车";
    x.currentpage = 1;
    x.para = ['carcookieid=' + getcartid];
    x.post('updatelabel', '/ajax.aspx', function(s) {
        var xml = x.createXmlDom(s);
        document.getElementById("MyCart").innerHTML = xml.getElementsByTagName("body")[0].firstChild.data;
    }
   );
};
