				var menu_timeout = null;
                
                function show_submenu(id, element)
				{
					hide_submenu();
					var location = getCumulativeOffset(element);
					$$(id).style.left = location.x + 'px';
					$$(id).style.top = location.y + 15 + 'px';
					$$(id).style.display = 'block';
					$$(id+'-top').style.backgroundColor = '#FF0175';
					$$(id+'-top').style.color = 'white';
				}	

				function gerbil_submenu(id, element)
				{
				    clear_menu_timeout();
					menu_timeout = setTimeout('hide_submenu(\'' + id + '\')', 1000);
				}	
			
			    function clear_menu_timeout()
			    {
                    if(menu_timeout)
                        clearTimeout(menu_timeout);
                    menu_timeout = null;
                }
			
				function hide_submenu(menu)
				{
                    clear_menu_timeout();
					if(menu == null)
					{
						$$('Clothing').style.display = 'none';
						$$('Clothing-top').style.backgroundColor = '';
						$$('Clothing-top').style.color = '';
						$$('Shoes').style.display = 'none';
						$$('Shoes-top').style.backgroundColor = '';
						$$('Shoes-top').style.color = '';
						$$('Bags').style.display = 'none';
						$$('Bags-top').style.backgroundColor = '';
						$$('Bags-top').style.color = '';
						$$('Accessories').style.display = 'none';
						$$('Accessories-top').style.backgroundColor = '';
						$$('Accessories-top').style.color = '';
						$$('Designers').style.display = 'none';
						$$('Designers-top').style.backgroundColor = '';
						$$('Designers-top').style.color = '';
						$$('Collections').style.display = 'none';
						$$('Collections-top').style.backgroundColor = '';
						$$('Collections-top').style.color = '';
					}
					else
					{
						$$(menu).style.display = 'none';
						$$(menu + '-top').style.backgroundColor = '';
						$$(menu + '-top').style.color = '';
					}
				}
				
				var shopping_bag = 
				{
					size: 0,
					maxsize: 150,
					view: function()
					{
						$$('shopping-bag-items').style.display = '';
						//this.enlarge();
					},
					
					hide: function()
					{ 
						//this.size = 0;
						$$('shopping-bag-items').style.display = 'none';
						//$$('shopping-bag-items').style.height = this.size + 'px';
					},
					
					enlarge: function()
					{
						
						if(this.size < this.maxsize) 
						{
							this.size += 5;
							$$('shopping-bag-items').style.height = this.size + 'px';
							setTimeout('shopping_bag.enlarge()', 5);
						} 
					}
				}
				
				function showPopup(popupId, boolShowHide, boolCloseOthers)
				{
					if(typeof boolCloseOthers != 'boolean') boolCloseOthers = true;
					if(boolCloseOthers)
					{
						$$('item-quick-view-popup').style.display = "none";
						$$('login-popup').style.display = "none";
						$$('contact-popup').style.display = "none";
						$$('terms-popup').style.display = "none";
						$$('sizechart-popup').style.display = "none";
					}
					
					var popup = $$(popupId);
					if(popup != null)
					{
						if(typeof boolShowHide != 'boolean') boolShowHide = true;
						
						var str_display = boolShowHide?'':'none';
						
						popup.style.display = str_display;
						
						
						if(boolShowHide)
						{
							var shadow = $$(popupId + '-shadow');
							if(shadow != null)
							{
								var bodyHeight = document.body.scrollHeight;
								shadow.style.height = bodyHeight + "px";
							}
							
							var content = $$(popupId + '-content');
							if(content != null)
							{
								var bodyWidth =		document.body.offsetWidth;
								var contentWidth =	content.offsetWidth;
								var contentLeft =	bodyWidth/2 - contentWidth/2;
								
								var windowHeight =	window.innerHeight;
								var contentHeight =	content.offsetHeight;
								
								var contentTop;
								
								if(windowHeight > contentHeight)
								{
									contentTop = windowHeight/2 - contentHeight/2 + "px";
								}else{
									contentTop = "";
								}
								content.style.top = contentTop;
								content.style.left = contentLeft + "px";
							}	
						}
					}
				}
	            
	            var last_selected = null;
				function change_image(image, vid, popup, ele)
				{
					$$(vid).src = image;
					if(ele)
					   addClass(ele, 'carousel-item-selected');
					if(last_selected)
					   removeClass(last_selected, 'carousel-item-selected');
					last_selected = ele;
                    if(!popup)
                    {
                        $$(vid).setAttribute('data-zoomsrc', image);
						MojoZoom.init();
					}
				}
					
				function add_to_cart(itemid, title, category, sub_category, size, color, price, main_image, ds_name, model_color_id, popup)
				{
					if(size == null)
						return;
                    var xhr = createXMLHttpRequest();
					title = title.replace('#', '%23');
                    var str = 'rpc/add_to_cart_rpc.php?itemid=' + itemid + '&title=' + title + '&category=' + category + '&sub_category=' + sub_category + '&size=' + size + '&color=' + color + '&price=' + price + '&ds_name=' + ds_name + '&main_image=' + main_image + '&model_color_id=' + model_color_id;
					xhr.open('GET', str, true);
					xhr.onreadystatechange = function()
					{
						if(xhr.readyState != 4) 
							return;
						if(xhr.status != 200) 
							return;
						
						var response = eval("(" + xhr.responseText + ")");
						if(response.html) 
							$$('shopping-bag').innerHTML = response.html;
						shopping_bag.view();
					}
					xhr.send(null);
					if(popup)
					   showPopup(); // hides the popup
				}
	
				function remove_from_cart(itemid)
				{
					var xhr = createXMLHttpRequest();
					var str = 'rpc/add_to_cart_rpc.php?removeid=' + itemid;
					xhr.open('GET', str, true);
					xhr.onreadystatechange = function()
					{
						if(xhr.readyState != 4)
							return;
						if(xhr.status != 200)
							return;
						
						var response = eval("(" + xhr.responseText + ")");
						if(response.html)
						{
							$$('shopping-bag').innerHTML = response.html;
						}
						shopping_bag.view();
					}
					xhr.send(null);
				}
					
				function quick_view(id)
				{
					var xhr = createXMLHttpRequest();
					var str = 'item_popup_rpc.php?id=' + id;
					xhr.open('GET', str, true);
					xhr.onreadystatechange = function()
					{
						if(xhr.readyState != 4)
							return;
						if(xhr.status != 200)
							return;
						
                        var response = eval("(" + xhr.responseText + ")");
						if (response.html) 
						{
							$$('item-quick-view-popup-content').innerHTML = response.html;
							Cufon.replace('.use-cufon');
						}
							
						if(response.js)
                            eval(response.js);
						
						//MojoZoom.init();
						showPopup('item-quick-view-popup', true, true);
					}
					xhr.send(null);
				}
	
                function request_view_popup(popId, request, text)
				{
					if(!request)
					{
                        showPopup(popId, true, true);
                        return;
                    }

                    var xhr = createXMLHttpRequest();
					xhr.open('GET', request, true);
					xhr.onreadystatechange = function()
					{
						if(xhr.readyState != 4)
							return;
						if(xhr.status != 200)
							return;
						
						$$(popId + '-content').innerHTML = xhr.responseText;
						showPopup(popId, true, false);
						if(text)
                            $$('contactus-comment').value = text;
					}
					xhr.send(null);
				}
				
				function view_sizechart(isQuickview)
				{
					var popId = 'sizechart-popup';
                    var xhr = createXMLHttpRequest();
					xhr.open('GET', 'size_chart.inc.html', true);
					xhr.onreadystatechange = function()
					{
						if(xhr.readyState != 4)
							return;
						if(xhr.status != 200)
							return;
						
						$$(popId + '-content').innerHTML = xhr.responseText;
    					selectTab('clothing');
    					showPopup(popId, true, !isQuickview);
					}
					xhr.send(null);
				}
				
				function contact_us_from_view_sizechart()
				{
					var popId = 'contact-popup';
                    var xhr = createXMLHttpRequest();
					xhr.open('GET', 'contact_us.html', true);
					xhr.onreadystatechange = function()
					{
						if(xhr.readyState != 4)
							return;
						if(xhr.status != 200)
							return;
						
						$$(popId + '-content').innerHTML = xhr.responseText;
    					showPopup(popId, true, true);
					}
					xhr.send(null);
				}
				
				function selectTab(tabId)
				{
					var tabctrl = $$('sizechart-tabs');
					if(tabctrl.getAttribute('selectedTab') != null)
					{
						var selectedTabId = tabctrl.getAttribute('selectedTab');
						var selectedTab = $$('tab-' + selectedTabId);
						var selectedTabPage = $$('tab-page-' + selectedTabId);
						selectedTabPage.style.display = '';
						selectedTab.className = 'tab';//tab-selected
					}
					
					var newTab = $$('tab-' + tabId);
					var newTabPage = $$('tab-page-' + tabId);
					newTabPage.style.display = 'block';
					newTab.className = 'tab tab-selected';
					tabctrl.setAttribute('selectedTab',tabId);
				}
				
		       var carousel = function() {
                   this.left = 0;
                   this.scroll = function(id, scroll)
			       {
			           var jump = ((scroll + this.left) - this.left) / 20;
			           var to = this.left + scroll;
			           var w = -1 * ($$(id).clientWidth - 310); 
			           if(to > 0 || to < w)
			             return;
                       this.real_scroll(id, jump, to, this);
                   };
                   
                   this.real_scroll = function(id, jump, to, context)
                   {
                        context.left += jump;
                        $$(id).style.left = context.left + 'px';
                        if( (jump > 0 && context.left < to) || (jump < 0 && context.left > to) )
                        {
                            // !!! todo - fix circular reference
                            setTimeout(function(){context.real_scroll(id, jump, to, context);}, 10);
                            //setTimeout('real_scroll(\'' + id + '\', ' + jump + ', ' + to + ')', 10);
                        }
                        else
                        {
                            context.left = to;
                            $$(id).style.left = context.left + 'px';
                        }
                        
                   }
                }

    		      var sizer = function()
    		      {
    		            this.sizes = [];
    		            this.buy_size = null;
    		            
    		            this.set_size = function(elementRef, size, lid)
    		            {
    		                $$('buyit_tooltip_' + lid).style.display = 'none';
    		                var elementP = elementRef.parentNode;
    			            for(var i = 0; i < elementP.childNodes.length; i++)
                                if(elementP.childNodes[i].tagName == "A")
                                    RemoveClassName(elementP.childNodes[i], 'item-size-selected');
    
                            AddClassName(elementRef, 'item-size-selected');
    
    			            // not availabale
    			            if(this.sizes[size] <= 0)
    			            {
                                $$('buy-button-'+lid).style.color = '#cccccc';
                                $$('available-'+lid).innerHTML = 'Not in stock - <a href="javascript:;" class="in-link" onclick="request_view_popup(\'contact-popup\', \'contact_us.html\', \'Availability inquiry regarding item #' + lid + ' size ' + size + '\');">Special Order</a>';
                                this.buy_size = null;
                                return;    
                            }
    
                            $$('buy-button-'+lid).style.color = '';
                            $$('buy-button-'+lid).title = ''
                            $$('available-'+lid).innerHTML = 'Yes';
    
                            this.buy_size = size;
                        }
                        
                        this.tooltip = function(lid)
                        {
                            if(this.buy_size)
                                return;
                            
                            $$('buyit_tooltip_' + lid).style.display = '';
                        }
                        
                        this.hide_tooltip = function(lid)
                        {
                            $$('buyit_tooltip_' + lid).style.display = 'none';
                        } 
                  }

