// All Items Page Variables
 var PreviewColor 	= "";
 var PreviewSize  	= "";
 var PreviewSrc	  	= "";
 var PreviewFamily 	= "";
 var PreviewGroup 	= "";

window.onload = function(){
	//Preview.initialize();
	//Cart.initialize();
	//Cart.show();
	//Popup.initialize();
	//Error.initialize();
};
window.onscroll = function(){
	if($('product_preview') && $('product_preview').style.display!='none'){
		var viewer 	= $('product_preview');
		var shadow  = $('product_preview_dropshadow');
		var pgDims 	= Element.getPageSize('viewport');
		var eleDim 	= viewer.getDimensions();
		var pgOSet 	= document.body.cumulativeScrollOffset();
		var pvTop  	= (pgOSet.top+((pgDims.height/2)-(eleDim.height/2)));
		
		viewer.setStyle({top:pvTop+'px'});
		shadow.setStyle({top:(pvTop+5)+'px'});
	}
}

var Error = {
	initialize : function(){
		this.create   = this.create.bind(this);
		this.open 	  = this.open.bind(this);
		this.close 	  = this.close.bind(this);
	},
	create : function(error,parent){
		this.close();
		
		this.message = document.createElement("DIV");
		this.message.id = 'Error_Message';
		this.message.className = 'error_message';
		
		this.message.style.cssText = "display:none; z-index:6040; position:absolute;";
		
		this.message.innerHTML = '<div>'+error+'</div>';
		
			new Insertion.Top(parent,this.message);
			var getDims = Element.getDimensions(this.message);
				
				if(parent==document.body){
					var left = Math.round(getDims.width/2);
					var top  = Math.round(getDims.height/2);
					this.message.style.cssText = "position:absolute; width:400px; top:50%; left:50%; margin-top:-"+top+"px; margin-left:-"+left+"px'; display:block; visibility:visible; z-index:6040; float: none;";
				}else{
					var par = Element.getDimensions($(parent));
					var width= Math.round(par.width-10);
					var left = Math.round((par.width/2)-(width/2));
					var top  = Math.round((par.height/2)-(getDims.height/2));
					this.message.style.cssText = "position:absolute; width:"+width+"px; margin-top:"+top+"px; margin-left:"+left+"px'; display:block; visibility:visible; z-index:6040; float: none;";
				}
		window.setTimeout(this.close, 2000);
	},
	open : function(error,parent){
		parent=="" ? this.parent=document.body : this.parent=$(parent);
		this.create(error,parent);
	},
	close : function(){
		if(Object.isElement($('Error_Message'))){
			$('Error_Message').remove();
		}
	}
};



/*
var Cookie = {
	initialize : function(){
		this.get 	= this.get.bind(this);
		this.set 	= this.set.bind(this);
		this.delete = this.delete.bind(this);
		this.check  = this.check.bind(this);
	},
	get : function(name){
		var dcookie = document.cookie; 
		var cname = name + "=";
		var clen = dcookie.length;
		var cbegin = 0;
				while (cbegin < clen) {
				var vbegin = cbegin + cname.length;
						if (dcookie.substring(cbegin, vbegin) == cname) { 
						var vend = dcookie.indexOf (";", vbegin);
								if (vend == -1) vend = clen;
						return unescape(dcookie.substring(vbegin, vend));
						}
				cbegin = dcookie.indexOf(" ", cbegin) + 1;
						if (cbegin == 0) break;
				}
		return null;
	},
	set : function(name,value,expires){
		if(!expires) expires = 365;
		expires = expires * 1000 * 60 * 60 * 24;	
        if (!expires) expires = new Date();
		document.cookie = 	name + "=" + escape (value) + 
							"; expires=" + expires.toGMTString(expires) +  "; path=/";
	},
	delete : function(name){
		var expireNow = new Date();
		document.cookie = name + "=" +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
	},
	check : function(name,value){
		var cookieValue = this.get(name);
		if(cookieValue.include(value)) return true;
		return false;
	}
};
*/

