﻿/*
Cart
*/
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 initDMenu(obj, showobj, Dtimeout, Dspeed) {
    //	Dtimeout=Dtimeout?Dtimeout:300;
    //	Dspeed=Dspeed?Dspeed:100;
    hideDiv = $("<div style='z-index:10000;'></div>");
    Container = $("<div id=\"Container\"></div>");
    hideDiv.append(Container);
    button = $(obj);
    jqShowObj = $(showobj);
    offset = button.offset();
    height = jqShowObj.height();
    width = jqShowObj.width();
    btnHeight = button.height();
    btnWidth = button.width();
    //alert(jqShowObj.width());
    $(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 + 12 + "px", left: button.offset().left - 50 + "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" });
        $(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);
}

$(function() {
    initDMenu("#CartSwitch_wrap", "#MyCart");
    $("#CartSwitch_wrap").mouseover(function() {
        clearTimeout(Dtimer);
        height = $("#MyCart").height();
        Dtimer = setTimeout("showDMenu()", 100);
    }).bind("mouseleave", function() {
        clearTimeout(Dtimer);
        if (Mdisplay == true) {
            Dtimer2 = setTimeout("hideDMenu()", 100);
        }
    });
})
