var menuIsVisible = false;

function _show_cart_menu(  ) {
    /*
    
    CSS properties of the "#hcart ul" class
    position		: absolute;
	z-index			: 1000;
	display			: block;
	
	width			: 332px;
	height			: 400px;
	background		: url(hart-lib/img/transparent.gif);
	padding-top		: 4px;
	right			: 0;
	top				: 15px;
	*/
	
	var ul = $id("hcart").getElementsByTagName("ul").item(0);
	if (ul != null){
		ul.style.position = "absolute";
		ul.style.zIndex = "1000";
		ul.style.display = "block";
	
		ul.style.width = "332px";
		ul.style.height = "400px";
		ul.style.background = "url(hart-lib/img/transparent.gif)";
		ul.style.paddingTop = "4px";
		ul.style.right = "0";
		ul.style.top = "15px";
	}
	
	menuIsVisible = true;
}

function _hide_cart_menu() {
	var ul = $id("hcart").getElementsByTagName("ul").item(0);
	if (ul != null){
		ul.style.position = "";
		ul.style.zIndex = "";
		ul.style.display = "";
	
		ul.style.width = "";
		ul.style.height = "";
		ul.style.background = "";
		ul.style.paddingTop = "";
		ul.style.right = "";
		ul.style.top = "";
	}
	menuIsVisible = false;
}

function _close_cart_menu() {
	var ul = $id("hcart").getElementsByTagName("ul").item(0);
	if (ul != null){
		ul.style.display = "none";
	}
	window.setTimeout( "_hide_cart_menu()", 200 );
}

function winLoad() {
	if( window.location.href.indexOf( "showCartMenu=true" ) > -1 ) {
		_show_cart_menu();
	} else {
		_hide_cart_menu();
	}
	
	
}

function newTab() {

    this.op         = 1;
    this.lnk        = [];
    this.tl = [];
    this.tp = [];

    this.getPanels = function(idtabpanel) {
        cp = 0;
        cpage = 0;
        cpager = 0;
        panels = $id(idtabpanel).getElementsByTagName('div');
        for (var i=0; i<panels.length; i++) {
         	if(panels[i].className == 'tabpanel'){
	            if ((/tabpanel/).test(panels[i].className)) {
	                this.tp.push(panels[i]);
	                panels[i].style.display = (++cp == this.op)? 'block':'none';
	            }
       		}
          	else if (panels[i].className == 'page'){
	            if ((/page/).test(panels[i].className)) {
	                this.tp.push(panels[i]);
	                panels[i].style.display = (++cpage == this.op)? 'block':'none';
	                
	            }
            }
            else{
            	if ((/pager/).test(panels[i].className)) {
	                this.tp.push(panels[i]);
	                panels[i].style.display = (++cpager == this.op)? 'block':'none';
	                
	            }
	            if(panels[i].style.display == 'block'){
	            	litags = panels[i].getElementsByTagName('li');
	            	for (k=0;k<litags.length;k++){
							if(k == 0){
								litags[k].className = 'current';
							}
							else {
								litags[k].className = '';
							}
						}
				}
            }
        }
    }

    this.closeAllPanels = function() {
        for (var i=0; i<this.tp.length; i++)
        this.tp[i].style.display = 'none';
    };
    
    
    this.registerPanel = function(element, id) {
        if (!($id(element)) || !($id(id))) return false; 
        this.associateRegister(element, id);
    };

    this.setLinkEvt = function(idtablink) {
        this.lnk = $id(idtablink).getElementsByTagName('a');
        this.liTrak = $id(idtablink).getElementsByTagName('li');
        for (var i=0; i<this.lnk.length; i++) {
            id = this.lnk[i].hash.replace(/^#/, '');
            this.associateLink(this.lnk[i], id, this.liTrak, idtablink);
            if (i+1 == this.op) this.lnk[i].parentNode.className += ' selected';
        }

        this.tl = $id(idtablink).getElementsByTagName('li');
    };

    this.removeCurrentClass = function() {
        for (var i=0; i<this.tl.length; i++) {
            var ccn = this.tl[i].className;
            if (/selected/.test(ccn))
            this.tl[i].className = trim(ccn.replace(/selected/, ''));
            if (/^\s*$/.test(this.tl[i].className)) this.tl[i].removeAttribute('class');
        }
    };

    this.associateLink = function(l, d, li, idTab) {
        var _self = this;
        if(idTab != 'numPages'){
	        l.onclick = function() {
	            return function(l) {
	                if (!(/selected/.test(l.parentNode.className))) {
	                    _self.closeAllPanels();
	                    if ($id(d)) {
	                        _self.removeCurrentClass();
	                        $id(d).style.display = 'block';
	                        l.className = d;
	                        l.parentNode.className = 'selected';
	                        if (d != 'numPages'){
	                        var prodtab2 = (new newTab()).init('numPages', d, 1);
	                        }
	                    }
	                    else alert([d, 'is undefined'].join(' '));
	                }
	                return false;
	            }(l)
        	}
        }
        
        //l = null; // Leak Memory IE (Circular reference)

    };
    
    this.associateRegister = function(l, d) {
        var _self = this;
        l = $id(l);
        l.onclick = function() {
            return function(l) {
                _self.closeAllPanels();
                _self.removeCurrentClass();
                $id(d).style.display = 'block';
                for (var i=0; i<_self.lnk.length; i++) {
                    if (_self.lnk[i].hash.replace(/^#/, '') == d) _self.lnk[i].parentNode.className += ' selected';
                } 
                return false;

            }(l)
        }
        
        //l = null; // Leak Memory IE (Circular reference)

    }

    this.init = function(idtablink, idtabpanel, openpanel) {
        this.op = openpanel || 1;        
        this.getPanels(idtabpanel);
        this.setLinkEvt(idtablink);
        return this;
    }
}