var Preview = {
	initialize : function(){
		this.set 	  	 = this.set.bind(this);
		this.create 	 = this.create.bind(this);
		this.remove 	 = this.remove.bind(this);
		this.isMouseOver = this.isMouseOver.bind(this);
		this.mouseMoveHandler = this.mouseMoveHandler.bind(this);
		this.button		 = $('preview_button');
		this.boundbox	 = {};
		this.bindbutton  = {};
		this.pWidth		 = 96;
		this.pHeight	 = 28;
		this.prodbox;
		this.group;
		this.x	= 0;    this.y 	= 0;
		Event.observe(document.body, "mousemove", this.mouseMoveHandler);
		
		this.productList = document.getElementsByClassName('product_item');
			
			for(i=0;i<this.productList.length;i++){
				this.productList[i].onmouseover = function(){
					Preview.create(this);
				}
				this.productList[i].onmouseout = function(){
					Preview.remove();
				}
			}

	},
	set : function(element){
		var bgPos = Position.cumulativeOffset(element);
		this.boundbox = {left:bgPos[0], 
						 top:bgPos[1], 
						 right:bgPos[0] + element.offsetWidth, 
						 bottom:bgPos[1] + element.offsetHeight, 
						 height:((bgPos[1] + element.offsetHeight) - bgPos[1]), 
						 width:((bgPos[0] + element.offsetWidth) - bgPos[0])};
		this.bindbutton = { top:Math.round((this.boundbox.top - (this.pHeight/2))+(this.boundbox.height/2)), 
							left:Math.round((this.boundbox.left - (this.pWidth/2))+(this.boundbox.width/2))};
		this.button.setStyle({left:this.bindbutton.left + 'px', top:this.bindbutton.top + 'px', display:'block'});
	},
	create : function(element,id){
		var id = parseFloat(element.id.replace(/item_/g,""));
		this.group   = id;
		this.set(element);
		this.prodbox = element;
		this.button.onclick = function(){ 
			Popup.getInfo(id);
		};
	},
	remove : function(){
		if(!this.isMouseOver(this.boundbox)) Element.hide(this.button);
	},
	mouseMoveHandler : function(e){
		this.x = Event.pointerX(e);		this.y = Event.pointerY(e);
	},
	isMouseOver : function(box){
	    return (box.bottom > this.y && box.top < this.y && box.left < this.x && box.right > this.x);
	}
};

