//<![CDATA[
var appearingMenu = true;
var appearingCart = true;
var menuDiv = null;
var cartDiv = null;
var statsDiv = null;
var statsHeader1Div = null;
var statsHeader2Div = null;
var topSellers = null;
var newReleases = null;
var speedCtrlMenu = 0;
var speedCtrlCart = 0;
var limitMenu;
var limitCart;

window.onload=function() {
    var div = document.all ? document.all.cartTitle : document.getElementById("cartTitle");
    if (div) { div.style.letterSpacing = "0px"; }
    div = document.all ? document.all.stateMenu : document.getElementById("stateMenu");
    if (div) { div.style.display = "inline"; }
    div = document.all ? document.all.stateCart : document.getElementById("stateCart");
    if (div) { div.style.display = "inline"; }

    menuDiv = document.all ? document.all.sliddingMenu : document.getElementById("sliddingMenu");
    cartDiv = document.all ? document.all.sliddingCart : document.getElementById("sliddingCart");
	statsDiv = document.all ? document.all.stats : document.getElementById("stats");
    statsHeader1Div = document.all ? document.all.statsHeader1 : document.getElementById("statsHeader1");
    statsHeader2Div = document.all ? document.all.statsHeader2 : document.getElementById("statsHeader2");
    topSellers = document.all ? document.all.topSellers : document.getElementById("topSellers");
    newReleases = document.all ? document.all.newReleases : document.getElementById("newReleases");
    
    menuDiv.onmouseover = appearLeftMenu;
	menuDiv.onmouseout = disappearLeftMenu;
	if (cartDiv) {
        cartDiv.onmouseover = appearLeftCart;
	    cartDiv.onmouseout = disappearLeftCart;
	}
	if (statsDiv) {
	    statsDiv.onmouseover = expandStats;
	    statsDiv.onmouseout = shrinkStats;
	}
}

function expandStats(e) {
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    if (checkMouseEnter(this, e)) {
	    statsDiv.style.height = "400px";
	    if (statsHeader1Div) statsHeader1Div.style.height = "396px";
	    if (statsHeader2Div) statsHeader2Div.style.height = "396px";
	    if (topSellers) topSellers.style.height = "370px";
	    if (newReleases) newReleases.style.height = "370px";
    }
}

function shrinkStats(e) {
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    if (checkMouseLeave(this, e)) {
	    statsDiv.style.height = "135px";
	    if (statsHeader1Div) statsHeader1Div.style.height = "131px";
	    if (statsHeader2Div) statsHeader2Div.style.height = "131px";
	    if (topSellers) topSellers.style.height = "105px";
	    if (newReleases) newReleases.style.height = "105px";
    }
}

function appearLeftMenu(e) {
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    if (checkMouseEnter(this, e)) { // this is necessary to ignore events fired by child controls
	    limitMenu = -114;
        startAppearLeftMenu();
    }
}

function startAppearLeftMenu() {
	menuDiv.style.left = limitMenu + "px";
	appearingMenu = true;
	speedCtrlMenu = 0;
	doAppearLeftMenu();
}

function doAppearLeftMenu() {
	if (appearingMenu) {
		if (parseInt(menuDiv.style.left) < -10) { 
			menuDiv.style.left = parseInt(menuDiv.style.left) + speedCtrlMenu*3 + "px";
			setTimeout(doAppearLeftMenu, getSpeedMenu());
		} else {
			menuDiv.style.left = "0px";
		}
	}
}

function disappearLeftMenu(e) {
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    if (checkMouseLeave(this, e)) {
	    appearingMenu = false;
	    speedCtrlMenu = 0;
	    limitMenu = -114;
	    doDisappearLeftMenu();
    }
}

function doDisappearLeftMenu() { 
	if (!appearingMenu) {
		if (parseInt(menuDiv.style.left) > limitMenu) {
			menuDiv.style.left = parseInt(menuDiv.style.left) - speedCtrlMenu*3 + "px";
			setTimeout(doDisappearLeftMenu, getSpeedMenu() );
		} else {
			menuDiv.style.left = limitMenu + "px";
		}
	}
}

function getSpeedMenu() {
	if (speedCtrlMenu < 8) {
		speedCtrlMenu++;
	}
	return 65 - speedCtrlMenu*8;
}

function appearLeftCart(e) {
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    if (checkMouseEnter(this, e)) { // this is necessary to ignore events fired by child controls
	    limitCart = -160;
        startAppearLeftCart();
    }
}

function startAppearLeftCart() {
	cartDiv.style.left = limitCart + "px";
	appearingCart = true;
	speedCtrlCart = 0;
	doAppearLeftCart();
}

function doAppearLeftCart() {
	if (appearingCart) {
		if (parseInt(cartDiv.style.left) < -10) { 
			cartDiv.style.left = parseInt(cartDiv.style.left) + speedCtrlCart*3 + "px";
			setTimeout(doAppearLeftCart, getSpeedCart());
		} else {
			cartDiv.style.left = "0px";
		}
	}
}

function disappearLeftCart(e) {
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    if (checkMouseLeave(this, e)) {
	    appearingCart = false;
	    speedCtrlCart = 0;
	    limitCart = -160;
	    doDisappearLeftCart();
    }
}

function doDisappearLeftCart() { 
	if (!appearingCart) {
		if (parseInt(cartDiv.style.left) > limitCart) {
			cartDiv.style.left = parseInt(cartDiv.style.left) - speedCtrlCart*3 + "px";
			setTimeout(doDisappearLeftCart, getSpeedCart() );
		} else {
			cartDiv.style.left = limitCart + "px";
		}
	}
}

function getSpeedCart() {
	if (speedCtrlCart < 8) {
		speedCtrlCart++;
	}
	return 65 - speedCtrlCart*8;
}

function containsDOM(container, containee) {
    var isParent = false;
    do {
        if ((isParent = container == containee)) break;
        containee = containee.parentNode;
    } while (containee != null);
    return isParent;
}

function checkMouseEnter(element, evt) {
    if (element.contains && evt.fromElement) {
        return !element.contains(evt.fromElement);
    } else {
        if (evt.relatedTarget) {
            return !containsDOM(element, evt.relatedTarget);
        }
    }
    return true;
}

function checkMouseLeave(element, evt) {
    if (element.contains && evt.toElement) {
        return !element.contains(evt.toElement);
    } else {
        if (evt.relatedTarget) {
            return !containsDOM(element, evt.relatedTarget);
        }
    }
    return true;
}

//]]>
