
var selectedCat;var selectedBrand;function insert(item,value){document.getElementById(item).innerHTML=document.getElementById(item).innerHTML+value;}
function clearAll(parent){document.getElementById(parent).innerHTML="";}
function select(item,parent){var navroot;var node;navRoot=document.getElementById(parent);for(i=0;i<navRoot.childNodes.length;i++)
{node=navRoot.childNodes[i];if(node.nodeName=="DIV"){node.className='';}}
item.className='selected';}
function updateBrands(catDiv){var cat=catDiv.innerHTML;cat=cat.toLowerCase();selectedCat=cat;clearAll('brand');var curBrands=categories[cat];if(!curBrands){return;}
if(!curBrands)alert("no brands");curBrands.each(function(theBrand){insert('brand',"<div onclick=\"select(this, 'brand');updateProducts(this);\" value='"+theBrand.search+"'>"+theBrand.display.capitalize()+'</div>');});}
function updateProducts(brandDiv){clearAll('product');var catSelect=selectedCat;var brandSelect=brandDiv.getAttribute('value');;selectedBrand=brandSelect;new Ajax.Request('/accessories.html',{method:'get',parameters:{ajaxRequest:'listProducts',category:catSelect,brand:brandSelect},onSuccess:productsUpdateCallback});}
function productsUpdateCallback(transport){var products=transport.responseText.evalJSON();var shouldSelectProduct=false;products.each(function(product){var id=product.postId;var name=product.title;insert('product',"<div id='"+id+"' onclick=\"select(this, 'product');selectProduct("+id+");\" >"+product.title+'</div>');});}
function selectProduct(id){if(id!=''){new Ajax.Request('/accessories.html',{method:'get',parameters:{ajaxRequest:'getProduct',id:id},onSuccess:productInfoCallback});}}
function productInfoCallback(transport){var theForm=document.forms['productSelection'];var product=transport.responseText.evalJSON();$('selected_product_name').href="product.html?postId="+product.id;$('selected_product_image_link').href="product.html?postId="+product.id;if($('selected_product_name').firstChild)($('selected_product_name').firstChild).nodeValue=product.brand+' - '+product.title;else $('selected_product_name').appendChild(document.createTextNode(product.brand+' - '+product.title));$('selected_product_image').src=product.image200;if($('selected_product_description').firstChild)$('selected_product_description').firstChild.nodeValue=product.storeDescription.substring(-1,200)+"...";else $('selected_product_description').appendChild(document.createTextNode(product.storeDescription.substring(-1,200)+"..."));$('selected_product_add_to_cart').href="?addScItem="+product.id+"&category="+selectedCat+"&brand="+selectedBrand+"&product="+product.id;$('selected_product_add_to_cart').onclick=function(){addToCartAjax(product.id);return false;}
if($('selected_product_price').firstChild)$('selected_product_price').firstChild.nodeValue=product.storePrice;else $('selected_product_price').appendChild(document.createTextNode(product.storePrice));var accessoriesDiv=$('accessory_listings');while(accessoriesDiv.firstChild)accessoriesDiv.removeChild(accessoriesDiv.firstChild);product.accessories.each(function(accessory){if(!accessory.id)return;var accDiv=document.createElement("div");accDiv.className='accessory_item';var imgDiv=document.createElement("div");imgDiv.className='accessory_img';var accImgLink=document.createElement("a");accImgLink.href="product.html?postId="+accessory.id;var accImg=document.createElement("img");accImg.src=accessory.image70;accImg.alt=accessory.title;accImgLink.appendChild(accImg);imgDiv.appendChild(accImgLink);accDiv.appendChild(imgDiv);var blurbDiv=document.createElement("div");blurbDiv.className='accessory_blurb';var accBlurbLink=document.createElement("a");accBlurbLink.className='accessory_title';accBlurbLink.href="product.html?postId="+accessory.id;accBlurbLink.appendChild(document.createTextNode(accessory.title));var accBlurbTextLink=document.createElement("a");accBlurbTextLink.href="product.html?postId="+accessory.id;accBlurbTextLink.appendChild(document.createTextNode(accessory.storeDescription));blurbDiv.appendChild(accBlurbLink);blurbDiv.appendChild(document.createElement("br"));blurbDiv.appendChild(accBlurbTextLink);accDiv.appendChild(blurbDiv);var priceDiv=document.createElement("div");priceDiv.className='accessory_price';priceDiv.appendChild(document.createTextNode('Price: $ '+accessory.storePrice));priceDiv.appendChild(document.createElement("br"));var accLink=document.createElement("a");accLink.href="?addScItem="+accessory.id+"&category="+selectedCat+"&brand="+selectedBrand+"&product="+product.id;var linkImg=document.createElement("img");linkImg.src="/img/add_to_cart_73x18.gif";linkImg.alt="Add To Cart";linkImg.onclick=function(){addToCartAjax(accessory.id);return false;}
accLink.appendChild(linkImg);priceDiv.appendChild(accLink);accDiv.appendChild(priceDiv);accessoriesDiv.appendChild(accDiv);});$('selected_product').style.display='block';}
function accLoad(){}