var Cart = {
	initialize : function(){
		this.cart 		 	= $('cart_border');
		this.cartContent 	= $('cart_content');
		this.cartTotalItems = $('cart_total_items');
		this.cartTotalPrice = $('cart_total_price');
		this.staticCart		= $('title_cart_box');
		this.moverCart		= $('cart_content');
		
		this.reposition 	= this.reposition.bind(this);
		this.update 		= this.update.bind(this);
		this.add 			= this.add.bind(this);
		this.remove 		= this.remove.bind(this);
		this.show 			= this.show.bind(this);
		this.hide 			= this.hide.bind(this);
		this.reset 			= this.reset.bind(this);
		this.cleanPrice 	= this.cleanPrice.bind(this);
		
		this.CurrentClip	= 0;
		this.cartHeight		= 0;

		this.cartTotal		= 0; // Price Total
		this.cartItemCnt	= 0; // Items in Cart
	},
	reposition : function(){
		this.cart.style.cssText = '';
		this.cartHeight			= 0;
		this.CurrentClip		= 0;
	},
	update : function(newItemPrice,newItemCnt){
			this.cartTotalPrice.innerHTML = newItemPrice;
			this.cartTotalItems.innerHTML = '['+newItemCnt+']';
	},
	add : function(product,element){
		var quantity;
		var upc;
		var ErrorCode;
		if(Object.isElement($('Quantity_'+product))){
			quantity 	= $('Quantity_'+product).value;
			upc 	 	= $('ItemUPC_'+product).value;
			ErrorCode 	= 'popup';
		}else{
			quantity 	= $('Quantity').value;
			upc 	 	= $('ItemUPC').value;
			ErrorCode 	= 'fullpage';
		}
		if(upc=="" || !upc || upc=="null" || upc=="undefined"){
			if(ErrorCode=='popup'){
				Error.open('You must select a size before adding this item to your cart.','prev_inner');
			}else{
				Error.open('You must select a size before adding this item to your cart.','');
			}
			return;
		}
		if(quantity=="" || quantity < 1){
			if(ErrorCode=='popup'){
				Error.open('You must enter in a valid quantity for this item.','prev_inner');
			}else{
				Error.open('You must enter in a valid quantity for this item.','');
			}
			return;
		}
		element.parentNode.innerHTML = "Adding Item(s) to Cart...";
		
		new Ajax.Updater($('cart_row'), '/store/updaters/cart_item_add.asp',{
						 method:'POST',
						 parameters:'upc='+upc+'&quantity='+quantity,
						 evalScripts: true,
						 onComplete: function(req){
							Popup.hide();
							Cart.show();
						  }
						 });	
	},
	reset : function(){
		this.cart.setStyle({display: 'none'});
	},
	remove : function(upc){
		if(upc!=""){
		new Ajax.Updater($('cart_row'), '/store/updaters/cart_item_remove.asp',{
						 method:'POST',
						 parameters:'upc='+upc,
						 evalScripts: true,
						 onComplete: function(req){
							Popup.hide();
							//Cart.reset();
							//alert(req.responseText)
						  }
						 });
		}else{
			alert('The item UPC was not found.  Please try deleting this item from the checkout page.');	
		}
	},
	show : function(){
		window.scrollTo(0,0);
		this.cart.setStyle({display: 'block'});
	},
	hide : function(){
		
	},
	cleanPrice : function(price){
		var num = price.toString().replace(/\$|\,/g,'');
			if(isNaN(num))
				num = "0";
			var sign = (num == (num = Math.abs(num)));
				num = Math.floor(num*100+0.50000000001);
			var cents = num%100;
				num = Math.floor(num/100).toString();
			if(cents<10)
				cents = "0" + cents;
			for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
				num = num.substring(0,num.length-(4*i+3))+','+
				num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + '$' + num + '.' + cents);
	}
};


var ProductPopupArray;
var PopupAvailableSizes;
var PopupSelectedColor;
var PopupProductName;
var PopupSelectedColorText;
var ProductID;

