﻿function showAddedCartItem(itemName, quantity) {

    // check if ie7 and add inline styles
    var isIe7 = (navigator.appVersion.indexOf("MSIE 7.") == -1) ? false : true;
    var isIe8 = (navigator.appVersion.indexOf("MSIE 8.") == -1) ? false : true;

    var uniqueId = quantity;
    var topNav = document.getElementById("topNav");
    var newdiv = document.createElement('div');
    var clearDivExists = document.getElementById("shoppingcartClearDiv");
    if (clearDivExists == null || clearDivExists == "undefined") {
        var clearDiv = document.createElement('div');
        clearDiv.setAttribute('id', 'shoppingcartClearDiv');
        topNav.appendChild(clearDiv);
        var containerCartDiv = document.createElement('div');
        if (isIe7) {
            containerCartDiv.setAttribute('id', 'dynamicCartItemContainerIe7');
        }
        else containerCartDiv.setAttribute('id', 'dynamicCartItemContainer');
        topNav.appendChild(containerCartDiv);
    }

    if (isIe8)
        $("#dynamicCartItemContainer").css("display", "block");

    if (isIe7)
        var containerDiv = document.getElementById("dynamicCartItemContainerIe7");
    else var containerDiv = document.getElementById("dynamicCartItemContainer");

    var divIdName = 'dynamicCartItemContainer' + uniqueId;



    if (isIe7) {
        containerDiv.appendChild(newdiv);
        newdiv.setAttribute('id', divIdName);
        newdiv.innerHTML = "<div class='TopNav_Footer_Background dynamicCartItemIe7'>" + itemName + " added to cart</div>";
    }
    else {
        newdiv.setAttribute('id', divIdName);
        newdiv.setAttribute('class', "TopNav_Footer_Background dynamicCartItem");
        newdiv.innerHTML = itemName + " added to cart";
        containerDiv.appendChild(newdiv);
    }

    $("#" + divIdName).fadeIn(400).delay(2500).fadeOut(400, function () {
        $("#" + divIdName).remove();
        if (isIe8)
            $("#dynamicCartItemContainer").css("display", "none");
    });
}

    function findPos(obj) {
        var curleft = curtop = 0;
        if (obj.offsetParent) {
            do {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
        }

        return [curleft, curtop];
    }

   function getWindowWidth()
    {
        var myWidth = 0, myHeight = 0;
        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            myWidth = window.innerWidth - 29;
            myHeight = window.innerHeight;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth - 12;
            myHeight = document.documentElement.clientHeight;
        }
        return myWidth;
    }

    /********************************
    *   (C) 2009 - Thiago Barbedo   *
    *   - tbarbedo@gmail.com        *
    *********************************/

    window.onscroll = function () {
        if (window.XMLHttpRequest) {
            if ($('#topNav').css('position') == "absolute") {
                var windowWidth = $(window).width();
                var menuDiv = document.getElementById("header");
                var coordinates = findPos(menuDiv);
                var menuWidth = $("#topNav").width();
                var correctWidth = (parseInt(coordinates[0]));
                    if (self.pageYOffset > 5 || document.documentElement.scrollTop > 5) {
                        $('#topNav').css('position', 'fixed');
                        $('#topNav').css('right', correctWidth);
                    } else if (self.pageYOffset < 5 || document.documentElement.scrollTop < 5) {
                        $('#topNav').css('position', 'absolute');
                        $('#topNav').css('right', 0);
                    }
            }
            else {
                // fix for chrome.  scrollTop is always 0
                if (self.pageYOffset > 0 && document.documentElement.scrollTop == 0) {
                    if (self.pageYOffset < 5) {
                        $('#topNav').css('position', 'absolute');
                        $('#topNav').css('right', 0);
                    }
                }
                else {
                    if (self.pageYOffset < 5 || document.documentElement.scrollTop < 5) {
                        $('#topNav').css('position', 'absolute');
                        $('#topNav').css('right', 0);
                    }
                }
            }
        }
    }


