// JavaScript Document

    ///
    ///These functions and var declarations need to be outside the $(docuemnt).ready function in order to be able to open the CartBox on startup.
    ///
    ///
    ///In order to open the CartBox on startup, the code from index_cartboxtest.html should be run on page load.
    ///
    ///variables for the CartBox
    ///
    var bCartBoxActive = false; //status if active (prevents from closing when moving from title bar to content and when quickly re-entering the content after leaving it
    var iCartBoxDeactivateTiming = 400;// Timing after which Box is closed after leaving it w/ the mouse
    var tCartBoxTimer = setTimeout(function(){},1);// This is the timeout variable used for the above mentioned functions
    
    //function to close Content if there was no event in between that set the Active attribute again.
    function checkCloseCartBox() {
        if (!bCartBoxActive) {
            $('#CartBoxContents').slideUp(200);
        }
    }



$(document).ready(function(){

    //open Contents when hovering
    $('#CartBoxDisplay').hover(
    function() {
        
        //clear any deactivation timeouts
        clearTimeout(tCartBoxTimer);
                                        
        //check if there are any cart contents
        var oCBCont = $('#CartBoxContents');
        if (oCBCont.length >0) {
            
            //set CartBox Active Status to true and show
            bCartBoxActive = true;
            $(oCBCont).slideDown(200);
            
        }
    }, function () {
        
        //set Status to false and set a timer to close the Content
        bCartBoxActive = false;
        tCartBoxTimer = window.setTimeout(function(){checkCloseCartBox();},iCartBoxDeactivateTiming);
    });
    
    //when moving mouse over the Content, set status to true
    $('#CartBoxContents').mousemove(function(){
        clearTimeout(tCartBoxTimer);
        bCartBoxActiveStatus = true;
    });
    
    //when over Contents, eliminate any timers 
    $('#CartBoxContents').hover(
    function() {
        clearTimeout(tCartBoxTimer);
    },function(){
        
        //when leaving content, set status to false and set a closing timer
        bCartBoxActiveStatus = false;
        tCartBoxTimer = window.setTimeout(function(){checkCloseCartBox();},iCartBoxDeactivateTiming);
    });

});