var Popup = {
	initialize : function(){
		this._mouseover   		= this.mouseOverHandler.bind(this);
		this._mouseout 	  		= this.mouseOutHandler.bind(this);
		this.updateSubCart 		= this.updateSubCart.bind(this);
		this.productUnavailable	= this.productUnavailable.bind(this);
		this.createProductPage	= this.createProductPage.bind(this);
		this.createSizeTiles	= this.createSizeTiles.bind(this);
		this.cleanPrice			= this.cleanPrice.bind(this);
		this.closeMessage		= this.closeMessage.bind(this);
		this.SELECTED_COLOR = "";
		this.SELECTED_SIZE = "";
		this.SELECTED_PRICE = "";
		this.SELECTED_UPC = "";
		this.SELECTED_COLOR_TEXT = "";
		this.SELECTED_SIZE_TEXT = "";
		this.SELECTED_SYMBOL = "";
		this.HOVER_COLOR_TEXT = "";
		this.HOVER_SIZE_TEXT = "";
		this.PRODUCT_NAME_TEXT = "";
		this.AVAILABLE_SIZES = "";
		this.outofStockMessage 		= false;
		this.ProductArray;
		this.ColorTileRow;
		this.SizeTileRow;
		this.ColorTextBox;
		this.SizeTextBox;
		this.MessageBox;
		this.MessageBoxText;
		this.description;
		this.textPrice;
		this.ItemUPC;
		this.textSize;
		this.product_image_bg;
		this.product_image;
		this.textColor;
		this.PRODUCT_NAME_TEXT;
		this.AVAILABLE_SIZES;
		this.createOverlay 	= this.createOverlay.bind(this);
		this.position 		= this.position.bind(this);
		this.show 			= this.show.bind(this);
		this.hide 			= this.hide.bind(this);
		this.getInfo 		= this.getInfo.bind(this);
		this.createOverlay();
	},
	createOverlay : function(){
		this.pv = document.createElement("DIV");
		this.pv.id = 'product_preview';
		this.pv.style.cssText = 'display:none; position:absolute; top:0px; left:0px; visibility:hidden; z-index:6003';
		new Insertion.After(document.body.firstChild, this.pv);
		
		this.pvds = document.createElement("DIV");
		this.pvds.id = 'product_preview_dropshadow';
		this.pvds.style.cssText = 'display:none; background:#000000; position:absolute; top:0px; left:0px; visibility:hidden; z-index:6002; opacity:.40; filter:alpha(opacity:40);';
		new Insertion.After(document.body.firstChild, this.pvds);
		
		this.bg = document.createElement("DIV");
		this.bg.id = 'Product_Preview_BG';
		this.bg.style.cssText = 'display:none; background:#000000; position:absolute; top:0px; left:0px; visibility:hidden; z-index:6001; opacity:.45; filter:alpha(opacity:45);';
		new Insertion.After(document.body.firstChild, this.bg);	
	},
	 position : function(){
		this.pv 	= $('product_preview');
		this.pvds 	= $('product_preview_dropshadow');
		this.bg 	= $('Product_Preview_BG');
		
		var pgDims 	= Element.getPageSize('viewport');
		var eleDim 	= this.pv.getDimensions();
		var dims 	= Element.getPageSize();
		
		var pgOSet 	= document.body.cumulativeScrollOffset();
		
		var pvTop  	= (pgOSet.top+((pgDims.height/2)-(eleDim.height/2)));
		var pvLeft 	= ((pgDims.width/2)-(eleDim.width/2));
		
		this.pv.setStyle({top:pvTop+'px', left:pvLeft+'px'});
		this.pvds.setStyle({width:eleDim.width+'px', height:eleDim.height+'px', top:(pvTop+5)+'px', left:(pvLeft+5)+'px'});
		this.bg.setStyle({width:'100%', height:dims.height+'px'});		
	},
	show : function(ProductID){
		Cart.reset();
		this.pv.innerHTML = '<div class="pop_top">&nbsp;</div><div class="productLoader">Loading Product ['+ProductID+'] ...</div><div class="clear"></div><div class="pop_bottom">&nbsp;</div>';
		this.position();
		var selectBoxes = document.getElementsByTagName("SELECT");
			for(i=0;i<selectBoxes.length;i++){
				selectBoxes[i].style.visibility = "hidden";
				selectBoxes[i].style.display = "none";
			}
		this.pv.setStyle({visibility:'visible', display:'block'});	
		this.pvds.setStyle({visibility:'visible', display:'block'});
		this.bg.setStyle({visibility:'visible', display:'block'});
	},
	hide : function(){
			var selectBoxes = document.getElementsByTagName("SELECT");
			for(i=0;i<selectBoxes.length;i++){
				selectBoxes[i].style.visibility = "visible";
				selectBoxes[i].style.display = "";
			}
		this.pv.setStyle({visibility:'hidden', display:'none'});
		this.pvds.setStyle({visibility:'hidden', display:'none'});
		this.bg.setStyle({visibility:'hidden', display:'none'});
		this.pv.innerHTML = '<div class="pop_top">&nbsp;</div><div class="productLoader">Loading Quick Look ...</div><div class="clear"></div><div class="pop_bottom">&nbsp;</div>';
	},
	createProductPage : function(){
		this.ProductArray 		= ProductPopupArray;
		this.ColorTileRow		= $('ColorSelectionRow_'+ProductID);
		this.SizeTileRow		= $('SizeTileRow_'+ProductID);
		this.ColorTextBox		= $('SelectColorText_'+ProductID);
		this.SizeTextBox		= $('SelectSizeText_'+ProductID);
		this.MessageBox			= $('product_alert_'+ProductID);
		this.MessageBoxText		= $('product_alert_text_'+ProductID);
		this.textPrice			= $('textPrice_'+ProductID);
		this.ItemUPC			= $('ItemUPC_'+ProductID);
		this.textSize			= $('textSize_'+ProductID);
		this.product_image_bg	= $('preview_img_'+ProductID);
		this.product_image		= $('product_image_'+ProductID);
		this.textColor			= $('textColor_'+ProductID);
		this.description		= $('order_stuff_'+ProductID);
		this.SELECTED_COLOR 	= PopupSelectedColor;
		this.PRODUCT_NAME_TEXT	= PopupProductName;
		this.AVAILABLE_SIZES	= PopupAvailableSizes;
		this.ColorTextBox.innerHTML	= PopupSelectedColorText;
		this.SELECTED_COLOR_TEXT = this.ProductArray[this.SELECTED_COLOR][1];
		if(this.SELECTED_COLOR==""){ this.setColor(0); }else{ this.setColor(this.SELECTED_COLOR); }
		 var imageObj = new Image();
		 var images = new Array();
		 var x=0;
		 var i;
		 for(i=0; i<this.ProductArray.length; i++) {
			 images[x] = this.ProductArray[i][6][0];
			 images[x+1] = this.ProductArray[i][6][1];
			 images[x+2] = this.ProductArray[i][6][2];
			 x=x+3;
		 }
		 if(!$('hide_preloads')){
		var makePreloads = document.createElement("DIV");
		makePreloads.id = 'hide_preloads';
		makePreloads.style.cssText = 'display:none; visibility:hidden; z-index:-15; opacity:.0; filter:alpha(opacity:0);';
		new Insertion.After(document.body.firstChild, makePreloads); 
		 }
		 for(i=0; i<images.length; i++) {
			imageObj.src=images[i];
			new Insertion.Bottom($('hide_preloads'),'<img src="'+imageObj.src+'">');
		 }
	},
	getInfo : function(product){
		this.show(product);
		ProductID = product;
		new Ajax.Updater(this.pv, '/store/updaters/quick_look.asp',{
						 method:'POST',
						 parameters:'product='+product,
						 evalScripts: true,
						 onComplete: function(req){
							Popup.position();
						  }
		});		
	},
	mouseOverHandler : function(element,size,quantity){
		if(element.className.include("size_tile")){
				if(element.className.include("size_tile_none") || quantity==0){	
			this.productUnavailable(this.PRODUCT_NAME_TEXT, this.SELECTED_COLOR_TEXT, size);	
				}else{
					element.className = "size_tile_on";
				}
			this.SizeTextBox.innerHTML = size+' ('+element.title+')';
		}
		if(element.className.include("color_tile")){
		  var identifier = element.id.split('_');
		  	  identifier = parseFloat(identifier[1]);
			element.className = "color_tile_on";
			this.ColorTextBox.innerHTML = element.title;
			var swapPane = $('prev_right').getElementsByClassName('swap_selector');
				for(i=0;(i<swapPane.length || i==0);i++){
					swapPane[i].style.display = 'none';	
				}
				$('infopane_'+identifier).style.display = 'block';
		}
	},
	mouseOutHandler : function(element){
		this.closeMessage();
		if(element.className.include("size_tile") && element.id!="size_"+this.SELECTED_SIZE+"_"+ProductID){
			if(element.className!="size_tile_none"){
			  element.className = "size_tile";	
			}
			this.SizeTextBox.innerHTML = this.SELECTED_SIZE_TEXT;
		}
		if(element.className.include("color_tile") && element.id!="color_"+this.SELECTED_COLOR+"_"+ProductID){
		  var identifier = element.id.split('_');
		  	  identifier = parseFloat(identifier[1]);
			element.className = "color_tile";
			this.ColorTextBox.innerHTML = this.SELECTED_COLOR_TEXT;
		  	//this.product_image.src 	= this.ProductArray[this.SELECTED_COLOR][6][0];
			var swapPane = $('prev_right').getElementsByClassName('swap_selector');
				for(i=0;i<swapPane.length;i++){
					swapPane[i].style.display = 'none';	
				}
				$('infopane_'+this.SELECTED_COLOR).style.display = 'block';
		}
	},
	setColor : function(identifier){
		if(identifier=="") identifier=0;
		identifier = parseFloat(identifier);
		var element = $('color_'+identifier+'_'+ProductID);
		if(this.SELECTED_COLOR!="" && this.SELECTED_COLOR!=identifier){
			$('color_'+this.SELECTED_COLOR+'_'+ProductID).className = "color_tile";
		}
				 var ColorTiles = this.ColorTileRow.getElementsByClassName('color_tile_on'); 
			for(i=0;i<ColorTiles.length;i++){
				if(ColorTiles[i] == element){	 
				 ColorTiles[i].className = 'color_tile_on';
				}else{
				 ColorTiles[i].className = 'color_tile';
				}
			}
		this.SELECTED_COLOR = identifier;
		this.SELECTED_COLOR_TEXT 	= $('color_'+identifier+'_'+ProductID).title;
		this.ColorTextBox.innerHTML = this.SELECTED_COLOR_TEXT;
		this.createSizeTiles(identifier);
		this.textColor.innerHTML 	= this.SELECTED_COLOR_TEXT;
		this.position();
	},
	setSize : function(identifier,element,size,price,upc,quantity){
		if(element.className=="size_tile_none") return this.productUnavailable(this.PRODUCT_NAME_TEXT, this.SELECTED_COLOR_TEXT, size);
		if(this.SELECTED_SIZE!="" && $('size_'+this.SELECTED_SIZE+'_'+ProductID)!=element) $('size_'+this.SELECTED_SIZE+'_'+ProductID).className = "size_tile";
		 var SizeTiles = this.SizeTileRow.getElementsByClassName('size_tile_on'); 
			 
			 for(i=0;i<SizeTiles.length;i++){
				if(SizeTiles[i] == element){	 
				 SizeTiles[i].className = 'size_tile_on';
				}else{
				 SizeTiles[i].className = 'size_tile';	
				}
			 }
			 
			if(quantity==0) return this.productUnavailable(this.PRODUCT_NAME_TEXT, this.SELECTED_COLOR_TEXT, size);
			this.SELECTED_SIZE 			= identifier;
			this.SELECTED_SYMBOL		= size;
			this.SELECTED_SIZE_TEXT 	= size+' ('+element.title+')';
			this.SizeTextBox.innerHTML 	= this.SELECTED_SIZE_TEXT;
			this.SELECTED_PRICE 		= price;
			this.SELECTED_UPC 			= upc;
			this.SELECTED_QUANTITY 		= quantity;
			this.updateSubCart();
			this.position();
	},
	createSizeTiles : function(identifier){
		if(identifier=="") identifier = 0;
		var Sizes  		= this.ProductArray[identifier][2]; 
		var Alts   		= this.ProductArray[identifier][5];
		var Prices 		= this.ProductArray[identifier][3];
		var UPC	   		= this.ProductArray[identifier][4];
		var Quantity	= this.ProductArray[identifier][7];
		var SizeBlocks    = this.AVAILABLE_SIZES.replace(/<XX><XX>/g,",");
			SizeBlocks    = SizeBlocks.replace(/<XX>/g,"");
			SizeBlocks    = SizeBlocks.split(",");
			this.SizeTileRow.innerHTML = "";
			for(var x=0; x<SizeBlocks.length; x++){
				var cacheClass;
				var cacheSize = SizeBlocks[x];
				var cachePrice;
				var cacheQuantity;
				var cacheAlts;
				var cacheUPC;
				var sizeFound = false;
				for(i=0; i<Sizes.length; i++){
					if(cacheSize == Sizes[i]){
						Quantity[i] > 0 ? cacheClass="size_tile" : cacheClass="size_tile_none";
						if(Sizes[i] == this.SELECTED_SYMBOL && Quantity[i] > 0) cacheClass="size_tile_on";
						if(Sizes[i] == this.SELECTED_SYMBOL && Quantity[i] < 1){
							this.productUnavailable(this.PRODUCT_NAME_TEXT, this.SELECTED_COLOR_TEXT, Sizes[i]);
							this.SELECTED_SIZE		 	= "";
							this.SELECTED_SIZE_TEXT 	= "";
							this.SELECTED_SYMBOL		= "";
							this.SizeTextBox.innerHTML 	= "";
							this.SELECTED_PRICE 		= "";
							this.SELECTED_UPC 			= "";
							this.SELECTED_QUANTITY 		= "";
							this.updateSubCart();
						}
						cachePrice 		= Prices[i];
						cacheQuantity 	= Quantity[i];
						cacheAlts 		= Alts[i];
						cacheUPC 		= UPC[i];
						sizeFound 		= true;
					}
				}
					if(sizeFound){	
					 new Insertion.Bottom(this.SizeTileRow, '<div class="'+cacheClass+'" id="size_'+cacheSize+'_'+ProductID+'" style="margin-bottom:8px;" '+
															'onmouseover="Popup.mouseOverHandler(this,\''+cacheSize+'\',\''+cacheQuantity+'\')"  '+
															'onmouseout="Popup.mouseOutHandler(this)" '+
															'onClick="Popup.setSize(\''+cacheSize+'\',this, \''+cacheSize+'\',\''+cachePrice+'\',\''+cacheUPC+'\',\''+cacheQuantity+'\');" title="'+cacheAlts+'">'+
															'<div class="size_tile_border">'+cacheSize+'</div></div>');
					}else{
					 new Insertion.Bottom(this.SizeTileRow, '<div class="size_tile_none" id="size_'+cacheSize+'_'+ProductID+'" style="margin-bottom:8px;" '+
															'onmouseover="Popup.mouseOverHandler(this,\''+cacheSize+'\',0)"  '+
															'onmouseout="Popup.mouseOutHandler(this)" '+
															'onClick="Popup.setSize(\'none\');" title="Not available or out of stock.">'+
															'<div class="size_tile_border">'+cacheSize+'</div></div>');
					}
			}
			this.position();
	},
	updateSubCart : function(){		
		if(this.SELECTED_SIZE!="" || this.SELECTED_SIZE==0 && this.SELECTED_SIZE!='undefined'){
		this.ItemUPC.value = this.SELECTED_UPC;
		this.textSize.innerHTML  = this.SELECTED_SYMBOL;
		this.SELECTED_PRICE=="" ? this.textPrice.innerHTML="" : this.textPrice.innerHTML = this.cleanPrice(this.SELECTED_PRICE);
		}
	},
	productUnavailable : function(name, color, size){
		var bgPos = Position.cumulativeOffset(this.product_image_bg);
			this.MessageBoxText.innerHTML = name+" in "+color+" is currently not available in "+size;
		var mbSize = this.MessageBoxText.getDimensions();
		var bgSize = this.product_image_bg.getDimensions();
		var newL = (((bgSize.width - mbSize.width)/2) + bgPos.left);
		var newT = (((bgSize.height - mbSize.height)/2) + bgPos.top);
		this.MessageBox.setStyle({left:newL+'px',top:newT+'px'});
		this.MessageBox.setStyle({zIndex:'6005', opacity:'1',filter:'alpha(opacity:100)',visibility:'visible',display:'block'});
		this.outofStockMessage = true;
	},
	closeMessage : function(){
		if(!this.outofStockMessage) return;
		this.MessageBox.setStyle({zIndex:'-10', opacity:'0',filter:'alpha(opacity:0)',visibility:'hidden'});
		this.MessageBoxText.innerHTML = "";
	},
	cleanPrice : function(price){
		var num = price.toString().replace(/\$|\,/g,'');
			if(isNaN(num))
				num = "0";
			var sign = (num == (num = Math.abs(num)));
				num = Math.floor(num*100+0.50000000001);
			var cents = num%100;
				num = Math.floor(num/100).toString();
			if(cents<10)
				cents = "0" + cents;
			for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
				num = num.substring(0,num.length-(4*i+3))+','+
				num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + '$' + num + '.' + cents);
	}
};
